Changes in uspace/srv/hid/input/input.c [a35b458:5a6cc679] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/input.c
ra35b458 r5a6cc679 54 54 #include <stdio.h> 55 55 #include <stdlib.h> 56 #include <str.h>57 56 #include <str_error.h> 58 57 … … 78 77 /** Link into the list of clients */ 79 78 link_t link; 80 79 81 80 /** Indicate whether the client is active */ 82 81 bool active; 83 82 84 83 /** Client callback session */ 85 84 async_sess_t *sess; … … 112 111 if (client == NULL) 113 112 return NULL; 114 113 115 114 link_initialize(&client->link); 116 115 client->active = false; 117 116 client->sess = NULL; 118 117 119 118 list_append(&client->link, &clients); 120 119 121 120 return client; 122 121 } … … 125 124 { 126 125 client_t *client = (client_t *) data; 127 126 128 127 list_remove(&client->link); 129 128 free(client); … … 144 143 kbd_event_t ev; 145 144 unsigned int mod_mask; 146 145 147 146 switch (key) { 148 147 case KC_LCTRL: … … 167 166 mod_mask = 0; 168 167 } 169 168 170 169 if (mod_mask != 0) { 171 170 if (type == KEY_PRESS) … … 174 173 kdev->mods = kdev->mods & ~mod_mask; 175 174 } 176 175 177 176 switch (key) { 178 177 case KC_CAPS_LOCK: … … 188 187 mod_mask = 0; 189 188 } 190 189 191 190 if (mod_mask != 0) { 192 191 if (type == KEY_PRESS) { … … 198 197 kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys); 199 198 kdev->lock_keys = kdev->lock_keys | mod_mask; 200 199 201 200 /* Update keyboard lock indicator lights. */ 202 201 (*kdev->ctl_ops->set_ind)(kdev, kdev->mods); … … 205 204 } 206 205 } 207 206 208 207 // TODO: More elegant layout switching 209 208 210 209 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) && 211 210 (key == KC_F1)) { … … 214 213 return; 215 214 } 216 215 217 216 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) && 218 217 (key == KC_F2)) { … … 221 220 return; 222 221 } 223 222 224 223 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) && 225 224 (key == KC_F3)) { … … 228 227 return; 229 228 } 230 229 231 230 if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) && 232 231 (key == KC_F4)) { … … 235 234 return; 236 235 } 237 236 238 237 ev.type = type; 239 238 ev.key = key; 240 239 ev.mods = kdev->mods; 241 240 242 241 ev.c = layout_parse_ev(kdev->active_layout, &ev); 243 242 244 243 list_foreach(clients, link, client_t, client) { 245 244 if (client->active) { … … 257 256 if (client->active) { 258 257 async_exch_t *exch = async_exchange_begin(client->sess); 259 258 260 259 if ((dx) || (dy)) 261 260 async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy); 262 261 263 262 if (dz) { 264 263 // TODO: Implement proper wheel support 265 264 keycode_t code = dz > 0 ? KC_UP : KC_DOWN; 266 265 267 266 for (unsigned int i = 0; i < 3; i++) 268 267 async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0); 269 268 270 269 async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0); 271 270 } 272 271 273 272 async_exchange_end(exch); 274 273 } … … 309 308 list_foreach(clients, link, client_t, client) 310 309 client->active = ((active) && (client == active_client)); 311 310 312 311 /* Notify clients about the arbitration */ 313 312 list_foreach(clients, link, client_t, client) { … … 327 326 return; 328 327 } 329 328 330 329 async_answer_0(iid, EOK); 331 330 332 331 while (true) { 333 332 ipc_call_t call; 334 333 ipc_callid_t callid = async_get_call(&call); 335 334 336 335 if (!IPC_GET_IMETHOD(call)) { 337 336 if (client->sess != NULL) { … … 339 338 client->sess = NULL; 340 339 } 341 340 342 341 async_answer_0(callid, EOK); 343 342 return; 344 343 } 345 344 346 345 async_sess_t *sess = 347 346 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); … … 375 374 active = true; 376 375 } 377 376 378 377 client_arbitration(); 379 378 } … … 387 386 return NULL; 388 387 } 389 388 390 389 link_initialize(&kdev->link); 391 390 392 391 kdev->mods = KM_NUM_LOCK; 393 392 kdev->lock_keys = 0; 394 393 kdev->active_layout = layout_create(layout[0]); 395 394 396 395 return kdev; 397 396 } … … 405 404 return NULL; 406 405 } 407 406 408 407 link_initialize(&mdev->link); 409 408 410 409 return mdev; 411 410 } … … 419 418 return NULL; 420 419 } 421 420 422 421 sdev->kdev = kbd_dev_new(); 423 422 if (sdev->kdev == NULL) { … … 427 426 428 427 link_initialize(&sdev->link); 429 428 430 429 return sdev; 431 430 } … … 437 436 if (kdev == NULL) 438 437 return; 439 438 440 439 kdev->port_ops = port; 441 440 kdev->ctl_ops = ctl; 442 441 kdev->svc_id = 0; 443 442 444 443 /* Initialize port driver. */ 445 444 if ((*kdev->port_ops->init)(kdev) != 0) 446 445 goto fail; 447 446 448 447 /* Initialize controller driver. */ 449 448 if ((*kdev->ctl_ops->init)(kdev) != 0) { … … 451 450 goto fail; 452 451 } 453 452 454 453 list_append(&kdev->link, &kbd_devs); 455 454 return; 456 455 457 456 fail: 458 457 free(kdev); … … 469 468 if (kdev == NULL) 470 469 return -1; 471 470 472 471 kdev->svc_id = service_id; 473 472 kdev->port_ops = NULL; 474 473 kdev->ctl_ops = &kbdev_ctl; 475 474 476 475 errno_t rc = loc_service_get_name(service_id, &kdev->svc_name); 477 476 if (rc != EOK) { … … 479 478 goto fail; 480 479 } 481 480 482 481 /* Initialize controller driver. */ 483 482 if ((*kdev->ctl_ops->init)(kdev) != 0) { 484 483 goto fail; 485 484 } 486 485 487 486 list_append(&kdev->link, &kbd_devs); 488 487 *kdevp = kdev; 489 488 return 0; 490 489 491 490 fail: 492 491 if (kdev->svc_name != NULL) … … 506 505 if (mdev == NULL) 507 506 return -1; 508 507 509 508 mdev->svc_id = service_id; 510 509 mdev->port_ops = NULL; 511 510 mdev->proto_ops = &mousedev_proto; 512 511 513 512 errno_t rc = loc_service_get_name(service_id, &mdev->svc_name); 514 513 if (rc != EOK) { … … 516 515 goto fail; 517 516 } 518 517 519 518 /* Initialize controller driver. */ 520 519 if ((*mdev->proto_ops->init)(mdev) != 0) { 521 520 goto fail; 522 521 } 523 522 524 523 list_append(&mdev->link, &mouse_devs); 525 524 *mdevp = mdev; 526 525 return 0; 527 526 528 527 fail: 529 528 free(mdev); … … 560 559 if (sdev == NULL) 561 560 return -1; 562 561 563 562 sdev->kdev->svc_id = service_id; 564 563 565 564 rc = loc_service_get_name(service_id, &sdev->kdev->svc_name); 566 565 if (rc != EOK) … … 598 597 fibril_add_ready(fid); 599 598 } 600 599 601 600 *sdevp = sdev; 602 601 return 0; 603 602 604 603 fail: 605 604 if (sdev->kdev->svc_name != NULL) … … 641 640 bool already_known; 642 641 errno_t rc; 643 642 644 643 rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING); 645 644 if (rc != EOK) { … … 647 646 return ENOENT; 648 647 } 649 648 650 649 /* 651 650 * Check for new keyboard devices … … 660 659 for (i = 0; i < count; i++) { 661 660 already_known = false; 662 661 663 662 /* Determine whether we already know this device. */ 664 663 list_foreach(kbd_devs, link, kbd_dev_t, kdev) { … … 668 667 } 669 668 } 670 669 671 670 if (!already_known) { 672 671 kbd_dev_t *kdev; … … 677 676 } 678 677 } 679 678 680 679 free(svcs); 681 680 682 681 /* XXX Handle device removal */ 683 682 684 683 return EOK; 685 684 } … … 692 691 bool already_known; 693 692 errno_t rc; 694 693 695 694 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 696 695 if (rc != EOK) { … … 698 697 return ENOENT; 699 698 } 700 699 701 700 /* 702 701 * Check for new mouse devices … … 708 707 return EIO; 709 708 } 710 709 711 710 for (i = 0; i < count; i++) { 712 711 already_known = false; 713 712 714 713 /* Determine whether we already know this device. */ 715 714 list_foreach(mouse_devs, link, mouse_dev_t, mdev) { … … 719 718 } 720 719 } 721 720 722 721 if (!already_known) { 723 722 mouse_dev_t *mdev; … … 728 727 } 729 728 } 730 729 731 730 free(svcs); 732 731 733 732 /* XXX Handle device removal */ 734 733 735 734 return EOK; 736 735 } … … 743 742 bool already_known; 744 743 errno_t rc; 745 744 746 745 rc = loc_category_get_id("serial", &serial_cat, IPC_FLAG_BLOCKING); 747 746 if (rc != EOK) { … … 749 748 return ENOENT; 750 749 } 751 750 752 751 /* 753 752 * Check for new serial devices … … 762 761 for (i = 0; i < count; i++) { 763 762 already_known = false; 764 763 765 764 /* Determine whether we already know this device. */ 766 765 list_foreach(serial_devs, link, serial_dev_t, sdev) { … … 770 769 } 771 770 } 772 771 773 772 if (!already_known) { 774 773 serial_dev_t *sdev; … … 779 778 } 780 779 } 781 780 782 781 free(svcs); 783 782 784 783 /* XXX Handle device removal */ 785 784 786 785 return EOK; 787 786 } … … 790 789 { 791 790 errno_t rc; 792 791 793 792 fibril_mutex_lock(&discovery_lock); 794 793 795 794 if (!serial_console) { 796 795 rc = dev_check_new_kbdevs(); … … 799 798 return rc; 800 799 } 801 800 802 801 rc = dev_check_new_mousedevs(); 803 802 if (rc != EOK) { … … 812 811 } 813 812 } 814 813 815 814 fibril_mutex_unlock(&discovery_lock); 816 815 817 816 return EOK; 818 817 } … … 832 831 return rc; 833 832 } 834 833 835 834 return dev_check_new(); 836 835 } … … 849 848 return 1; 850 849 } 851 850 852 851 printf("%s: HelenOS input service\n", NAME); 853 852 854 853 list_initialize(&clients); 855 854 list_initialize(&kbd_devs); 856 855 list_initialize(&mouse_devs); 857 856 list_initialize(&serial_devs); 858 857 859 858 serial_console = config_get_value("console"); 860 859 861 860 /* Add legacy keyboard devices. */ 862 861 kbd_add_legacy_devs(); 863 862 864 863 /* Register driver */ 865 864 async_set_client_data_constructor(client_data_create); 866 865 async_set_client_data_destructor(client_data_destroy); 867 866 async_set_fallback_port_handler(client_connection, NULL); 868 867 869 868 rc = loc_server_register(NAME); 870 869 if (rc != EOK) { … … 872 871 return rc; 873 872 } 874 873 875 874 service_id_t service_id; 876 875 rc = loc_service_register(argv[1], &service_id); … … 879 878 return rc; 880 879 } 881 880 882 881 /* Receive kernel notifications */ 883 882 rc = async_event_subscribe(EVENT_KCONSOLE, kconsole_event_handler, NULL); … … 885 884 printf("%s: Failed to register kconsole notifications (%s)\n", 886 885 NAME, str_error(rc)); 887 886 888 887 /* Start looking for new input devices */ 889 888 input_start_dev_discovery(); 890 889 891 890 printf("%s: Accepting connections\n", NAME); 892 891 task_retval(0); 893 892 async_manager(); 894 893 895 894 /* Not reached. */ 896 895 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.