blob: 49fb1fc1b5cadf5aad47489cdc7ca0185d11d91a [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 *
31 * $Id: telnetd-gui.c,v 1.1 2003/10/14 11:23:04 adamdunkels Exp $
32 *
33 */
34
35#include "program-handler.h"
36#include "loader.h"
37#include "uip.h"
38#include "uip_main.h"
39#include "petsciiconv.h"
40#include "uip_arp.h"
41#include "resolv.h"
42#include "telnetd.h"
43#include "memb.h"
44
45#include "shell.h"
46
47#include "uip-signal.h"
48
49#include "telnetd.h"
50
51#include <string.h>
52
53#define ISO_nl 0x0a
54#define ISO_cr 0x0d
55
56#define XSIZE 36
57#define YSIZE 12
58
59static struct ctk_window window;
60static char log[XSIZE * YSIZE];
61static struct ctk_label loglabel =
62 {CTK_LABEL(0, 0, XSIZE, YSIZE, log)};
63
64/*-----------------------------------------------------------------------------------*/
65void
66telnetd_gui_output(char *str1, char *str2)
67{
68 static unsigned int len, i;
69
70 for(i = 1; i < YSIZE; ++i) {
71 memcpy(&log[(i - 1) * XSIZE], &log[i * XSIZE], XSIZE);
72 }
73 memset(&log[(YSIZE - 1) * XSIZE], 0, XSIZE);
74
75 len = strlen(str1);
76
77 strncpy(&log[(YSIZE - 1) * XSIZE], str1, XSIZE);
78 if(len < XSIZE) {
79 strncpy(&log[(YSIZE - 1) * XSIZE] + len, str2, XSIZE - len);
80 }
81
82 CTK_WIDGET_REDRAW(&loglabel);
83}
84/*-----------------------------------------------------------------------------------*/
85void
86telnetd_gui_quit(void)
87{
88 ctk_window_close(&window);
89}
90/*-----------------------------------------------------------------------------------*/
91void
92telnetd_gui_init(void)
93{
94 dispatcher_listen(ctk_signal_window_close);
95 dispatcher_listen(ctk_signal_widget_activate);
96
97 ctk_window_new(&window, XSIZE, YSIZE, "Shell server");
98 CTK_WIDGET_ADD(&window, &loglabel);
99 memset(log, ' ', sizeof(log));
100 ctk_window_open(&window);
101}
102/*-----------------------------------------------------------------------------------*/
103DISPATCHER_SIGHANDLER(telnetd_gui_sighandler, s, data)
104{
105 DISPATCHER_SIGHANDLER_ARGS(s, data);
106
107 if(s == ctk_signal_window_close) {
108 telnetd_quit();
109 }
110}
111/*-----------------------------------------------------------------------------------*/