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