Changeset cc574511 in mainline for uspace/lib/c/generic/loc.c
- Timestamp:
- 2011-08-16T12:37:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 16dc887
- Parents:
- 86ffa27f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.