Subversion Repositories HelenOS-historic

Rev

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

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