Changes in uspace/srv/hid/input/generic/input.c [cc574511:99ac5cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
rcc574511 r99ac5cf 64 64 65 65 // FIXME: remove this header 66 #include <kernel/ipc/ipc_methods.h> 67 68 /* In microseconds */ 69 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000) 66 #include <abi/ipc/methods.h> 70 67 71 68 #define NUM_LAYOUTS 3 … … 276 273 kdev->port_ops = port; 277 274 kdev->ctl_ops = ctl; 278 kdev->s ervice_id = 0;275 kdev->svc_id = 0; 279 276 280 277 /* Initialize port driver. */ … … 304 301 mdev->port_ops = port; 305 302 mdev->proto_ops = proto; 306 mdev->s ervice_id = 0;303 mdev->svc_id = 0; 307 304 308 305 /* Initialize port driver. */ … … 328 325 * 329 326 */ 330 static int kbd_add_kbdev(service_id_t service_id )327 static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp) 331 328 { 332 329 kbd_dev_t *kdev = kbd_dev_new(); … … 334 331 return -1; 335 332 336 kdev->s ervice_id = service_id;333 kdev->svc_id = service_id; 337 334 kdev->port_ops = NULL; 338 335 kdev->ctl_ops = &kbdev_ctl; 339 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 340 343 /* Initialize controller driver. */ 341 344 if ((*kdev->ctl_ops->init)(kdev) != 0) { … … 344 347 345 348 list_append(&kdev->kbd_devs, &kbd_devs); 349 *kdevp = kdev; 346 350 return EOK; 347 351 348 352 fail: 353 if (kdev->svc_name != NULL) 354 free(kdev->svc_name); 349 355 free(kdev); 350 356 return -1; … … 356 362 * 357 363 */ 358 static int mouse_add_mousedev(service_id_t service_id )364 static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp) 359 365 { 360 366 mouse_dev_t *mdev = mouse_dev_new(); … … 362 368 return -1; 363 369 364 mdev->s ervice_id = service_id;370 mdev->svc_id = service_id; 365 371 mdev->port_ops = NULL; 366 372 mdev->proto_ops = &mousedev_proto; 367 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 368 380 /* Initialize controller driver. */ 369 381 if ((*mdev->proto_ops->init)(mdev) != 0) { … … 372 384 373 385 list_append(&mdev->mouse_devs, &mouse_devs); 386 *mdevp = mdev; 374 387 return EOK; 375 388 … … 481 494 } 482 495 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; 496 static int dev_check_new_kbdevs(void) 497 { 498 category_id_t keyboard_cat; 494 499 service_id_t *svcs; 495 500 size_t count, i; 496 501 bool already_known; 497 const char *dev_name = "todo";498 502 int rc; 499 503 … … 504 508 } 505 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 506 557 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 507 558 if (rc != EOK) { … … 510 561 } 511 562 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 } 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; 543 583 } 544 584 } 545 585 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 } 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); 576 591 } 577 592 } 578 579 /* XXX Handle device removal */ 580 } 593 } 594 595 free(svcs); 596 597 /* XXX Handle device removal */ 581 598 582 599 return EOK; 583 600 } 584 601 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); 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(); 596 635 } 597 636 … … 615 654 /* Add legacy keyboard devices. */ 616 655 kbd_add_legacy_devs(); 617 656 618 657 /* Add legacy mouse devices. */ 619 658 mouse_add_legacy_devs();
Note:
See TracChangeset
for help on using the changeset viewer.