00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #include <ipc/ipc.h>
00039 #include <ipc/services.h>
00040 #include <stdio.h>
00041 #include <unistd.h>
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 #include <ipc/ns.h>
00045 #include <errno.h>
00046 #include <arch/kbd.h>
00047 #include <kbd.h>
00048 #include <libadt/fifo.h>
00049 #include <key_buffer.h>
00050 #include <async.h>
00051 #include <keys.h>
00052
00053 #define NAME "KBD"
00054
00055 int cons_connected = 0;
00056 int phone2cons = -1;
00057 keybuffer_t keybuffer;
00058
00059 static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
00060 {
00061 int chr;
00062
00063 #ifdef MOUSE_ENABLED
00064 if (mouse_arch_process(phone2cons, call))
00065 return;
00066 #endif
00067
00068 kbd_arch_process(&keybuffer, call);
00069
00070 if (cons_connected && phone2cons != -1) {
00071
00072 while (!keybuffer_empty(&keybuffer)) {
00073 if (!keybuffer_pop(&keybuffer, (int *)&chr))
00074 break;
00075
00076 async_msg(phone2cons, KBD_PUSHCHAR, chr);
00077 }
00078 }
00079 }
00080
00081 static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
00082 {
00083 ipc_callid_t callid;
00084 ipc_call_t call;
00085 int retval;
00086
00087 if (cons_connected) {
00088 ipc_answer_fast(iid, ELIMIT, 0, 0);
00089 return;
00090 }
00091 cons_connected = 1;
00092 ipc_answer_fast(iid, 0, 0, 0);
00093
00094 while (1) {
00095 callid = async_get_call(&call);
00096 switch (IPC_GET_METHOD(call)) {
00097 case IPC_M_PHONE_HUNGUP:
00098 cons_connected = 0;
00099 ipc_hangup(phone2cons);
00100 phone2cons = -1;
00101 ipc_answer_fast(callid, 0,0,0);
00102 return;
00103 case IPC_M_CONNECT_TO_ME:
00104 if (phone2cons != -1) {
00105 retval = ELIMIT;
00106 break;
00107 }
00108 phone2cons = IPC_GET_ARG3(call);
00109 retval = 0;
00110 break;
00111 default:
00112 retval = EINVAL;
00113 }
00114 ipc_answer_fast(callid, retval, 0, 0);
00115 }
00116 }
00117
00118
00119 int main(int argc, char **argv)
00120 {
00121 ipcarg_t phonead;
00122
00123
00124 if (kbd_arch_init())
00125 return -1;
00126
00127
00128 keybuffer_init(&keybuffer);
00129
00130 async_set_client_connection(console_connection);
00131 async_set_interrupt_received(irq_handler);
00132
00133 if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead) != 0)
00134 return -1;
00135
00136 async_manager();
00137
00138
00139 return 0;
00140 }
00141