Changeset 111d2d6 in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2012-08-17T17:05:06Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 01e397ac
- Parents:
- ad78054
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
rad78054 r111d2d6 36 36 #include <stdio.h> 37 37 #include <adt/prodcons.h> 38 #include <i pc/input.h>38 #include <io/input.h> 39 39 #include <ipc/console.h> 40 40 #include <ipc/vfs.h> … … 43 43 #include <loc.h> 44 44 #include <event.h> 45 #include <io/kbd_event.h> 45 46 #include <io/keycode.h> 46 47 #include <io/chargrid.h> … … 81 82 } console_t; 82 83 83 /** Session to the input server*/84 static async_sess_t *input_sess;84 /** Input server proxy */ 85 static input_t *input; 85 86 86 87 /** Session to the output server */ … … 100 101 static console_t *active_console = &consoles[0]; 101 102 static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; 103 104 static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t); 105 static int input_ev_move(input_t *, int, int); 106 static int input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned); 107 static int input_ev_button(input_t *, int, int); 108 109 static input_ev_ops_t input_ev_ops = { 110 .key = input_ev_key, 111 .move = input_ev_move, 112 .abs_move = input_ev_abs_move, 113 .button = input_ev_button 114 }; 102 115 103 116 static void cons_update(console_t *cons) … … 195 208 } 196 209 197 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 198 { 199 /* Ignore parameters, the connection is already opened */ 200 while (true) { 201 ipc_call_t call; 202 ipc_callid_t callid = async_get_call(&call); 203 204 if (!IPC_GET_IMETHOD(call)) { 205 /* TODO: Handle hangup */ 206 async_hangup(input_sess); 207 return; 208 } 209 210 kbd_event_type_t type; 211 keycode_t key; 212 keymod_t mods; 213 wchar_t c; 214 215 switch (IPC_GET_IMETHOD(call)) { 216 case INPUT_EVENT_KEY: 217 type = IPC_GET_ARG1(call); 218 key = IPC_GET_ARG2(call); 219 mods = IPC_GET_ARG3(call); 220 c = IPC_GET_ARG4(call); 221 222 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 223 ((mods & KM_CTRL) == 0)) 224 cons_switch(&consoles[key - KC_F1]); 225 else { 226 /* Got key press/release event */ 227 kbd_event_t *event = 228 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 229 if (event == NULL) { 230 async_answer_0(callid, ENOMEM); 231 break; 232 } 233 234 link_initialize(&event->link); 235 event->type = type; 236 event->key = key; 237 event->mods = mods; 238 event->c = c; 239 240 /* 241 * Kernel console does not read events 242 * from us, so we will redirect them 243 * to the (last) active userspace console 244 * if necessary. 245 */ 246 console_t *target_console = cons_get_active_uspace(); 247 248 prodcons_produce(&target_console->input_pc, 249 &event->link); 250 } 251 252 async_answer_0(callid, EOK); 253 break; 254 case INPUT_EVENT_MOVE: 255 async_answer_0(callid, EOK); 256 break; 257 case INPUT_EVENT_BUTTON: 258 async_answer_0(callid, EOK); 259 break; 260 default: 261 async_answer_0(callid, EINVAL); 262 } 263 } 210 static int input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key, 211 keymod_t mods, wchar_t c) 212 { 213 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 214 ((mods & KM_CTRL) == 0)) { 215 cons_switch(&consoles[key - KC_F1]); 216 } else { 217 /* Got key press/release event */ 218 kbd_event_t *event = 219 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 220 if (event == NULL) { 221 return ENOMEM; 222 } 223 224 link_initialize(&event->link); 225 event->type = type; 226 event->key = key; 227 event->mods = mods; 228 event->c = c; 229 230 /* 231 * Kernel console does not read events 232 * from us, so we will redirect them 233 * to the (last) active userspace console 234 * if necessary. 235 */ 236 console_t *target_console = cons_get_active_uspace(); 237 238 prodcons_produce(&target_console->input_pc, 239 &event->link); 240 } 241 242 return EOK; 243 } 244 245 static int input_ev_move(input_t *input, int dx, int dy) 246 { 247 return EOK; 248 } 249 250 static int input_ev_abs_move(input_t *input, unsigned x , unsigned y, 251 unsigned max_x, unsigned max_y) 252 { 253 return EOK; 254 } 255 256 static int input_ev_button(input_t *input, int bnum, int bpress) 257 { 258 return EOK; 264 259 } 265 260 … … 518 513 } 519 514 520 static async_sess_t *input_connect(const char *svc)515 static int input_connect(const char *svc) 521 516 { 522 517 async_sess_t *sess; … … 524 519 525 520 int rc = loc_service_get_id(svc, &dsid, 0); 526 if (rc == EOK) { 527 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 528 if (sess == NULL) { 529 printf("%s: Unable to connect to input service %s\n", NAME, 530 svc); 531 return NULL; 532 } 533 } else 534 return NULL; 535 536 async_exch_t *exch = async_exchange_begin(sess); 537 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 538 async_exchange_end(exch); 539 521 if (rc != EOK) { 522 printf("%s: Input service %s not found\n", NAME, svc); 523 return rc; 524 } 525 526 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 527 if (sess == NULL) { 528 printf("%s: Unable to connect to input service %s\n", NAME, 529 svc); 530 return EIO; 531 } 532 533 rc = input_open(sess, &input_ev_ops, NULL, &input); 540 534 if (rc != EOK) { 541 535 async_hangup(sess); 542 printf("%s: Unable to c reate callback connection toservice %s (%s)\n",536 printf("%s: Unable to communicate with service %s (%s)\n", 543 537 NAME, svc, str_error(rc)); 544 return NULL;545 } 546 547 return sess;538 return rc; 539 } 540 541 return EOK; 548 542 } 549 543 … … 574 568 static bool console_srv_init(char *input_svc, char *output_svc) 575 569 { 570 int rc; 571 576 572 /* Connect to input service */ 577 input_sess= input_connect(input_svc);578 if ( input_sess == NULL)573 rc = input_connect(input_svc); 574 if (rc != EOK) 579 575 return false; 580 576 … … 586 582 /* Register server */ 587 583 async_set_client_connection(client_connection); 588 intrc = loc_server_register(NAME);584 rc = loc_server_register(NAME); 589 585 if (rc != EOK) { 590 586 printf("%s: Unable to register server (%s)\n", NAME,
Note:
See TracChangeset
for help on using the changeset viewer.