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
00041 #include <ipc/mouse.h>
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <async.h>
00045 #include <errno.h>
00046 #include <devmap.h>
00047
00048 #include <char_mouse.h>
00049 #include <mouse_port.h>
00050 #include <mouse_proto.h>
00051
00052 #define NAME "mouse"
00053 #define NAMESPACE "hid_in"
00054
00055 int client_phone = -1;
00056
00057 void mouse_handle_byte(int byte)
00058 {
00059
00060 mouse_proto_parse_byte(byte);
00061 }
00062
00063 void mouse_ev_btn(int button, int press)
00064 {
00065
00066 if (client_phone != -1) {
00067 async_msg_2(client_phone, MEVENT_BUTTON, button, press);
00068 }
00069 }
00070
00071 void mouse_ev_move(int dx, int dy)
00072 {
00073
00074 if (client_phone != -1)
00075 async_msg_2(client_phone, MEVENT_MOVE, dx, dy);
00076 }
00077
00078 static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
00079 {
00080 ipc_callid_t callid;
00081 ipc_call_t call;
00082 int retval;
00083
00084 async_answer_0(iid, EOK);
00085
00086 while (1) {
00087 callid = async_get_call(&call);
00088 switch (IPC_GET_IMETHOD(call)) {
00089 case IPC_M_PHONE_HUNGUP:
00090 if (client_phone != -1) {
00091 async_hangup(client_phone);
00092 client_phone = -1;
00093 }
00094
00095 async_answer_0(callid, EOK);
00096 return;
00097 case IPC_M_CONNECT_TO_ME:
00098 if (client_phone != -1) {
00099 retval = ELIMIT;
00100 break;
00101 }
00102 client_phone = IPC_GET_ARG5(call);
00103 retval = 0;
00104 break;
00105 default:
00106 retval = EINVAL;
00107 }
00108 async_answer_0(callid, retval);
00109 }
00110 }
00111
00112
00113 int main(int argc, char **argv)
00114 {
00115 printf(NAME ": Chardev mouse driver\n");
00116
00117
00118 if (mouse_port_init() != 0)
00119 return -1;
00120
00121
00122 if (mouse_proto_init() != 0)
00123 return -1;
00124
00125
00126 int rc = devmap_driver_register(NAME, client_connection);
00127 if (rc < 0) {
00128 printf(NAME ": Unable to register driver (%d)\n", rc);
00129 return -1;
00130 }
00131
00132 char dev_path[DEVMAP_NAME_MAXLEN + 1];
00133 snprintf(dev_path, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
00134
00135 devmap_handle_t devmap_handle;
00136 if (devmap_device_register(dev_path, &devmap_handle) != EOK) {
00137 printf(NAME ": Unable to register device %s\n", dev_path);
00138 return -1;
00139 }
00140
00141 printf(NAME ": Accepting connections\n");
00142 task_retval(0);
00143 async_manager();
00144
00145
00146 return 0;
00147 }
00148