Changeset cc574511 in mainline
- Timestamp:
- 2011-08-16T12:37:58Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 16dc887
- Parents:
- 86ffa27f
- Files:
-
- 3 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/sysipc.c
r86ffa27f rcc574511 427 427 case IPC_M_DATA_READ: { 428 428 size_t size = IPC_GET_ARG2(call->data); 429 if (size <= 0)430 return ELIMIT;431 429 if (size > DATA_XFER_LIMIT) { 432 430 int flags = IPC_GET_ARG3(call->data); -
uspace/lib/c/generic/loc.c
r86ffa27f rcc574511 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 20 09Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 331 331 } 332 332 333 /** Get category ID. 334 * 335 * Provided name of a category, return its ID. 336 * 337 * @param name Category name 338 * @param cat_id Place to store ID 339 * @param flags IPC_FLAG_BLOCKING to wait for location service to start 340 * @return EOK on success or negative error code 341 */ 342 int loc_category_get_id(const char *name, category_id_t *cat_id, 343 unsigned int flags) 344 { 345 async_exch_t *exch; 346 347 if (flags & IPC_FLAG_BLOCKING) 348 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 349 else { 350 exch = loc_exchange_begin(LOC_PORT_CONSUMER); 351 if (exch == NULL) 352 return errno; 353 } 354 355 ipc_call_t answer; 356 aid_t req = async_send_0(exch, LOC_CATEGORY_GET_ID, 357 &answer); 358 sysarg_t retval = async_data_write_start(exch, name, str_size(name)); 359 360 loc_exchange_end(exch); 361 362 if (retval != EOK) { 363 async_wait_for(req, NULL); 364 return retval; 365 } 366 367 async_wait_for(req, &retval); 368 369 if (retval != EOK) { 370 if (cat_id != NULL) 371 *cat_id = (category_id_t) -1; 372 373 return retval; 374 } 375 376 if (cat_id != NULL) 377 *cat_id = (category_id_t) IPC_GET_ARG1(answer); 378 379 return retval; 380 } 381 382 333 383 loc_object_type_t loc_id_probe(service_id_t handle) 334 384 { … … 393 443 } 394 444 445 /** Add service to category. 446 * 447 * @param svc_id Service ID 448 * @param cat_id Category ID 449 * @return EOK on success or negative error code 450 */ 451 int loc_service_add_to_cat(service_id_t svc_id, service_id_t cat_id) 452 { 453 async_exch_t *exch; 454 sysarg_t retval; 455 456 exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); 457 retval = async_req_2_0(exch, LOC_SERVICE_ADD_TO_CAT, svc_id, cat_id); 458 loc_exchange_end(exch); 459 460 return retval; 461 } 462 395 463 static size_t loc_count_services_internal(async_exch_t *exch, 396 464 service_id_t ns_handle) … … 425 493 size_t loc_get_namespaces(loc_sdesc_t **data) 426 494 { 427 /* Loop until namespaces readsuccesful */495 /* Loop until read is succesful */ 428 496 while (true) { 429 497 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); … … 474 542 size_t loc_get_services(service_id_t ns_handle, loc_sdesc_t **data) 475 543 { 476 /* Loop until devices readsuccesful */544 /* Loop until read is succesful */ 477 545 while (true) { 478 546 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); … … 520 588 } 521 589 } 590 591 static int loc_category_get_svcs_internal(category_id_t cat_id, 592 service_id_t *id_buf, size_t buf_size, size_t *act_size) 593 { 594 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 595 596 ipc_call_t answer; 597 aid_t req = async_send_1(exch, LOC_CATEGORY_GET_SVCS, cat_id, 598 &answer); 599 int rc = async_data_read_start(exch, id_buf, buf_size); 600 601 loc_exchange_end(exch); 602 603 if (rc != EOK) { 604 async_wait_for(req, NULL); 605 return rc; 606 } 607 608 sysarg_t retval; 609 async_wait_for(req, &retval); 610 611 if (retval != EOK) { 612 return retval; 613 } 614 615 *act_size = IPC_GET_ARG1(answer); 616 return EOK; 617 } 618 619 /** Get list of services in category. 620 * 621 * Returns an allocated array of service IDs. 622 * 623 * @param cat_id Category ID 624 * @param data Place to store pointer to array of IDs 625 * @param count Place to store number of IDs 626 * @return EOK on success or negative error code 627 */ 628 int loc_category_get_svcs(category_id_t cat_id, category_id_t **data, 629 size_t *count) 630 { 631 service_id_t *ids; 632 size_t act_size; 633 size_t alloc_size; 634 int rc; 635 636 *data = NULL; 637 act_size = 0; /* silence warning */ 638 639 rc = loc_category_get_svcs_internal(cat_id, NULL, 0, &act_size); 640 if (rc != EOK) 641 return rc; 642 643 alloc_size = act_size; 644 ids = malloc(alloc_size); 645 if (ids == NULL) 646 return ENOMEM; 647 648 while (true) { 649 rc = loc_category_get_svcs_internal(cat_id, ids, alloc_size, 650 &act_size); 651 if (rc != EOK) 652 return rc; 653 654 if (act_size <= alloc_size) 655 break; 656 657 alloc_size *= 2; 658 free(ids); 659 660 ids = malloc(alloc_size); 661 if (ids == NULL) 662 return ENOMEM; 663 } 664 665 *count = act_size / sizeof(category_id_t); 666 *data = ids; 667 return EOK; 668 } -
uspace/lib/c/include/ipc/loc.h
r86ffa27f rcc574511 40 40 41 41 typedef sysarg_t service_id_t; 42 typedef sysarg_t category_id_t; 42 43 43 44 typedef enum { … … 50 51 LOC_SERVER_REGISTER = IPC_FIRST_USER_METHOD, 51 52 LOC_SERVER_UNREGISTER, 53 LOC_SERVICE_ADD_TO_CAT, 52 54 LOC_SERVICE_REGISTER, 53 55 LOC_SERVICE_UNREGISTER, 54 56 LOC_SERVICE_GET_ID, 55 57 LOC_NAMESPACE_GET_ID, 58 LOC_CATEGORY_GET_ID, 59 LOC_CATEGORY_GET_SVCS, 56 60 LOC_ID_PROBE, 57 61 LOC_NULL_CREATE, -
uspace/lib/c/include/loc.h
r86ffa27f rcc574511 48 48 extern int loc_service_register_with_iface(const char *, service_id_t *, 49 49 sysarg_t); 50 extern int loc_service_add_to_cat(service_id_t, category_id_t); 50 51 51 52 extern int loc_service_get_id(const char *, service_id_t *, … … 53 54 extern int loc_namespace_get_id(const char *, service_id_t *, 54 55 unsigned int); 56 extern int loc_category_get_id(const char *, category_id_t *, 57 unsigned int); 58 extern int loc_category_get_svcs(category_id_t, category_id_t **, size_t *); 55 59 extern loc_object_type_t loc_id_probe(service_id_t); 56 60 -
uspace/srv/devman/main.c
r86ffa27f rcc574511 362 362 { 363 363 devman_handle_t handle = IPC_GET_ARG1(*call); 364 category_id_t cat_id; 365 int rc; 364 366 365 367 /* Get class name. */ 366 368 char *class_name; 367 intrc = async_data_write_accept((void **) &class_name, true,369 rc = async_data_write_accept((void **) &class_name, true, 368 370 0, 0, 0, 0); 369 371 if (rc != EOK) { … … 383 385 /* Register the device's class alias with location service. */ 384 386 loc_register_class_dev(class_info); 387 388 rc = loc_category_get_id(class_name, &cat_id, IPC_FLAG_BLOCKING); 389 if (rc == EOK) { 390 loc_service_add_to_cat(fun->service_id, cat_id); 391 } else { 392 log_msg(LVL_ERROR, "Failed adding function `%s' to category " 393 "`%s'.", fun->pathname, class_name); 394 } 385 395 386 396 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", … … 760 770 printf(NAME ": HelenOS Device Manager\n"); 761 771 762 if (log_init(NAME, LVL_ ERROR) != EOK) {772 if (log_init(NAME, LVL_WARN) != EOK) { 763 773 printf(NAME ": Error initializing logging subsystem.\n"); 764 774 return -1; -
uspace/srv/hid/input/ctl/kbdev.c
r86ffa27f rcc574511 48 48 #include <kbd_ctl.h> 49 49 #include <kbd_port.h> 50 #include <loc.h> 50 51 #include <stdlib.h> 52 #include <sys/typefmt.h> 51 53 #include <vfs/vfs_sess.h> 52 54 … … 70 72 /** Session with kbdev device */ 71 73 async_sess_t *sess; 72 73 /** File descriptor of open kbdev device */74 int fd;75 74 } kbdev_t; 76 75 … … 84 83 85 84 kbdev->kbd_dev = kdev; 86 kbdev->fd = -1;87 85 88 86 return kbdev; … … 93 91 if (kbdev->sess != NULL) 94 92 async_hangup(kbdev->sess); 95 if (kbdev->fd >= 0)96 close(kbdev->fd);97 93 free(kbdev); 98 94 } … … 100 96 static int kbdev_ctl_init(kbd_dev_t *kdev) 101 97 { 102 const char *pathname;103 98 async_sess_t *sess; 104 99 async_exch_t *exch; 105 100 kbdev_t *kbdev; 106 int fd;101 char *svc_name; 107 102 int rc; 108 103 109 pathname = kdev->dev_path; 104 if (asprintf(&svc_name, "devname%" PRIun, kdev->service_id) > 0) 105 svc_name = (char *) "unknown"; 110 106 111 fd = open(pathname, O_RDWR); 112 if (fd < 0) { 113 return -1; 114 } 115 116 sess = fd_session(EXCHANGE_SERIALIZE, fd); 107 sess = loc_service_connect(EXCHANGE_SERIALIZE, kdev->service_id, 0); 117 108 if (sess == NULL) { 118 printf("%s: Failed starting session with '%s '\n", NAME, pathname);119 close(fd);109 printf("%s: Failed starting session with '%s.'\n", NAME, 110 svc_name); 120 111 return -1; 121 112 } … … 124 115 if (kbdev == NULL) { 125 116 printf("%s: Failed allocating device structure for '%s'.\n", 126 NAME, pathname);117 NAME, svc_name); 127 118 return -1; 128 119 } 129 120 130 kbdev->fd = fd;131 121 kbdev->sess = sess; 132 122 133 123 exch = async_exchange_begin(sess); 134 124 if (exch == NULL) { 135 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname); 125 printf("%s: Failed starting exchange with '%s'.\n", NAME, 126 svc_name); 136 127 kbdev_destroy(kbdev); 137 128 return -1; … … 141 132 if (rc != EOK) { 142 133 printf("%s: Failed creating callback connection from '%s'.\n", 143 NAME, pathname);134 NAME, svc_name); 144 135 async_exchange_end(exch); 145 136 kbdev_destroy(kbdev); -
uspace/srv/hid/input/generic/input.c
r86ffa27f rcc574511 38 38 39 39 #include <adt/list.h> 40 #include <bool.h> 40 41 #include <ipc/services.h> 41 42 #include <ipc/input.h> … … 275 276 kdev->port_ops = port; 276 277 kdev->ctl_ops = ctl; 277 kdev-> dev_path = NULL;278 kdev->service_id = 0; 278 279 279 280 /* Initialize port driver. */ … … 303 304 mdev->port_ops = port; 304 305 mdev->proto_ops = proto; 305 mdev-> dev_path = NULL;306 mdev->service_id = 0; 306 307 307 308 /* Initialize port driver. */ … … 324 325 /** Add new kbdev device. 325 326 * 326 * @param dev_path Filesystem path to the device (/loc/class/...)327 * @param service_id Service ID of the keyboard device 327 328 * 328 329 */ 329 static int kbd_add_kbdev( const char *dev_path)330 static int kbd_add_kbdev(service_id_t service_id) 330 331 { 331 332 kbd_dev_t *kdev = kbd_dev_new(); … … 333 334 return -1; 334 335 335 kdev-> dev_path = dev_path;336 kdev->service_id = service_id; 336 337 kdev->port_ops = NULL; 337 338 kdev->ctl_ops = &kbdev_ctl; … … 352 353 /** Add new mousedev device. 353 354 * 354 * @param dev_path Filesystem path to the device (/loc/class/...)355 * @param service_id Service ID of the mouse device 355 356 * 356 357 */ 357 static int mouse_add_mousedev( const char *dev_path)358 static int mouse_add_mousedev(service_id_t service_id) 358 359 { 359 360 mouse_dev_t *mdev = mouse_dev_new(); … … 361 362 return -1; 362 363 363 mdev-> dev_path = dev_path;364 mdev->service_id = service_id; 364 365 mdev->port_ops = NULL; 365 366 mdev->proto_ops = &mousedev_proto; … … 487 488 * 488 489 */ 490 #include <sys/typefmt.h> 489 491 static int dev_discovery_fibril(void *arg) 490 492 { 491 char *dev_path; 492 size_t kbd_id = 1; 493 size_t mouse_id = 1; 493 category_id_t keyboard_cat, mouse_cat; 494 service_id_t *svcs; 495 size_t count, i; 496 bool already_known; 497 const char *dev_name = "todo"; 494 498 int rc; 499 500 rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING); 501 if (rc != EOK) { 502 printf("%s: Failed resolving category 'keyboard'.\n", NAME); 503 return ENOENT; 504 } 505 506 rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING); 507 if (rc != EOK) { 508 printf("%s: Failed resolving category 'mouse'.\n", NAME); 509 return ENOENT; 510 } 495 511 496 512 while (true) { … … 498 514 499 515 /* 500 * Check for new keyboard device 516 * Check for new keyboard devices 501 517 */ 502 rc = asprintf(&dev_path, "/loc/class/keyboard\\%zu", kbd_id); 503 if (rc < 0) 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); 504 522 continue; 505 506 if (kbd_add_kbdev(dev_path) == EOK) { 507 printf("%s: Connected keyboard device '%s'\n",508 NAME, dev_path);523 } 524 525 for (i = 0; i < count; i++) { 526 already_known = false; 509 527 510 /* XXX Handle device removal */ 511 ++kbd_id; 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 } 543 } 512 544 } 513 545 514 free(dev_path);546 /* XXX Handle device removal */ 515 547 516 548 /* 517 * Check for new mouse device 549 * Check for new mouse devices 518 550 */ 519 rc = asprintf(&dev_path, "/loc/class/mouse\\%zu", mouse_id); 520 if (rc < 0) 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); 521 555 continue; 522 523 if (mouse_add_mousedev(dev_path) == EOK) { 524 printf("%s: Connected mouse device '%s'\n",525 NAME, dev_path);556 } 557 558 for (i = 0; i < count; i++) { 559 already_known = false; 526 560 527 /* XXX Handle device removal */ 528 ++mouse_id; 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 } 576 } 529 577 } 530 578 531 free(dev_path);579 /* XXX Handle device removal */ 532 580 } 533 581 -
uspace/srv/hid/input/include/kbd.h
r86ffa27f rcc574511 40 40 41 41 #include <adt/list.h> 42 #include <ipc/loc.h> 42 43 43 44 struct kbd_port_ops; … … 49 50 link_t kbd_devs; 50 51 51 /** Path to the device(only for kbdev devices) */52 const char *dev_path;52 /** Service ID (only for kbdev devices) */ 53 service_id_t service_id; 53 54 54 55 /** Port ops */ -
uspace/srv/hid/input/include/mouse.h
r86ffa27f rcc574511 39 39 40 40 #include <adt/list.h> 41 #include <ipc/loc.h> 41 42 42 43 struct mouse_port_ops; … … 47 48 link_t mouse_devs; 48 49 49 /** Path to the device (only for mouseev devices) */50 const char *dev_path;50 /** Service ID (only for mousedev devices) */ 51 service_id_t service_id; 51 52 52 53 /** Port ops */ -
uspace/srv/hid/input/proto/mousedev.c
r86ffa27f rcc574511 44 44 #include <ipc/mouseev.h> 45 45 #include <input.h> 46 #include <loc.h> 46 47 #include <mouse.h> 47 48 #include <mouse_port.h> 48 49 #include <mouse_proto.h> 50 #include <sys/typefmt.h> 49 51 50 52 /** Mousedev softstate */ … … 55 57 /** Session to mouse device */ 56 58 async_sess_t *sess; 57 58 /** File descriptor of open mousedev device */59 int fd;60 59 } mousedev_t; 61 60 … … 67 66 68 67 mousedev->mouse_dev = mdev; 69 mousedev->fd = -1;70 68 71 69 return mousedev; … … 76 74 if (mousedev->sess != NULL) 77 75 async_hangup(mousedev->sess); 78 79 if (mousedev->fd >= 0)80 close(mousedev->fd);81 76 82 77 free(mousedev); … … 122 117 static int mousedev_proto_init(mouse_dev_t *mdev) 123 118 { 124 c onst char *pathname = mdev->dev_path;119 char *svc_name; 125 120 126 int fd = open(pathname, O_RDWR); 127 if (fd < 0) 128 return -1; 121 if (asprintf(&svc_name, "devname%" PRIun, mdev->service_id) > 0) 122 svc_name = (char *) "unknown"; 129 123 130 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); 124 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, 125 mdev->service_id, 0); 131 126 if (sess == NULL) { 132 printf("%s: Failed starting session with '%s'\n", NAME, pathname); 133 close(fd); 127 printf("%s: Failed starting session with '%s'\n", NAME, svc_name); 134 128 return -1; 135 129 } … … 138 132 if (mousedev == NULL) { 139 133 printf("%s: Failed allocating device structure for '%s'.\n", 140 NAME, pathname);134 NAME, svc_name); 141 135 return -1; 142 136 } 143 137 144 mousedev->fd = fd;145 138 mousedev->sess = sess; 146 139 147 140 async_exch_t *exch = async_exchange_begin(sess); 148 141 if (exch == NULL) { 149 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname); 142 printf("%s: Failed starting exchange with '%s'.\n", NAME, 143 svc_name); 150 144 mousedev_destroy(mousedev); 151 145 return -1; … … 157 151 if (rc != EOK) { 158 152 printf("%s: Failed creating callback connection from '%s'.\n", 159 NAME, pathname);153 NAME, svc_name); 160 154 mousedev_destroy(mousedev); 161 155 return -1; -
uspace/srv/loc/Makefile
r86ffa27f rcc574511 33 33 34 34 SOURCES = \ 35 category.c \ 35 36 loc.c 36 37 -
uspace/srv/loc/loc.c
r86ffa27f rcc574511 49 49 #include <assert.h> 50 50 51 #include "category.h" 52 #include "loc.h" 53 51 54 #define NAME "loc" 52 55 #define NULL_SERVICES 256 53 54 /** Representation of server (supplier).55 *56 * Each server supplies a set of services.57 *58 */59 typedef struct {60 /** Link to servers_list */61 link_t servers;62 63 /** List of services supplied by this server */64 list_t services;65 66 /** Session asociated with this server */67 async_sess_t *sess;68 69 /** Server name */70 char *name;71 72 /** Fibril mutex for list of services owned by this server */73 fibril_mutex_t services_mutex;74 } loc_server_t;75 76 /** Info about registered namespaces77 *78 */79 typedef struct {80 /** Link to namespaces_list */81 link_t namespaces;82 83 /** Unique namespace identifier */84 service_id_t id;85 86 /** Namespace name */87 char *name;88 89 /** Reference count */90 size_t refcnt;91 } loc_namespace_t;92 93 /** Info about registered service94 *95 */96 typedef struct {97 /** Link to global list of services (services_list) */98 link_t services;99 /** Link to server list of services (loc_server_t.services) */100 link_t server_services;101 /** Unique service identifier */102 service_id_t id;103 /** Service namespace */104 loc_namespace_t *namespace;105 /** Service name */106 char *name;107 /** Supplier of this service */108 loc_server_t *server;109 /** Use this interface when forwarding to server. */110 sysarg_t forward_interface;111 } loc_service_t;112 56 113 57 LIST_INITIALIZE(services_list); … … 137 81 static LIST_INITIALIZE(dummy_null_services); 138 82 139 static service_id_t loc_create_id(void) 83 /** Service directory ogranized by categories (yellow pages) */ 84 static categ_dir_t cdir; 85 86 service_id_t loc_create_id(void) 140 87 { 141 88 /* TODO: allow reusing old ids after their unregistration … … 734 681 } 735 682 683 /** Find ID for category specified by name. 684 * 685 * On success, answer will contain EOK int retval and service ID in arg1. 686 * On failure, error code will be sent in retval. 687 * 688 */ 689 static void loc_category_get_id(ipc_callid_t iid, ipc_call_t *icall) 690 { 691 char *name; 692 category_t *cat; 693 694 /* Get service name */ 695 int rc = async_data_write_accept((void **) &name, true, 0, 696 LOC_NAME_MAXLEN, 0, NULL); 697 if (rc != EOK) { 698 async_answer_0(iid, rc); 699 return; 700 } 701 702 fibril_mutex_lock(&cdir.mutex); 703 704 cat = category_find_by_name(&cdir, name); 705 if (cat == NULL) { 706 /* Category not found */ 707 async_answer_0(iid, ENOENT); 708 goto cleanup; 709 } 710 711 async_answer_1(iid, EOK, cat->id); 712 cleanup: 713 fibril_mutex_unlock(&cdir.mutex); 714 free(name); 715 } 716 736 717 static void loc_id_probe(ipc_callid_t iid, ipc_call_t *icall) 737 718 { … … 892 873 } 893 874 875 static void loc_category_get_svcs(ipc_callid_t iid, ipc_call_t *icall) 876 { 877 ipc_callid_t callid; 878 size_t size; 879 size_t act_size; 880 int rc; 881 882 if (!async_data_read_receive(&callid, &size)) { 883 async_answer_0(callid, EREFUSED); 884 async_answer_0(iid, EREFUSED); 885 return; 886 } 887 888 fibril_mutex_lock(&cdir.mutex); 889 890 category_t *cat = category_get(&cdir, IPC_GET_ARG1(*icall)); 891 if (cat == NULL) { 892 fibril_mutex_unlock(&cdir.mutex); 893 async_answer_0(callid, ENOENT); 894 async_answer_0(iid, ENOENT); 895 return; 896 } 897 898 category_id_t *id_buf = (category_id_t *) malloc(size); 899 if (id_buf == NULL) { 900 fibril_mutex_unlock(&cdir.mutex); 901 async_answer_0(callid, ENOMEM); 902 async_answer_0(iid, ENOMEM); 903 return; 904 } 905 906 fibril_mutex_lock(&cat->mutex); 907 908 rc = category_get_services(cat, id_buf, size, &act_size); 909 if (rc != EOK) { 910 fibril_mutex_unlock(&cat->mutex); 911 fibril_mutex_unlock(&cdir.mutex); 912 async_answer_0(callid, rc); 913 async_answer_0(iid, rc); 914 return; 915 } 916 917 fibril_mutex_unlock(&cat->mutex); 918 fibril_mutex_unlock(&cdir.mutex); 919 920 sysarg_t retval = async_data_read_finalize(callid, id_buf, size); 921 free(id_buf); 922 923 async_answer_1(iid, retval, act_size); 924 } 925 926 894 927 static void loc_null_create(ipc_callid_t iid, ipc_call_t *icall) 895 928 { … … 991 1024 } 992 1025 1026 static void loc_service_add_to_cat(ipc_callid_t iid, ipc_call_t *icall) 1027 { 1028 category_t *cat; 1029 loc_service_t *svc; 1030 catid_t cat_id; 1031 service_id_t svc_id; 1032 sysarg_t retval; 1033 1034 svc_id = IPC_GET_ARG1(*icall); 1035 cat_id = IPC_GET_ARG2(*icall); 1036 1037 fibril_mutex_lock(&services_list_mutex); 1038 fibril_mutex_lock(&cdir.mutex); 1039 1040 cat = category_get(&cdir, cat_id); 1041 svc = loc_service_find_id(svc_id); 1042 1043 fibril_mutex_lock(&cat->mutex); 1044 retval = category_add_service(cat, svc); 1045 1046 fibril_mutex_unlock(&cat->mutex); 1047 fibril_mutex_unlock(&cdir.mutex); 1048 fibril_mutex_unlock(&services_list_mutex); 1049 1050 async_answer_0(iid, retval); 1051 } 1052 1053 993 1054 /** Initialize location service. 994 1055 * … … 997 1058 static bool loc_init(void) 998 1059 { 999 fibril_mutex_lock(&null_services_mutex);1000 1001 1060 unsigned int i; 1061 category_t *cat; 1062 1002 1063 for (i = 0; i < NULL_SERVICES; i++) 1003 1064 null_services[i] = NULL; 1004 1065 1005 fibril_mutex_unlock(&null_services_mutex); 1006 1066 categ_dir_init(&cdir); 1067 1068 cat = category_new("bd"); 1069 categ_dir_add_cat(&cdir, cat); 1070 1071 cat = category_new("keyboard"); 1072 categ_dir_add_cat(&cdir, cat); 1073 1074 cat = category_new("mouse"); 1075 categ_dir_add_cat(&cdir, cat); 1076 1077 cat = category_new("serial"); 1078 categ_dir_add_cat(&cdir, cat); 1079 1007 1080 return true; 1008 1081 } … … 1034 1107 async_answer_0(callid, EOK); 1035 1108 break; 1109 case LOC_SERVICE_ADD_TO_CAT: 1110 /* Add service to category */ 1111 loc_service_add_to_cat(callid, &call); 1112 break; 1036 1113 case LOC_SERVICE_REGISTER: 1037 1114 /* Register one service */ … … 1083 1160 case LOC_NAMESPACE_GET_ID: 1084 1161 loc_namespace_get_id(callid, &call); 1162 break; 1163 case LOC_CATEGORY_GET_ID: 1164 loc_category_get_id(callid, &call); 1165 break; 1166 case LOC_CATEGORY_GET_SVCS: 1167 loc_category_get_svcs(callid, &call); 1085 1168 break; 1086 1169 case LOC_ID_PROBE:
Note:
See TracChangeset
for help on using the changeset viewer.