Rev 1517 | Rev 1520 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1517 | Rev 1518 | ||
---|---|---|---|
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 | #include <libadt/fifo.h> |
40 | #include <libadt/fifo.h> |
41 | #include <screenbuffer.h> |
41 | #include <screenbuffer.h> |
42 | #include <sys/mman.h> |
42 | #include <sys/mman.h> |
43 | 43 | ||
44 | #define CONSOLE_COUNT 12 |
- | |
45 | #define MAX_KEYREQUESTS_BUFFERED 32 |
44 | #define MAX_KEYREQUESTS_BUFFERED 32 |
46 | 45 | ||
47 | #define NAME "CONSOLE" |
46 | #define NAME "CONSOLE" |
48 | 47 | ||
49 | int active_console = 0; |
48 | int active_console = 0; |
50 | 49 | ||
51 | struct { |
50 | struct { |
52 | int phone; /**< Framebuffer phone */ |
51 | int phone; /**< Framebuffer phone */ |
53 | ipcarg_t rows; /**< Framebuffer rows */ |
52 | ipcarg_t rows; /**< Framebuffer rows */ |
54 | ipcarg_t cols; /**< Framebuffer columns */ |
53 | ipcarg_t cols; /**< Framebuffer columns */ |
55 | } fb_info; |
54 | } fb_info; |
56 | 55 | ||
57 | typedef struct { |
56 | typedef struct { |
58 | keybuffer_t keybuffer; |
57 | keybuffer_t keybuffer; |
59 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); |
58 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); |
60 | int keyrequest_counter; |
59 | int keyrequest_counter; |
61 | int client_phone; |
60 | int client_phone; |
62 | int used; |
61 | int used; |
63 | screenbuffer_t screenbuffer; |
62 | screenbuffer_t screenbuffer; |
64 | } connection_t; |
63 | } connection_t; |
65 | 64 | ||
66 | 65 | ||
67 | 66 | ||
68 | connection_t connections[CONSOLE_COUNT]; |
67 | connection_t connections[CONSOLE_COUNT]; |
69 | keyfield_t *interbuffer = NULL; |
68 | keyfield_t *interbuffer = NULL; |
70 | 69 | ||
71 | static int find_free_connection() |
70 | static int find_free_connection() |
72 | { |
71 | { |
73 | int i = 0; |
72 | int i = 0; |
74 | 73 | ||
75 | while (i < CONSOLE_COUNT) { |
74 | while (i < CONSOLE_COUNT) { |
76 | if (connections[i].used == 0) |
75 | if (connections[i].used == 0) |
77 | return i; |
76 | return i; |
78 | ++i; |
77 | ++i; |
79 | } |
78 | } |
80 | return CONSOLE_COUNT; |
79 | return CONSOLE_COUNT; |
81 | } |
80 | } |
82 | 81 | ||
83 | 82 | ||
84 | static int find_connection(int client_phone) |
83 | static int find_connection(int client_phone) |
85 | { |
84 | { |
86 | int i = 0; |
85 | int i = 0; |
87 | 86 | ||
88 | while (i < CONSOLE_COUNT) { |
87 | while (i < CONSOLE_COUNT) { |
89 | if (connections[i].client_phone == client_phone) |
88 | if (connections[i].client_phone == client_phone) |
90 | return i; |
89 | return i; |
91 | ++i; |
90 | ++i; |
92 | } |
91 | } |
93 | return CONSOLE_COUNT; |
92 | return CONSOLE_COUNT; |
94 | } |
93 | } |
95 | 94 | ||
96 | /** Check key and process special keys. |
95 | /** Check key and process special keys. |
97 | * |
96 | * |
98 | * */ |
97 | * */ |
99 | static void write_char(int console, char key) |
98 | static void write_char(int console, char key) |
100 | { |
99 | { |
101 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
100 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
102 | 101 | ||
103 | switch (key) { |
102 | switch (key) { |
104 | case '\n': |
103 | case '\n': |
105 | scr->position_y += 1; |
104 | scr->position_y += 1; |
106 | scr->position_x = 0; |
105 | scr->position_x = 0; |
107 | break; |
106 | break; |
108 | case '\r': |
107 | case '\r': |
109 | break; |
108 | break; |
110 | case '\t': |
109 | case '\t': |
111 | scr->position_x += 8; |
110 | scr->position_x += 8; |
112 | scr->position_x -= scr->position_x % 8; |
111 | scr->position_x -= scr->position_x % 8; |
113 | break; |
112 | break; |
114 | case '\b': |
113 | case '\b': |
115 | if (scr->position_x == 0) |
114 | if (scr->position_x == 0) |
116 | break; |
115 | break; |
117 | 116 | ||
118 | scr->position_x--; |
117 | scr->position_x--; |
119 | 118 | ||
120 | if (console == active_console) { |
119 | if (console == active_console) { |
121 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, ' ', scr->position_y, scr->position_x, NULL, NULL); |
120 | nsend_call_3(fb_info.phone, FB_PUTCHAR, ' ', scr->position_y, scr->position_x); |
122 | } |
121 | } |
123 | 122 | ||
124 | screenbuffer_putchar(scr, ' '); |
123 | screenbuffer_putchar(scr, ' '); |
125 | 124 | ||
126 | break; |
125 | break; |
127 | default: |
126 | default: |
128 | if (console == active_console) { |
127 | if (console == active_console) { |
129 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, key, scr->position_y, scr->position_x, NULL, NULL); |
128 | nsend_call_3(fb_info.phone, FB_PUTCHAR, key, scr->position_y, scr->position_x); |
130 | } |
129 | } |
131 | 130 | ||
132 | screenbuffer_putchar(scr, key); |
131 | screenbuffer_putchar(scr, key); |
133 | scr->position_x++; |
132 | scr->position_x++; |
134 | } |
133 | } |
135 | 134 | ||
136 | scr->position_y += (scr->position_x >= scr->size_x); |
135 | scr->position_y += (scr->position_x >= scr->size_x); |
137 | 136 | ||
138 | if (scr->position_y >= scr->size_y) { |
137 | if (scr->position_y >= scr->size_y) { |
139 | scr->position_y = scr->size_y - 1; |
138 | scr->position_y = scr->size_y - 1; |
140 | screenbuffer_clear_line(scr, scr->top_line++); |
139 | screenbuffer_clear_line(scr, scr->top_line++); |
- | 140 | if (console == active_console) |
|
141 | ipc_call_async(fb_info.phone, FB_SCROLL, 1, NULL, NULL); |
141 | nsend_call(fb_info.phone, FB_SCROLL, 1); |
142 | } |
142 | } |
143 | 143 | ||
144 | scr->position_x = scr->position_x % scr->size_x; |
144 | scr->position_x = scr->position_x % scr->size_x; |
145 | 145 | ||
146 | if (console == active_console) |
146 | if (console == active_console) |
147 | ipc_call_async_2(fb_info.phone, FB_CURSOR_GOTO, scr->position_y, scr->position_x, NULL, NULL); |
147 | send_call_2(fb_info.phone, FB_CURSOR_GOTO, scr->position_y, scr->position_x); |
148 | 148 | ||
149 | } |
149 | } |
150 | 150 | ||
151 | 151 | ||
152 | /* Handler for keyboard */ |
152 | /* Handler for keyboard */ |
153 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
153 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
154 | { |
154 | { |
155 | ipc_callid_t callid; |
155 | ipc_callid_t callid; |
156 | ipc_call_t call; |
156 | ipc_call_t call; |
157 | int retval; |
157 | int retval; |
158 | int i, j; |
158 | int i, j; |
159 | char c,d; |
159 | char c,d; |
160 | connection_t *conn; |
160 | connection_t *conn; |
161 | 161 | ||
162 | /* Ignore parameters, the connection is alread opened */ |
162 | /* Ignore parameters, the connection is alread opened */ |
163 | while (1) { |
163 | while (1) { |
164 | callid = async_get_call(&call); |
164 | callid = async_get_call(&call); |
165 | switch (IPC_GET_METHOD(call)) { |
165 | switch (IPC_GET_METHOD(call)) { |
166 | case IPC_M_PHONE_HUNGUP: |
166 | case IPC_M_PHONE_HUNGUP: |
167 | ipc_answer_fast(callid,0,0,0); |
167 | ipc_answer_fast(callid,0,0,0); |
168 | /* TODO: Handle hangup */ |
168 | /* TODO: Handle hangup */ |
169 | return; |
169 | return; |
170 | case KBD_PUSHCHAR: |
170 | case KBD_PUSHCHAR: |
171 | /* got key from keyboard driver */ |
171 | /* got key from keyboard driver */ |
172 | 172 | ||
173 | retval = 0; |
173 | retval = 0; |
174 | c = IPC_GET_ARG1(call) - '0'; |
174 | c = IPC_GET_ARG1(call) - '0'; |
175 | /* switch to another virtual console */ |
175 | /* switch to another virtual console */ |
176 | 176 | ||
177 | conn = &connections[active_console]; |
177 | conn = &connections[active_console]; |
178 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
178 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
179 | if ((c >= 0) && (c < CONSOLE_COUNT)) { |
179 | if ((c >= 0) && (c < CONSOLE_COUNT)) { |
180 | /*FIXME: draw another console content from buffer */ |
180 | /*FIXME: draw another console content from buffer */ |
181 | if (c == active_console) |
181 | if (c == active_console) |
182 | break; |
182 | break; |
183 | 183 | ||
184 | if (c == 0) { |
184 | if (c == 0) { |
185 | /* switch to kernel console*/ |
185 | /* switch to kernel console*/ |
186 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
186 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
187 | 187 | ||
188 | } else { |
188 | } else { |
189 | active_console = c; |
189 | active_console = c; |
190 | } |
190 | } |
191 | 191 | ||
192 | 192 | ||
193 | conn = &connections[active_console]; |
193 | conn = &connections[active_console]; |
194 | 194 | ||
195 | ipc_call_async(fb_info.phone, FB_CURSOR_VISIBILITY, 0, NULL, NULL); |
195 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 0); |
196 | 196 | ||
197 | if (interbuffer) { |
197 | if (interbuffer) { |
198 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
198 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
199 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
199 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
200 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
200 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
201 | 201 | ||
202 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
202 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
203 | } else { |
203 | } else { |
204 | - | ||
205 | ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL); |
204 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
206 | 205 | ||
207 | 206 | ||
208 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
207 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
209 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
208 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
210 | d = get_field_at(&(conn->screenbuffer),i, j)->character; |
209 | d = get_field_at(&(conn->screenbuffer),i, j)->character; |
211 | if (d && d != ' ') |
210 | if (d && d != ' ') |
212 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, d, j, i, NULL, NULL); |
211 | nsend_call_3(fb_info.phone, FB_PUTCHAR, d, j, i); |
213 | } |
212 | } |
214 | 213 | ||
215 | } |
214 | } |
216 | ipc_call_async_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x, NULL, NULL); |
215 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x); |
217 | ipc_call_async_2(fb_info.phone, FB_SET_STYLE, conn->screenbuffer.style.fg_color, \ |
216 | nsend_call_2(fb_info.phone, FB_SET_STYLE, conn->screenbuffer.style.fg_color, \ |
218 | conn->screenbuffer.style.bg_color, NULL, NULL); |
217 | conn->screenbuffer.style.bg_color); |
219 | ipc_call_async(fb_info.phone, FB_CURSOR_VISIBILITY, 1, NULL, NULL); |
218 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
220 | 219 | ||
221 | break; |
220 | break; |
222 | } |
221 | } |
223 | 222 | ||
224 | /* if client is awaiting key, send it */ |
223 | /* if client is awaiting key, send it */ |
225 | if (conn->keyrequest_counter > 0) { |
224 | if (conn->keyrequest_counter > 0) { |
226 | conn->keyrequest_counter--; |
225 | conn->keyrequest_counter--; |
227 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
226 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
228 | break; |
227 | break; |
229 | } |
228 | } |
230 | 229 | ||
231 | /*FIXME: else store key to its buffer */ |
230 | /*FIXME: else store key to its buffer */ |
232 | keybuffer_push(&conn->keybuffer, c); |
231 | keybuffer_push(&conn->keybuffer, c); |
233 | 232 | ||
234 | break; |
233 | break; |
235 | default: |
234 | default: |
236 | retval = ENOENT; |
235 | retval = ENOENT; |
237 | } |
236 | } |
238 | ipc_answer_fast(callid, retval, 0, 0); |
237 | ipc_answer_fast(callid, retval, 0, 0); |
239 | } |
238 | } |
240 | } |
239 | } |
241 | 240 | ||
242 | /** Default thread for new connections */ |
241 | /** Default thread for new connections */ |
243 | void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
242 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
244 | { |
243 | { |
245 | ipc_callid_t callid; |
244 | ipc_callid_t callid; |
246 | ipc_call_t call; |
245 | ipc_call_t call; |
247 | int consnum; |
246 | int consnum; |
248 | ipcarg_t arg1; |
247 | ipcarg_t arg1; |
249 | 248 | ||
250 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
249 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
251 | ipc_answer_fast(iid,ELIMIT,0,0); |
250 | ipc_answer_fast(iid,ELIMIT,0,0); |
252 | return; |
251 | return; |
253 | } |
252 | } |
254 | 253 | ||
255 | connections[consnum].used = 1; |
254 | connections[consnum].used = 1; |
256 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
255 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
257 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
256 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
258 | 257 | ||
259 | /* Accept the connection */ |
258 | /* Accept the connection */ |
260 | ipc_answer_fast(iid,0,0,0); |
259 | ipc_answer_fast(iid,0,0,0); |
261 | 260 | ||
262 | while (1) { |
261 | while (1) { |
263 | callid = async_get_call(&call); |
262 | callid = async_get_call(&call); |
264 | switch (IPC_GET_METHOD(call)) { |
263 | switch (IPC_GET_METHOD(call)) { |
265 | case IPC_M_PHONE_HUNGUP: |
264 | case IPC_M_PHONE_HUNGUP: |
266 | /* TODO */ |
265 | /* TODO */ |
267 | ipc_answer_fast(callid, 0,0,0); |
266 | ipc_answer_fast(callid, 0,0,0); |
268 | return; |
267 | return; |
269 | case CONSOLE_PUTCHAR: |
268 | case CONSOLE_PUTCHAR: |
270 | write_char(consnum, IPC_GET_ARG1(call)); |
269 | write_char(consnum, IPC_GET_ARG1(call)); |
271 | break; |
270 | break; |
272 | case CONSOLE_CLEAR: |
271 | case CONSOLE_CLEAR: |
273 | /* Send message to fb */ |
272 | /* Send message to fb */ |
274 | if (consnum == active_console) { |
273 | if (consnum == active_console) { |
275 | ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL); |
274 | send_call(fb_info.phone, FB_CLEAR, 0); |
276 | } |
275 | } |
277 | 276 | ||
278 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
277 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
279 | 278 | ||
280 | break; |
279 | break; |
281 | case CONSOLE_GOTO: |
280 | case CONSOLE_GOTO: |
282 | 281 | ||
283 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
282 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
284 | 283 | ||
285 | break; |
284 | break; |
286 | 285 | ||
287 | case CONSOLE_GETCHAR: |
286 | case CONSOLE_GETCHAR: |
288 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
287 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
289 | /* buffer is empty -> store request */ |
288 | /* buffer is empty -> store request */ |
290 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
289 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
291 | fifo_push(connections[consnum].keyrequests, callid); |
290 | fifo_push(connections[consnum].keyrequests, callid); |
292 | connections[consnum].keyrequest_counter++; |
291 | connections[consnum].keyrequest_counter++; |
293 | } else { |
292 | } else { |
294 | /* no key available and too many requests => fail */ |
293 | /* no key available and too many requests => fail */ |
295 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
294 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
296 | } |
295 | } |
297 | continue; |
296 | continue; |
298 | }; |
297 | }; |
299 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
298 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
300 | 299 | ||
301 | break; |
300 | break; |
302 | } |
301 | } |
303 | ipc_answer_fast(callid, 0, arg1, 0); |
302 | ipc_answer_fast(callid, 0, arg1, 0); |
304 | } |
303 | } |
305 | } |
304 | } |
306 | 305 | ||
307 | int main(int argc, char *argv[]) |
306 | int main(int argc, char *argv[]) |
308 | { |
307 | { |
309 | ipcarg_t phonehash; |
308 | ipcarg_t phonehash; |
310 | int kbd_phone, fb_phone; |
309 | int kbd_phone, fb_phone; |
311 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
310 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
312 | int i; |
311 | int i; |
313 | 312 | ||
314 | async_set_client_connection(client_connection); |
313 | async_set_client_connection(client_connection); |
315 | 314 | ||
316 | /* Connect to keyboard driver */ |
315 | /* Connect to keyboard driver */ |
317 | 316 | ||
318 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
317 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
319 | usleep(10000); |
318 | usleep(10000); |
320 | }; |
319 | }; |
321 | 320 | ||
322 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
321 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
323 | return -1; |
322 | return -1; |
324 | }; |
323 | }; |
325 | 324 | ||
326 | /* Connect to framebuffer driver */ |
325 | /* Connect to framebuffer driver */ |
327 | 326 | ||
328 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
327 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
329 | usleep(10000); |
328 | usleep(10000); |
330 | } |
329 | } |
331 | 330 | ||
332 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
331 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
333 | ipc_call_async_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR, NULL, NULL); |
332 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
334 | ipc_call_sync(fb_info.phone, FB_CURSOR_VISIBILITY, 1, NULL); |
333 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
335 | 334 | ||
336 | /* Init virtual consoles */ |
335 | /* Init virtual consoles */ |
337 | for (i = 0; i < CONSOLE_COUNT; i++) { |
336 | for (i = 0; i < CONSOLE_COUNT; i++) { |
338 | connections[i].used = 0; |
337 | connections[i].used = 0; |
339 | keybuffer_init(&(connections[i].keybuffer)); |
338 | keybuffer_init(&(connections[i].keybuffer)); |
340 | 339 | ||
341 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
340 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
342 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
341 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
343 | connections[i].keyrequest_counter = 0; |
342 | connections[i].keyrequest_counter = 0; |
344 | 343 | ||
345 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
344 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
346 | /*FIXME: handle error */ |
345 | /*FIXME: handle error */ |
347 | return -1; |
346 | return -1; |
348 | } |
347 | } |
349 | } |
348 | } |
350 | 349 | ||
351 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
350 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
352 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ | AS_AREA_CACHEABLE, NULL, NULL, NULL) != 0) { |
351 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ | AS_AREA_CACHEABLE, NULL, NULL, NULL) != 0) { |
353 | // ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '?', 10, 10, NULL, NULL); |
352 | // ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '?', 10, 10, NULL, NULL); |
354 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
353 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
355 | interbuffer = NULL; |
354 | interbuffer = NULL; |
356 | } |
355 | } |
357 | /* } else { |
356 | /* } else { |
358 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '!', 10, 10, NULL, NULL); |
357 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '!', 10, 10, NULL, NULL); |
359 | */ |
358 | */ |
360 | } |
359 | } |
361 | 360 | ||
362 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
361 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
363 | 362 | ||
364 | ipc_call_async_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0, NULL, NULL); |
363 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0); |
365 | 364 | ||
- | 365 | /* Register at NS */ |
|
366 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
366 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
367 | return -1; |
367 | return -1; |
368 | }; |
368 | }; |
369 | 369 | ||
370 | async_manager(); |
370 | async_manager(); |
371 | 371 | ||
372 | return 0; |
372 | return 0; |
373 | } |
373 | } |
374 | 374 |