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