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