Changeset 6843a9c in mainline for uspace/srv/locsrv/locsrv.c
- Timestamp:
- 2012-06-29T13:02:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 722912e
- Parents:
- ba72f2b (diff), 0bbd13e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/locsrv/locsrv.c
rba72f2b r6843a9c 51 51 52 52 #include "category.h" 53 #include "loc .h"53 #include "locsrv.h" 54 54 55 55 #define NAME "loc" 56 56 #define NULL_SERVICES 256 57 58 /** Callback session */ 59 typedef struct { 60 link_t cb_sess_list; 61 async_sess_t *sess; 62 } cb_sess_t; 57 63 58 64 LIST_INITIALIZE(services_list); … … 86 92 87 93 static FIBRIL_MUTEX_INITIALIZE(callback_sess_mutex); 88 static async_sess_t *callback_sess = NULL;94 static LIST_INITIALIZE(callback_sess_list); 89 95 90 96 service_id_t loc_create_id(void) … … 384 390 */ 385 391 list_initialize(&server->services); 386 387 392 link_initialize(&server->servers); 388 393 … … 608 613 size_t act_size; 609 614 loc_service_t *svc; 615 char *fqn; 610 616 611 617 if (!async_data_read_receive(&callid, &size)) { … … 625 631 } 626 632 627 act_size = str_size(svc->name); 633 if (asprintf(&fqn, "%s/%s", svc->namespace->name, svc->name) < 0) { 634 fibril_mutex_unlock(&services_list_mutex); 635 async_answer_0(callid, ENOMEM); 636 async_answer_0(iid, ENOMEM); 637 return; 638 } 639 640 act_size = str_size(fqn); 628 641 if (act_size > size) { 642 free(fqn); 629 643 fibril_mutex_unlock(&services_list_mutex); 630 644 async_answer_0(callid, EOVERFLOW); … … 633 647 } 634 648 635 sysarg_t retval = async_data_read_finalize(callid, svc->name, 649 sysarg_t retval = async_data_read_finalize(callid, fqn, 650 min(size, act_size)); 651 free(fqn); 652 653 fibril_mutex_unlock(&services_list_mutex); 654 655 async_answer_0(iid, retval); 656 } 657 658 static void loc_service_get_server_name(ipc_callid_t iid, ipc_call_t *icall) 659 { 660 ipc_callid_t callid; 661 size_t size; 662 size_t act_size; 663 loc_service_t *svc; 664 665 if (!async_data_read_receive(&callid, &size)) { 666 async_answer_0(callid, EREFUSED); 667 async_answer_0(iid, EREFUSED); 668 return; 669 } 670 671 fibril_mutex_lock(&services_list_mutex); 672 673 svc = loc_service_find_id(IPC_GET_ARG1(*icall)); 674 if (svc == NULL) { 675 fibril_mutex_unlock(&services_list_mutex); 676 async_answer_0(callid, ENOENT); 677 async_answer_0(iid, ENOENT); 678 return; 679 } 680 681 if (svc->server == NULL) { 682 fibril_mutex_unlock(&services_list_mutex); 683 async_answer_0(callid, EINVAL); 684 async_answer_0(iid, EINVAL); 685 return; 686 } 687 688 act_size = str_size(svc->server->name); 689 if (act_size > size) { 690 fibril_mutex_unlock(&services_list_mutex); 691 async_answer_0(callid, EOVERFLOW); 692 async_answer_0(iid, EOVERFLOW); 693 return; 694 } 695 696 sysarg_t retval = async_data_read_finalize(callid, svc->server->name, 636 697 min(size, act_size)); 637 698 … … 790 851 } 791 852 792 /** Find ID for category specified by name. 793 * 794 * On success, answer will contain EOK int retval and service ID in arg1. 853 /** Create callback connection. 854 * 855 * Create callback connection which will be used to send category change 856 * events. 857 * 858 * On success, answer will contain EOK int retval. 795 859 * On failure, error code will be sent in retval. 796 860 * … … 798 862 static void loc_callback_create(ipc_callid_t iid, ipc_call_t *icall) 799 863 { 800 async_sess_t *cb_sess = async_callback_receive(EXCHANGE_SERIALIZE);864 cb_sess_t *cb_sess = calloc(1, sizeof(cb_sess_t)); 801 865 if (cb_sess == NULL) { 802 866 async_answer_0(iid, ENOMEM); … … 804 868 } 805 869 870 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 871 if (sess == NULL) { 872 free(cb_sess); 873 async_answer_0(iid, ENOMEM); 874 return; 875 } 876 877 cb_sess->sess = sess; 878 link_initialize(&cb_sess->cb_sess_list); 879 806 880 fibril_mutex_lock(&callback_sess_mutex); 807 if (callback_sess != NULL) { 808 fibril_mutex_unlock(&callback_sess_mutex); 809 async_answer_0(iid, EEXIST); 810 return; 811 } 812 813 callback_sess = cb_sess; 881 list_append(&cb_sess->cb_sess_list, &callback_sess_list); 814 882 fibril_mutex_unlock(&callback_sess_mutex); 815 883 … … 820 888 { 821 889 fibril_mutex_lock(&callback_sess_mutex); 822 823 if (callback_sess != NULL) { 824 async_exch_t *exch = async_exchange_begin(callback_sess); 890 891 list_foreach(callback_sess_list, link) { 892 cb_sess_t *cb_sess; 893 894 cb_sess = list_get_instance(link, cb_sess_t, cb_sess_list); 895 896 async_exch_t *exch = async_exchange_begin(cb_sess->sess); 825 897 async_msg_0(exch, LOC_EVENT_CAT_CHANGE); 826 898 async_exchange_end(exch); 827 899 } 828 900 829 901 fibril_mutex_unlock(&callback_sess_mutex); 830 902 } … … 1269 1341 categ_dir_add_cat(&cdir, cat); 1270 1342 1343 cat = category_new("iplink"); 1344 categ_dir_add_cat(&cdir, cat); 1345 1271 1346 cat = category_new("keyboard"); 1272 1347 categ_dir_add_cat(&cdir, cat); … … 1375 1450 case LOC_SERVICE_GET_NAME: 1376 1451 loc_service_get_name(callid, &call); 1452 break; 1453 case LOC_SERVICE_GET_SERVER_NAME: 1454 loc_service_get_server_name(callid, &call); 1377 1455 break; 1378 1456 case LOC_NAMESPACE_GET_ID: … … 1460 1538 1461 1539 /* Register location service at naming service */ 1462 if (service_register(SERVICE_LOC) != EOK) 1463 return -1; 1540 int rc = service_register(SERVICE_LOC); 1541 if (rc != EOK) 1542 return rc; 1464 1543 1465 1544 printf("%s: Accepting connections\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.