Subversion Repositories HelenOS-historic

Rev

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

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