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