blob: 3384855eb8e18101795ce0b4f8a1d228fa8dc308 [file] [log] [blame]
adamdunkels8e5d9902003-10-14 11:23:04 +00001/*
2 * Copyright (c) 2003, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
15 * written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * This file is part of the Contiki desktop OS.
30 *
oliverschmidt72da8302005-04-28 21:16:37 +000031 * $Id: telnetd-gui.c,v 1.5 2005/04/28 21:16:37 oliverschmidt Exp $
adamdunkels8e5d9902003-10-14 11:23:04 +000032 *
33 */
34
35#include "program-handler.h"
36#include "loader.h"
37#include "uip.h"
adamdunkels8e5d9902003-10-14 11:23:04 +000038#include "petsciiconv.h"
39#include "uip_arp.h"
40#include "resolv.h"
41#include "telnetd.h"
42#include "memb.h"
43
44#include "shell.h"
45
adamdunkels8e5d9902003-10-14 11:23:04 +000046#include "telnetd.h"
47
48#include <string.h>
49
50#define ISO_nl 0x0a
51#define ISO_cr 0x0d
52
53#define XSIZE 36
54#define YSIZE 12
55
56static struct ctk_window window;
57static char log[XSIZE * YSIZE];
58static struct ctk_label loglabel =
59 {CTK_LABEL(0, 0, XSIZE, YSIZE, log)};
60
61/*-----------------------------------------------------------------------------------*/
62void
63telnetd_gui_output(char *str1, char *str2)
64{
65 static unsigned int len, i;
66
67 for(i = 1; i < YSIZE; ++i) {
68 memcpy(&log[(i - 1) * XSIZE], &log[i * XSIZE], XSIZE);
69 }
70 memset(&log[(YSIZE - 1) * XSIZE], 0, XSIZE);
71
72 len = strlen(str1);
73
74 strncpy(&log[(YSIZE - 1) * XSIZE], str1, XSIZE);
75 if(len < XSIZE) {
76 strncpy(&log[(YSIZE - 1) * XSIZE] + len, str2, XSIZE - len);
77 }
78
79 CTK_WIDGET_REDRAW(&loglabel);
80}
81/*-----------------------------------------------------------------------------------*/
82void
83telnetd_gui_quit(void)
84{
85 ctk_window_close(&window);
86}
87/*-----------------------------------------------------------------------------------*/
88void
89telnetd_gui_init(void)
90{
adamdunkels8e5d9902003-10-14 11:23:04 +000091 ctk_window_new(&window, XSIZE, YSIZE, "Shell server");
92 CTK_WIDGET_ADD(&window, &loglabel);
oliverschmidt72da8302005-04-28 21:16:37 +000093 memset(log, 0, sizeof(log));
adamdunkels8e5d9902003-10-14 11:23:04 +000094 ctk_window_open(&window);
95}
96/*-----------------------------------------------------------------------------------*/
adamdunkelsf2f8cb22004-07-04 11:35:07 +000097void
98telnetd_gui_eventhandler(ek_event_t ev, ek_data_t data)
adamdunkels8e5d9902003-10-14 11:23:04 +000099{
adamdunkelsf2f8cb22004-07-04 11:35:07 +0000100 if(ev == ctk_signal_window_close) {
adamdunkels8e5d9902003-10-14 11:23:04 +0000101 telnetd_quit();
102 }
103}
104/*-----------------------------------------------------------------------------------*/