Changes in uspace/srv/hid/input/generic/input.c [99ac5cf:cc574511] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
r99ac5cf rcc574511 64 64 65 65 // FIXME: remove this header 66 #include <abi/ipc/methods.h> 66 #include <kernel/ipc/ipc_methods.h> 67 68 /* In microseconds */ 69 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000) 67 70 68 71 #define NUM_LAYOUTS 3 … … 273 276 kdev->port_ops = port; 274 277 kdev->ctl_ops = ctl; 275 kdev->s vc_id = 0;278 kdev->service_id = 0; 276 279 277 280 /* Initialize port driver. */ … … 301 304 mdev->port_ops = port; 302 305 mdev->proto_ops = proto; 303 mdev->s vc_id = 0;306 mdev->service_id = 0; 304 307 305 308 /* Initialize port driver. */ … … 325 328 * 326 329 */ 327 static int kbd_add_kbdev(service_id_t service_id , kbd_dev_t **kdevp)330 static int kbd_add_kbdev(service_id_t service_id) 328 331 { 329 332 kbd_dev_t *kdev = kbd_dev_new(); … … 331 334 return -1; 332 335 333 kdev->s vc_id = service_id;336 kdev->service_id = service_id; 334 337 kdev->port_ops = NULL; 335 338 kdev->ctl_ops = &kbdev_ctl; 336 337 int rc = loc_service_get_name(service_id, &kdev->svc_name);338 if (rc != EOK) {339 kdev->svc_name = NULL;340 goto fail;341 }342 339 343 340 /* Initialize controller driver. */ … … 347 344 348 345 list_append(&kdev->kbd_devs, &kbd_devs); 349 *kdevp = kdev;350 346 return EOK; 351 347 352 348 fail: 353 if (kdev->svc_name != NULL)354 free(kdev->svc_name);355 349 free(kdev); 356 350 return -1; … … 362 356 * 363 357 */ 364 static int mouse_add_mousedev(service_id_t service_id , mouse_dev_t **mdevp)358 static int mouse_add_mousedev(service_id_t service_id) 365 359 { 366 360 mouse_dev_t *mdev = mouse_dev_new(); … … 368 362 return -1; 369 363 370 mdev->s vc_id = service_id;364 mdev->service_id = service_id; 371 365 mdev->port_ops = NULL; 372 366 mdev->proto_ops = &mousedev_proto; 373 374 int rc = loc_service_get_name(service_id, &mdev->svc_name);375 if (rc != EOK) {376 mdev->svc_name = NULL;377 goto fail;378 }379 367 380 368 /* Initialize controller driver. */ … … 384 372 385 373 list_append(&mdev->mouse_devs, &mouse_devs); 386 *mdevp = mdev;387 374 return EOK; 388 375 … … 494 481 } 495 482 496 static int dev_check_new_kbdevs(void) 497 { 498 category_id_t keyboard_cat; 483 /** Periodically check for new input devices. 484 * 485 * Looks under /loc/class/keyboard and /loc/class/mouse. 486 * 487 * @param arg Ignored 488 * 489 */ 490 #include <sys/typefmt.h> 491 static int dev_discovery_fibril(void *arg) 492 { 493 category_id_t keyboard_cat, mouse_cat; 499 494 service_id_t *svcs; 500 495 size_t count, i; 501 496 bool already_known; 497 const char *dev_name = "todo"; 502 498 int rc; 503 499 … … 508 504 } 509 505 510 /*511 * Check for new keyboard devices512 */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 557 506 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 558 507 if (rc != EOK) { … … 561 510 } 562 511 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; 512 while (true) { 513 async_usleep(DISCOVERY_POLL_INTERVAL); 514 515 /* 516 * Check for new keyboard devices 517 */ 518 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count); 519 if (rc != EOK) { 520 printf("%s: Failed getting list of keyboard devices.\n", 521 NAME); 522 continue; 523 } 524 525 for (i = 0; i < count; i++) { 526 already_known = false; 527 528 /* Determine whether we already know this device. */ 529 list_foreach(kbd_devs, kdev_link) { 530 kbd_dev_t *kdev = list_get_instance(kdev_link, 531 kbd_dev_t, kbd_devs); 532 if (kdev->service_id == svcs[i]) { 533 already_known = true; 534 break; 535 } 536 } 537 538 if (!already_known) { 539 if (kbd_add_kbdev(svcs[i]) == EOK) { 540 printf("%s: Connected keyboard device '%s'\n", 541 NAME, dev_name); 542 } 583 543 } 584 544 } 585 545 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); 546 /* XXX Handle device removal */ 547 548 /* 549 * Check for new mouse devices 550 */ 551 rc = loc_category_get_svcs(mouse_cat, &svcs, &count); 552 if (rc != EOK) { 553 printf("%s: Failed getting list of mouse devices.\n", 554 NAME); 555 continue; 556 } 557 558 for (i = 0; i < count; i++) { 559 already_known = false; 560 561 /* Determine whether we already know this device. */ 562 list_foreach(mouse_devs, mdev_link) { 563 mouse_dev_t *mdev = list_get_instance(mdev_link, 564 mouse_dev_t, mouse_devs); 565 if (mdev->service_id == svcs[i]) { 566 already_known = true; 567 break; 568 } 569 } 570 571 if (!already_known) { 572 if (mouse_add_mousedev(svcs[i]) == EOK) { 573 printf("%s: Connected mouse device '%s'\n", 574 NAME, dev_name); 575 } 591 576 } 592 577 } 593 } 594 595 free(svcs); 596 597 /* XXX Handle device removal */ 578 579 /* XXX Handle device removal */ 580 } 598 581 599 582 return EOK; 600 583 } 601 584 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(); 585 /** Start a fibril for discovering new devices. */ 586 static void input_start_dev_discovery(void) 587 { 588 fid_t fid = fibril_create(dev_discovery_fibril, NULL); 589 if (!fid) { 590 printf("%s: Failed to create device discovery fibril.\n", 591 NAME); 592 return; 593 } 594 595 fibril_add_ready(fid); 635 596 } 636 597 … … 654 615 /* Add legacy keyboard devices. */ 655 616 kbd_add_legacy_devs(); 656 617 657 618 /* Add legacy mouse devices. */ 658 619 mouse_add_legacy_devs();
Note:
See TracChangeset
for help on using the changeset viewer.