Contiki 3.x
telnetd-gui.c
1 /*
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  *
32  */
33 
34 #include "program-handler.h"
35 #include "contiki-net.h"
36 #include "lib/petsciiconv.h"
37 
38 #include "shell.h"
39 #include "telnetd.h"
40 
41 #include <string.h>
42 
43 #define ISO_nl 0x0a
44 #define ISO_cr 0x0d
45 
46 #define XSIZE 78
47 #define YSIZE 30
48 
49 static struct ctk_window window;
50 static char log[XSIZE * YSIZE];
51 static struct ctk_label loglabel =
52  {CTK_LABEL(0, 0, XSIZE, YSIZE, log)};
53 
54 /*-----------------------------------------------------------------------------------*/
55 void
56 telnetd_gui_output(const char *str1, int len1, const char *str2, int len2)
57 {
58  static unsigned int i;
59 
60  for(i = 1; i < YSIZE; ++i) {
61  memcpy(&log[(i - 1) * XSIZE], &log[i * XSIZE], XSIZE);
62  }
63 
64  strncpy(&log[(YSIZE - 1) * XSIZE], str1, XSIZE);
65  if(len1 < XSIZE) {
66  strncpy(&log[(YSIZE - 1) * XSIZE] + len1, str2, XSIZE - len1);
67  if(len1 + len2 < XSIZE) {
68  log[(YSIZE - 1) * XSIZE + len1 + len2] = 0;
69  }
70  }
71 
72  CTK_WIDGET_REDRAW(&loglabel);
73 }
74 /*-----------------------------------------------------------------------------------*/
75 void
76 telnetd_gui_quit(void)
77 {
78  ctk_window_close(&window);
79 }
80 /*-----------------------------------------------------------------------------------*/
81 void
82 telnetd_gui_init(void)
83 {
84  shell_file_init();
85  shell_ps_init();
86  shell_run_init();
87  shell_text_init();
88  shell_time_init();
89  shell_wget_init();
90 
91  ctk_window_new(&window, XSIZE, YSIZE, "Shell server");
92  CTK_WIDGET_ADD(&window, &loglabel);
93  memset(log, 0, sizeof(log));
94  ctk_window_open(&window);
95 }
96 /*-----------------------------------------------------------------------------------*/
97 void
98 telnetd_gui_eventhandler(process_event_t ev, process_data_t data)
99 {
100  if(ev == ctk_signal_window_close) {
101  telnetd_quit();
102  }
103 }
104 /*-----------------------------------------------------------------------------------*/
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
Definition: ctk.h:752
process_event_t ctk_signal_window_close
Emitted when a window is closed.
Definition: ctk.c:155
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
Definition: ctk.c:347
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
Definition: ctk.c:400
Main header file for the Contiki shell
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
Definition: ctk.h:171
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
Definition: ctk.c:732
PETSCII/ASCII conversion functions.
Representation of a CTK window.
Definition: ctk.h:506
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
Definition: ctk.h:771