Changes in uspace/srv/hid/input/generic/input.c [99ac5cf:336d2f52] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/input.c
r99ac5cf r336d2f52 38 38 39 39 #include <adt/list.h> 40 #include <bool.h>41 40 #include <ipc/services.h> 42 41 #include <ipc/input.h> … … 54 53 #include <io/console.h> 55 54 #include <io/keycode.h> 56 #include < loc.h>55 #include <devmap.h> 57 56 #include <input.h> 58 57 #include <kbd.h> … … 64 63 65 64 // FIXME: remove this header 66 #include <abi/ipc/methods.h> 65 #include <kernel/ipc/ipc_methods.h> 66 67 /* In microseconds */ 68 #define DISCOVERY_POLL_INTERVAL (10 * 1000 * 1000) 67 69 68 70 #define NUM_LAYOUTS 3 … … 273 275 kdev->port_ops = port; 274 276 kdev->ctl_ops = ctl; 275 kdev-> svc_id = 0;277 kdev->dev_path = NULL; 276 278 277 279 /* Initialize port driver. */ … … 301 303 mdev->port_ops = port; 302 304 mdev->proto_ops = proto; 303 mdev-> svc_id = 0;305 mdev->dev_path = NULL; 304 306 305 307 /* Initialize port driver. */ … … 322 324 /** Add new kbdev device. 323 325 * 324 * @param service_id Service ID of the keyboard device326 * @param dev_path Filesystem path to the device (/dev/class/...) 325 327 * 326 328 */ 327 static int kbd_add_kbdev( service_id_t service_id, kbd_dev_t **kdevp)329 static int kbd_add_kbdev(const char *dev_path) 328 330 { 329 331 kbd_dev_t *kdev = kbd_dev_new(); … … 331 333 return -1; 332 334 333 kdev-> svc_id = service_id;335 kdev->dev_path = dev_path; 334 336 kdev->port_ops = NULL; 335 337 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 338 343 339 /* Initialize controller driver. */ … … 347 343 348 344 list_append(&kdev->kbd_devs, &kbd_devs); 349 *kdevp = kdev;350 345 return EOK; 351 346 352 347 fail: 353 if (kdev->svc_name != NULL)354 free(kdev->svc_name);355 348 free(kdev); 356 349 return -1; … … 359 352 /** Add new mousedev device. 360 353 * 361 * @param service_id Service ID of the mouse device354 * @param dev_path Filesystem path to the device (/dev/class/...) 362 355 * 363 356 */ 364 static int mouse_add_mousedev( service_id_t service_id, mouse_dev_t **mdevp)357 static int mouse_add_mousedev(const char *dev_path) 365 358 { 366 359 mouse_dev_t *mdev = mouse_dev_new(); … … 368 361 return -1; 369 362 370 mdev-> svc_id = service_id;363 mdev->dev_path = dev_path; 371 364 mdev->port_ops = NULL; 372 365 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 366 380 367 /* Initialize controller driver. */ … … 384 371 385 372 list_append(&mdev->mouse_devs, &mouse_devs); 386 *mdevp = mdev;387 373 return EOK; 388 374 … … 424 410 #endif 425 411 #if defined(MACHINE_msim) 426 kbd_add_dev(&msim_port, & stty_ctl);412 kbd_add_dev(&msim_port, &pc_ctl); 427 413 #endif 428 414 #if (defined(MACHINE_lgxemul) || defined(MACHINE_bgxemul)) && defined(CONFIG_FB) … … 494 480 } 495 481 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; 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; 502 494 int rc; 503 495 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", 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; 512 } 513 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; 529 } 530 531 free(dev_path); 532 } 533 534 return EOK; 535 } 536 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", 516 543 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 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", 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; 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(); 544 return; 545 } 546 547 fibril_add_ready(fid); 635 548 } 636 549 … … 659 572 660 573 /* Register driver */ 661 int rc = loc_server_register(NAME, client_connection);574 int rc = devmap_driver_register(NAME, client_connection); 662 575 if (rc < 0) { 663 printf("%s: Unable to register server (%d)\n", NAME, rc);576 printf("%s: Unable to register driver (%d)\n", NAME, rc); 664 577 return -1; 665 578 } 666 579 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);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); 673 586 return -1; 674 587 }
Note:
See TracChangeset
for help on using the changeset viewer.