generic/kbd.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Josef Cejka
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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                 /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
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         /* Initialize arch dependent parts */
00124         if (kbd_arch_init())
00125                 return -1;
00126         
00127         /* Initialize key buffer */
00128         keybuffer_init(&keybuffer);
00129         
00130         async_set_client_connection(console_connection);
00131         async_set_interrupt_received(irq_handler);
00132         /* Register service at nameserver */
00133         if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead) != 0)
00134                 return -1;
00135 
00136         async_manager();
00137 
00138         /* Never reached */
00139         return 0;
00140 }
00141 

Generated on Sun Jun 18 18:00:18 2006 for HelenOS Userspace (ia64) by  doxygen 1.4.6