Rev 1466 | Rev 1481 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1445 | cejka | 1 | /* |
2 | * Copyright (C) 2006 Josef Cejka |
||
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 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | |||
30 | #include <kbd.h> |
||
1451 | cejka | 31 | #include <fb.h> |
1445 | cejka | 32 | #include <ipc/ipc.h> |
1451 | cejka | 33 | #include <ipc/fb.h> |
1445 | cejka | 34 | #include <ipc/services.h> |
35 | #include <errno.h> |
||
1451 | cejka | 36 | #include <key_buffer.h> |
37 | #include <console.h> |
||
1453 | palkovsky | 38 | #include <unistd.h> |
39 | #include <async.h> |
||
1445 | cejka | 40 | |
1466 | palkovsky | 41 | static void sysput(char c) |
42 | { |
||
43 | __SYSCALL3(SYS_IO, 1, &c, 1); |
||
44 | |||
45 | } |
||
1451 | cejka | 46 | //#define CONSOLE_COUNT VFB_CONNECTIONS |
1476 | cejka | 47 | #define CONSOLE_COUNT 8 |
1451 | cejka | 48 | |
1445 | cejka | 49 | #define NAME "CONSOLE" |
50 | |||
1476 | cejka | 51 | int active_console = 1; |
1453 | palkovsky | 52 | |
53 | |||
1451 | cejka | 54 | typedef struct { |
55 | keybuffer_t keybuffer; |
||
56 | int client_phone; |
||
57 | int vfb_number; /* Not used */ |
||
58 | int vfb_phone; |
||
59 | int used; |
||
60 | } connection_t; |
||
61 | |||
62 | connection_t connections[CONSOLE_COUNT]; |
||
63 | |||
64 | static int find_free_connection() |
||
65 | { |
||
66 | int i = 0; |
||
67 | |||
68 | while (i < CONSOLE_COUNT) { |
||
69 | if (connections[i].used == 0) |
||
70 | return i; |
||
71 | ++i; |
||
72 | } |
||
73 | return CONSOLE_COUNT; |
||
74 | } |
||
75 | |||
76 | |||
77 | static int find_connection(int client_phone) |
||
78 | { |
||
79 | int i = 0; |
||
80 | |||
81 | while (i < CONSOLE_COUNT) { |
||
82 | if (connections[i].client_phone == client_phone) |
||
83 | return i; |
||
84 | ++i; |
||
85 | } |
||
86 | return CONSOLE_COUNT; |
||
87 | } |
||
88 | |||
1453 | palkovsky | 89 | /* Handler for keyboard */ |
90 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
||
1445 | cejka | 91 | { |
1453 | palkovsky | 92 | ipc_callid_t callid; |
1445 | cejka | 93 | ipc_call_t call; |
1453 | palkovsky | 94 | int retval; |
95 | int i; |
||
1476 | cejka | 96 | char c; |
1453 | palkovsky | 97 | |
98 | /* Ignore parameters, the connection is alread opened */ |
||
99 | while (1) { |
||
100 | callid = async_get_call(&call); |
||
101 | switch (IPC_GET_METHOD(call)) { |
||
102 | case IPC_M_PHONE_HUNGUP: |
||
103 | ipc_answer_fast(callid,0,0,0); |
||
104 | /* TODO: Handle hangup */ |
||
105 | return; |
||
106 | case KBD_PUSHCHAR: |
||
107 | /* got key from keyboard driver */ |
||
1465 | cejka | 108 | |
1453 | palkovsky | 109 | /* find active console */ |
1465 | cejka | 110 | |
1453 | palkovsky | 111 | /* if client is awaiting key, send it */ |
1465 | cejka | 112 | |
1453 | palkovsky | 113 | /*FIXME: else store key to its buffer */ |
114 | retval = 0; |
||
1476 | cejka | 115 | c = IPC_GET_ARG1(call); |
116 | // ipc_call_sync_2(connections[3].vfb_phone, FB_PUTCHAR, 0, c,NULL,NULL); |
||
1453 | palkovsky | 117 | /* switch to another virtual console */ |
1476 | cejka | 118 | if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
119 | active_console = c - KBD_KEY_F1; |
||
1453 | palkovsky | 120 | break; |
121 | } |
||
1476 | cejka | 122 | keybuffer_push(&(connections[active_console].keybuffer), c); |
123 | |||
1453 | palkovsky | 124 | /* Send it to first FB, DEBUG */ |
1459 | palkovsky | 125 | // ipc_call_async_2(connections[0].vfb_phone, FB_PUTCHAR, 0, IPC_GET_ARG1(call),NULL,NULL); |
1476 | cejka | 126 | // ipc_call_sync_2(connections[4].vfb_phone, FB_PUTCHAR, 0, c,NULL,NULL); |
1459 | palkovsky | 127 | |
1453 | palkovsky | 128 | break; |
129 | default: |
||
1459 | palkovsky | 130 | retval = ENOENT; |
1453 | palkovsky | 131 | } |
1459 | palkovsky | 132 | ipc_answer_fast(callid, retval, 0, 0); |
1453 | palkovsky | 133 | } |
134 | } |
||
135 | |||
136 | /** Default thread for new connections */ |
||
137 | void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
||
138 | { |
||
1445 | cejka | 139 | ipc_callid_t callid; |
1453 | palkovsky | 140 | ipc_call_t call; |
141 | int consnum; |
||
142 | ipcarg_t arg1; |
||
143 | |||
144 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
||
145 | ipc_answer_fast(iid,ELIMIT,0,0); |
||
146 | return; |
||
147 | } |
||
148 | connections[consnum].used = 1; |
||
149 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
||
150 | |||
151 | /* Accept the connection */ |
||
152 | ipc_answer_fast(iid,0,0,0); |
||
153 | |||
154 | while (1) { |
||
155 | callid = async_get_call(&call); |
||
156 | switch (IPC_GET_METHOD(call)) { |
||
157 | case IPC_M_PHONE_HUNGUP: |
||
158 | /* TODO */ |
||
159 | ipc_answer_fast(callid, 0,0,0); |
||
160 | return; |
||
161 | case CONSOLE_PUTCHAR: |
||
1476 | cejka | 162 | if (consnum != active_console) { |
163 | } |
||
1465 | cejka | 164 | /* Send message to fb */ |
1476 | cejka | 165 | ipc_call_sync_2(connections[consnum].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL); |
166 | // ipc_call_sync_2(connections[6].vfb_phone, FB_PUTCHAR, 0, IPC_GET_ARG2(call),NULL,NULL); |
||
1453 | palkovsky | 167 | break; |
1476 | cejka | 168 | case CONSOLE_CLEAR: |
169 | break; |
||
170 | case CONSOLE_GOTO: |
||
171 | break; |
||
172 | |||
1453 | palkovsky | 173 | case CONSOLE_GETCHAR: |
1465 | cejka | 174 | /* FIXME: Only temporary solution until request storage will be created */ |
1476 | cejka | 175 | while (keybuffer_empty(&(connections[consnum].keybuffer))) { |
1453 | palkovsky | 176 | /* FIXME: buffer empty -> store request */ |
1476 | cejka | 177 | async_usleep(1000); |
1453 | palkovsky | 178 | }; |
1476 | cejka | 179 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
180 | // ipc_call_sync_2(connections[6].vfb_phone, FB_PUTCHAR, 0, arg1,NULL,NULL); |
||
1465 | cejka | 181 | |
1453 | palkovsky | 182 | break; |
183 | } |
||
1465 | cejka | 184 | ipc_answer_fast(callid, 0, arg1, 0); |
1453 | palkovsky | 185 | } |
186 | } |
||
187 | |||
188 | int main(int argc, char *argv[]) |
||
189 | { |
||
190 | ipcarg_t phonehash; |
||
1451 | cejka | 191 | int kbd_phone, fb_phone; |
1445 | cejka | 192 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
1451 | cejka | 193 | int i; |
1445 | cejka | 194 | |
195 | /* Connect to keyboard driver */ |
||
196 | |||
1451 | cejka | 197 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
1453 | palkovsky | 198 | usleep(10000); |
1445 | cejka | 199 | }; |
200 | |||
1453 | palkovsky | 201 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
1445 | cejka | 202 | return -1; |
203 | }; |
||
1453 | palkovsky | 204 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
1445 | cejka | 205 | |
206 | /* Connect to framebuffer driver */ |
||
207 | |||
1451 | cejka | 208 | for (i = 0; i < CONSOLE_COUNT; i++) { |
209 | connections[i].used = 0; |
||
210 | keybuffer_init(&(connections[i].keybuffer)); |
||
211 | /* TODO: init key_buffer */ |
||
212 | while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
||
1465 | cejka | 213 | usleep(10000); |
214 | //ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL); |
||
1451 | cejka | 215 | } |
216 | } |
||
1445 | cejka | 217 | |
1453 | palkovsky | 218 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
1445 | cejka | 219 | return -1; |
220 | }; |
||
221 | |||
1453 | palkovsky | 222 | async_manager(); |
1451 | cejka | 223 | |
1445 | cejka | 224 | return 0; |
225 | } |