Changes in uspace/srv/hid/input/generic/input.c [cce8a83:99ac5cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
rcce8a83 r99ac5cf 66 66 #include <abi/ipc/methods.h> 67 67 68 /* In microseconds */69 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000)70 71 68 #define NUM_LAYOUTS 3 72 69 … … 497 494 } 498 495 499 /** Periodically check for new input devices. 500 * 501 * Looks under /loc/class/keyboard and /loc/class/mouse. 502 * 503 * @param arg Ignored 504 * 505 */ 506 static int dev_discovery_fibril(void *arg) 507 { 508 category_id_t keyboard_cat, mouse_cat; 496 static int dev_check_new_kbdevs(void) 497 { 498 category_id_t keyboard_cat; 509 499 service_id_t *svcs; 510 500 size_t count, i; … … 518 508 } 519 509 510 /* 511 * Check for new keyboard devices 512 */ 513 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count); 514 if (rc != EOK) { 515 printf("%s: Failed getting list of keyboard devices.\n", 516 NAME); 517 return EIO; 518 } 519 520 for (i = 0; i < count; i++) { 521 already_known = false; 522 523 /* Determine whether we already know this device. */ 524 list_foreach(kbd_devs, kdev_link) { 525 kbd_dev_t *kdev = list_get_instance(kdev_link, 526 kbd_dev_t, kbd_devs); 527 if (kdev->svc_id == svcs[i]) { 528 already_known = true; 529 break; 530 } 531 } 532 533 if (!already_known) { 534 kbd_dev_t *kdev; 535 if (kbd_add_kbdev(svcs[i], &kdev) == EOK) { 536 printf("%s: Connected keyboard device '%s'\n", 537 NAME, kdev->svc_name); 538 } 539 } 540 } 541 542 free(svcs); 543 544 /* XXX Handle device removal */ 545 546 return EOK; 547 } 548 549 static int dev_check_new_mousedevs(void) 550 { 551 category_id_t mouse_cat; 552 service_id_t *svcs; 553 size_t count, i; 554 bool already_known; 555 int rc; 556 520 557 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 521 558 if (rc != EOK) { … … 524 561 } 525 562 526 while (true) { 527 async_usleep(DISCOVERY_POLL_INTERVAL); 528 529 /* 530 * Check for new keyboard devices 531 */ 532 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count); 533 if (rc != EOK) { 534 printf("%s: Failed getting list of keyboard devices.\n", 535 NAME); 536 continue; 537 } 538 539 for (i = 0; i < count; i++) { 540 already_known = false; 541 542 /* Determine whether we already know this device. */ 543 list_foreach(kbd_devs, kdev_link) { 544 kbd_dev_t *kdev = list_get_instance(kdev_link, 545 kbd_dev_t, kbd_devs); 546 if (kdev->svc_id == svcs[i]) { 547 already_known = true; 548 break; 549 } 550 } 551 552 if (!already_known) { 553 kbd_dev_t *kdev; 554 if (kbd_add_kbdev(svcs[i], &kdev) == EOK) { 555 printf("%s: Connected keyboard device '%s'\n", 556 NAME, kdev->svc_name); 557 } 563 /* 564 * Check for new mouse devices 565 */ 566 rc = loc_category_get_svcs(mouse_cat, &svcs, &count); 567 if (rc != EOK) { 568 printf("%s: Failed getting list of mouse devices.\n", 569 NAME); 570 return EIO; 571 } 572 573 for (i = 0; i < count; i++) { 574 already_known = false; 575 576 /* Determine whether we already know this device. */ 577 list_foreach(mouse_devs, mdev_link) { 578 mouse_dev_t *mdev = list_get_instance(mdev_link, 579 mouse_dev_t, mouse_devs); 580 if (mdev->svc_id == svcs[i]) { 581 already_known = true; 582 break; 558 583 } 559 584 } 560 585 561 /* XXX Handle device removal */ 562 563 /* 564 * Check for new mouse devices 565 */ 566 rc = loc_category_get_svcs(mouse_cat, &svcs, &count); 567 if (rc != EOK) { 568 printf("%s: Failed getting list of mouse devices.\n", 569 NAME); 570 continue; 571 } 572 573 for (i = 0; i < count; i++) { 574 already_known = false; 575 576 /* Determine whether we already know this device. */ 577 list_foreach(mouse_devs, mdev_link) { 578 mouse_dev_t *mdev = list_get_instance(mdev_link, 579 mouse_dev_t, mouse_devs); 580 if (mdev->svc_id == svcs[i]) { 581 already_known = true; 582 break; 583 } 584 } 585 586 if (!already_known) { 587 mouse_dev_t *mdev; 588 if (mouse_add_mousedev(svcs[i], &mdev) == EOK) { 589 printf("%s: Connected mouse device '%s'\n", 590 NAME, mdev->svc_name); 591 } 586 if (!already_known) { 587 mouse_dev_t *mdev; 588 if (mouse_add_mousedev(svcs[i], &mdev) == EOK) { 589 printf("%s: Connected mouse device '%s'\n", 590 NAME, mdev->svc_name); 592 591 } 593 592 } 594 595 /* XXX Handle device removal */ 596 } 593 } 594 595 free(svcs); 596 597 /* XXX Handle device removal */ 597 598 598 599 return EOK; 599 600 } 600 601 601 /** Start a fibril for discovering new devices. */ 602 static void input_start_dev_discovery(void) 603 { 604 fid_t fid = fibril_create(dev_discovery_fibril, NULL); 605 if (!fid) { 606 printf("%s: Failed to create device discovery fibril.\n", 607 NAME); 608 return; 609 } 610 611 fibril_add_ready(fid); 602 static int dev_check_new(void) 603 { 604 int rc; 605 606 rc = dev_check_new_kbdevs(); 607 if (rc != EOK) 608 return rc; 609 610 rc = dev_check_new_mousedevs(); 611 if (rc != EOK) 612 return rc; 613 614 return EOK; 615 } 616 617 static void cat_change_cb(void) 618 { 619 dev_check_new(); 620 } 621 622 /** Start listening for new devices. */ 623 static int input_start_dev_discovery(void) 624 { 625 int rc; 626 627 rc = loc_register_cat_change_cb(cat_change_cb); 628 if (rc != EOK) { 629 printf("%s: Failed registering callback for device discovery. " 630 "(%d)\n", NAME, rc); 631 return rc; 632 } 633 634 return dev_check_new(); 612 635 } 613 636
Note:
See TracChangeset
for help on using the changeset viewer.