Changes in uspace/srv/hid/input/generic/input.c [333c233:99ac5cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
r333c233 r99ac5cf 38 38 39 39 #include <adt/list.h> 40 #include <bool.h> 40 41 #include <ipc/services.h> 41 42 #include <ipc/input.h> … … 53 54 #include <io/console.h> 54 55 #include <io/keycode.h> 55 #include < devmap.h>56 #include <loc.h> 56 57 #include <input.h> 57 58 #include <kbd.h> … … 63 64 64 65 // FIXME: remove this header 65 #include <kernel/ipc/ipc_methods.h> 66 67 /* In microseconds */ 68 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000) 66 #include <abi/ipc/methods.h> 69 67 70 68 #define NUM_LAYOUTS 3 … … 275 273 kdev->port_ops = port; 276 274 kdev->ctl_ops = ctl; 277 kdev-> dev_path = NULL;275 kdev->svc_id = 0; 278 276 279 277 /* Initialize port driver. */ … … 303 301 mdev->port_ops = port; 304 302 mdev->proto_ops = proto; 305 mdev-> dev_path = NULL;303 mdev->svc_id = 0; 306 304 307 305 /* Initialize port driver. */ … … 324 322 /** Add new kbdev device. 325 323 * 326 * @param dev_path Filesystem path to the device (/dev/class/...)324 * @param service_id Service ID of the keyboard device 327 325 * 328 326 */ 329 static int kbd_add_kbdev( const char *dev_path)327 static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp) 330 328 { 331 329 kbd_dev_t *kdev = kbd_dev_new(); … … 333 331 return -1; 334 332 335 kdev-> dev_path = dev_path;333 kdev->svc_id = service_id; 336 334 kdev->port_ops = NULL; 337 335 kdev->ctl_ops = &kbdev_ctl; 338 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 /* Initialize controller driver. */ 340 344 if ((*kdev->ctl_ops->init)(kdev) != 0) { … … 343 347 344 348 list_append(&kdev->kbd_devs, &kbd_devs); 349 *kdevp = kdev; 345 350 return EOK; 346 351 347 352 fail: 353 if (kdev->svc_name != NULL) 354 free(kdev->svc_name); 348 355 free(kdev); 349 356 return -1; … … 352 359 /** Add new mousedev device. 353 360 * 354 * @param dev_path Filesystem path to the device (/dev/class/...)361 * @param service_id Service ID of the mouse device 355 362 * 356 363 */ 357 static int mouse_add_mousedev( const char *dev_path)364 static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp) 358 365 { 359 366 mouse_dev_t *mdev = mouse_dev_new(); … … 361 368 return -1; 362 369 363 mdev-> dev_path = dev_path;370 mdev->svc_id = service_id; 364 371 mdev->port_ops = NULL; 365 372 mdev->proto_ops = &mousedev_proto; 366 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 /* Initialize controller driver. */ 368 381 if ((*mdev->proto_ops->init)(mdev) != 0) { … … 371 384 372 385 list_append(&mdev->mouse_devs, &mouse_devs); 386 *mdevp = mdev; 373 387 return EOK; 374 388 … … 480 494 } 481 495 482 /** Periodically check for new input devices. 483 * 484 * Looks under /dev/class/keyboard and /dev/class/mouse. 485 * 486 * @param arg Ignored 487 * 488 */ 489 static int dev_discovery_fibril(void *arg) 490 { 491 char *dev_path; 492 size_t kbd_id = 1; 493 size_t mouse_id = 1; 496 static int dev_check_new_kbdevs(void) 497 { 498 category_id_t keyboard_cat; 499 service_id_t *svcs; 500 size_t count, i; 501 bool already_known; 494 502 int rc; 495 503 496 while (true) { 497 async_usleep(DISCOVERY_POLL_INTERVAL); 498 499 /* 500 * Check for new keyboard device 501 */ 502 rc = asprintf(&dev_path, "/dev/class/keyboard\\%zu", kbd_id); 503 if (rc < 0) 504 continue; 505 506 if (kbd_add_kbdev(dev_path) == EOK) { 507 printf("%s: Connected keyboard device '%s'\n", 508 NAME, dev_path); 509 510 /* XXX Handle device removal */ 511 ++kbd_id; 504 rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING); 505 if (rc != EOK) { 506 printf("%s: Failed resolving category 'keyboard'.\n", NAME); 507 return ENOENT; 508 } 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 } 512 531 } 513 532 514 free(dev_path); 515 516 /* 517 * Check for new mouse device 518 */ 519 rc = asprintf(&dev_path, "/dev/class/mouse\\%zu", mouse_id); 520 if (rc < 0) 521 continue; 522 523 if (mouse_add_mousedev(dev_path) == EOK) { 524 printf("%s: Connected mouse device '%s'\n", 525 NAME, dev_path); 526 527 /* XXX Handle device removal */ 528 ++mouse_id; 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 } 529 539 } 530 531 free(dev_path); 532 } 540 } 541 542 free(svcs); 543 544 /* XXX Handle device removal */ 533 545 534 546 return EOK; 535 547 } 536 548 537 /** Start a fibril for discovering new devices. */ 538 static void input_start_dev_discovery(void) 539 { 540 fid_t fid = fibril_create(dev_discovery_fibril, NULL); 541 if (!fid) { 542 printf("%s: Failed to create device discovery fibril.\n", 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 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 558 if (rc != EOK) { 559 printf("%s: Failed resolving category 'mouse'.\n", NAME); 560 return ENOENT; 561 } 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", 543 569 NAME); 544 return; 545 } 546 547 fibril_add_ready(fid); 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; 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 } 592 } 593 } 594 595 free(svcs); 596 597 /* XXX Handle device removal */ 598 599 return EOK; 600 } 601 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(); 548 635 } 549 636 … … 572 659 573 660 /* Register driver */ 574 int rc = devmap_driver_register(NAME, client_connection);661 int rc = loc_server_register(NAME, client_connection); 575 662 if (rc < 0) { 576 printf("%s: Unable to register driver (%d)\n", NAME, rc);663 printf("%s: Unable to register server (%d)\n", NAME, rc); 577 664 return -1; 578 665 } 579 666 580 char kbd[ DEVMAP_NAME_MAXLEN + 1];581 snprintf(kbd, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);582 583 devmap_handle_t devmap_handle;584 if ( devmap_device_register(kbd, &devmap_handle) != EOK) {585 printf("%s: Unable to register device %s\n", NAME, kbd);667 char kbd[LOC_NAME_MAXLEN + 1]; 668 snprintf(kbd, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME); 669 670 service_id_t service_id; 671 if (loc_service_register(kbd, &service_id) != EOK) { 672 printf("%s: Unable to register service %s\n", NAME, kbd); 586 673 return -1; 587 674 }
Note:
See TracChangeset
for help on using the changeset viewer.