2 * Copyright (c) 2003, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * This file is part of the Contiki VNC client
32 * $Id: vnc.c,v 1.1 2006/06/17 23:08:35 adamdunkels Exp $
40 /*#include "petsciiconv.h"*/
41 #include "net/uiplib.h"
44 #include "ctk/ctk-mouse.h"
45 #include "net/resolv.h"
46 /*#include "telnet.h"*/
49 #include "vnc-viewer.h"
50 #include "contiki-conf.h"
52 #include "sys/loader.h"
58 #define PRINTF(x) printf x
62 #ifdef VNC_CONF_VIEWPORT_WIDTH
63 #define VNC_VIEWPORT_WIDTH VNC_CONF_VIEWPORT_WIDTH
65 #define VNC_VIEWPORT_WIDTH 10
68 #ifdef VNC_CONF_VIEWPORT_HEIGHT
69 #define VNC_VIEWPORT_HEIGHT VNC_CONF_VIEWPORT_HEIGHT
71 #define VNC_VIEWPORT_HEIGHT 10
74 #define HEIGHT (4 + VNC_VIEWPORT_HEIGHT/8)
77 static struct ctk_window mainwindow
;
80 static struct ctk_textentry hosttextentry
=
81 {CTK_TEXTENTRY(0, 0, 18, 1, host
, 18)};
83 static char portentry
[4];
84 static struct ctk_textentry porttextentry
=
85 {CTK_TEXTENTRY(21, 0, 3, 1, portentry
, 3)};
87 static struct ctk_button connectbutton
=
88 {CTK_BUTTON(27, 0, 7, "Connect")};
89 /*static struct ctk_button disconnectbutton =
90 {CTK_BUTTON(25, 3, 10, "Disconnect")};*/
92 static struct ctk_separator sep1
=
93 {CTK_SEPARATOR(0, 1, 36)};
95 static struct ctk_bitmap vncbitmap
=
97 VNC_VIEWPORT_WIDTH
/ 8,
98 VNC_VIEWPORT_HEIGHT
/ 8,
101 VNC_VIEWPORT_HEIGHT
)};
103 static struct ctk_button leftbutton
=
104 {CTK_BUTTON(6, HEIGHT
- 1, 4, "Left")};
106 static struct ctk_button upbutton
=
107 {CTK_BUTTON(13, HEIGHT
- 1, 2, "Up")};
109 static struct ctk_button downbutton
=
110 {CTK_BUTTON(18, HEIGHT
- 1, 4, "Down")};
112 static struct ctk_button rightbutton
=
113 {CTK_BUTTON(25, HEIGHT
- 1, 5, "Right")};
115 PROCESS(vnc_process
, "VNC viewer");
117 /*-----------------------------------------------------------------------------------*/
123 /*-----------------------------------------------------------------------------------*/
127 u16_t addr
[2], *addrptr
;
131 /* Find the first space character in host and put a zero there
132 to end the string. */
133 for(cptr
= host
; *cptr
!= ' ' && *cptr
!= 0; ++cptr
);
137 if(uiplib_ipaddrconv(host
, (unsigned char *)addr
) == 0) {
138 addrptr
= resolv_lookup(host
);
139 if(addrptr
== NULL
) {
141 show("Resolving host...");
147 for(cptr
= portentry
; *cptr
!= ' ' && *cptr
!= 0; ++cptr
) {
148 if(*cptr
< '0' || *cptr
> '9') {
149 show("Port number error");
152 port
= 10 * port
+ *cptr
- '0';
156 vnc_viewer_connect(addrptr
, port
);
158 show("Connecting...");
161 /*-----------------------------------------------------------------------------------*/
162 PROCESS_THREAD(vnc_process
, ev
, data
)
165 unsigned char xc
, yc
;
169 ctk_window_new(&mainwindow
, 36, HEIGHT
, "VNC client");
170 ctk_window_move(&mainwindow
, 0, 0);
172 CTK_WIDGET_ADD(&mainwindow
, &hosttextentry
);
173 CTK_WIDGET_FOCUS(&mainwindow
, &hosttextentry
);
174 CTK_WIDGET_ADD(&mainwindow
, &porttextentry
);
175 CTK_WIDGET_ADD(&mainwindow
, &connectbutton
);
177 CTK_WIDGET_ADD(&mainwindow
, &sep1
);
179 CTK_WIDGET_ADD(&mainwindow
, &vncbitmap
);
181 CTK_WIDGET_ADD(&mainwindow
, &leftbutton
);
182 CTK_WIDGET_ADD(&mainwindow
, &upbutton
);
183 CTK_WIDGET_ADD(&mainwindow
, &downbutton
);
184 CTK_WIDGET_ADD(&mainwindow
, &rightbutton
);
188 ctk_window_open(&mainwindow
);
191 PROCESS_WAIT_EVENT();
193 if(ev
== ctk_signal_button_activate
) {
194 if(data
== (process_data_t
)&connectbutton
) {
197 } else if(ev
== ctk_signal_window_close
) {
198 process_exit(&vnc_process
);
200 } else if(ev
== resolv_event_found
) {
201 if(strcmp(data
, host
) == 0) {
202 if(resolv_lookup(host
) != NULL
) {
205 show("Host not found");
208 } else if(ev
== ctk_signal_pointer_move
) {
209 /* Check if pointer is within the VNC viewer area */
213 xc
= ctk_mouse_xtoc(x
);
214 yc
= ctk_mouse_ytoc(y
);
216 if(xc
>= 2 && yc
>= 2 &&
217 xc
< 2 + VNC_VIEWPORT_WIDTH
/ 8 &&
218 yc
< 2 + VNC_VIEWPORT_HEIGHT
/ 8) {
220 VNC_VIEWER_POST_POINTER_EVENT(x
, y
, 0);
223 } else if(ev
== tcpip_event
) {
224 vnc_viewer_appcall(data
);
230 /*-----------------------------------------------------------------------------------*/
232 vnc_viewer_refresh(void)
234 CTK_WIDGET_REDRAW(&vncbitmap
);
236 /*-----------------------------------------------------------------------------------*/