Subversion Repositories HelenOS-historic

Rev

Rev 1506 | Rev 1514 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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