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