Changes in uspace/lib/c/generic/loc.c [a3fcfba:0fe52ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loc.c
ra3fcfba r0fe52ef 47 47 static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex); 48 48 static bool loc_callback_created = false; 49 static loc_cat_change_cb_t cat_change_cb = NULL;50 49 51 50 static async_sess_t *loc_supp_block_sess = NULL; … … 55 54 static async_sess_t *loc_consumer_sess = NULL; 56 55 56 static loc_cat_change_cb_t cat_change_cb = NULL; 57 57 58 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 58 59 { 60 loc_cat_change_cb_t cb_fun; 61 59 62 while (true) { 60 63 ipc_call_t call; … … 66 69 } 67 70 71 int retval; 72 68 73 switch (IPC_GET_IMETHOD(call)) { 69 74 case LOC_EVENT_CAT_CHANGE: 70 75 fibril_mutex_lock(&loc_callback_mutex); 71 loc_cat_change_cb_t cb_fun = cat_change_cb; 76 cb_fun = cat_change_cb; 77 if (cb_fun != NULL) { 78 (*cb_fun)(); 79 } 72 80 fibril_mutex_unlock(&loc_callback_mutex); 73 74 async_answer_0(callid, EOK); 75 76 if (cb_fun != NULL) 77 (*cb_fun)(); 78 81 retval = 0; 79 82 break; 80 83 default: 81 async_answer_0(callid, ENOTSUP);84 retval = ENOTSUP; 82 85 } 86 87 async_answer_0(callid, retval); 83 88 } 84 89 } … … 96 101 } 97 102 98 /** Create callback99 *100 * Must be called with loc_callback_mutex locked.101 *102 * @return EOK on success.103 *104 */105 103 static int loc_callback_create(void) 106 104 { 105 async_exch_t *exch; 106 sysarg_t retval; 107 int rc = EOK; 108 109 fibril_mutex_lock(&loc_callback_mutex); 110 107 111 if (!loc_callback_created) { 108 async_exch_t *exch = 109 loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 112 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 110 113 111 114 ipc_call_t answer; 112 115 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 113 int rc =async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);116 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 114 117 loc_exchange_end(exch); 115 118 119 async_wait_for(req, &retval); 116 120 if (rc != EOK) 117 return rc;118 119 sysarg_t retval;120 async_wait_for(req, &retval);121 if (retval != EOK)122 return retval;121 goto done; 122 123 if (retval != EOK) { 124 rc = retval; 125 goto done; 126 } 123 127 124 128 loc_callback_created = true; 125 129 } 126 130 127 return EOK; 131 rc = EOK; 132 done: 133 fibril_mutex_unlock(&loc_callback_mutex); 134 return rc; 128 135 } 129 136 … … 235 242 236 243 /** Register new driver with loc. */ 237 int loc_server_register(const char *name )244 int loc_server_register(const char *name, async_client_conn_t conn) 238 245 { 239 246 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); … … 246 253 247 254 if (retval != EOK) { 248 async_forget(req); 249 return retval; 250 } 255 async_wait_for(req, NULL); 256 return retval; 257 } 258 259 async_set_client_connection(conn); 251 260 252 261 exch = loc_exchange_begin(LOC_PORT_SUPPLIER); … … 285 294 286 295 if (retval != EOK) { 287 async_ forget(req);296 async_wait_for(req, NULL); 288 297 return retval; 289 298 } … … 352 361 353 362 if (retval != EOK) { 354 async_ forget(req);363 async_wait_for(req, NULL); 355 364 return retval; 356 365 } … … 401 410 402 411 if (dretval != EOK) { 403 async_ forget(req);412 async_wait_for(req, NULL); 404 413 return dretval; 405 414 } … … 448 457 { 449 458 return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name); 450 }451 452 /** Get service server name.453 *454 * Provided ID of a service, return the name of its server.455 *456 * @param svc_id Service ID457 * @param name Place to store pointer to new string. Caller should458 * free it using free().459 * @return EOK on success or negative error code460 */461 int loc_service_get_server_name(service_id_t svc_id, char **name)462 {463 return loc_get_name_internal(LOC_SERVICE_GET_SERVER_NAME, svc_id, name);464 459 } 465 460 … … 485 480 486 481 if (retval != EOK) { 487 async_ forget(req);482 async_wait_for(req, NULL); 488 483 return retval; 489 484 } … … 534 529 535 530 if (retval != EOK) { 536 async_ forget(req);531 async_wait_for(req, NULL); 537 532 return retval; 538 533 } … … 697 692 698 693 if (rc != EOK) { 699 async_ forget(req);694 async_wait_for(req, NULL); 700 695 free(devs); 701 696 return 0; … … 746 741 747 742 if (rc != EOK) { 748 async_ forget(req);743 async_wait_for(req, NULL); 749 744 free(devs); 750 745 return 0; … … 774 769 775 770 if (rc != EOK) { 776 async_ forget(req);771 async_wait_for(req, NULL); 777 772 return rc; 778 773 } … … 802 797 sysarg_t **data, size_t *count) 803 798 { 799 service_id_t *ids; 800 size_t act_size; 801 size_t alloc_size; 802 int rc; 803 804 804 *data = NULL; 805 *count = 0; 806 807 size_t act_size = 0; 808 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 805 act_size = 0; /* silence warning */ 806 807 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 809 808 &act_size); 810 809 if (rc != EOK) 811 810 return rc; 812 813 size_talloc_size = act_size;814 service_id_t *ids = malloc(alloc_size);811 812 alloc_size = act_size; 813 ids = malloc(alloc_size); 815 814 if (ids == NULL) 816 815 return ENOMEM; 817 816 818 817 while (true) { 819 818 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 821 820 if (rc != EOK) 822 821 return rc; 823 822 824 823 if (act_size <= alloc_size) 825 824 break; 826 827 alloc_size = act_size; 828 ids = realloc(ids, alloc_size); 825 826 alloc_size *= 2; 827 free(ids); 828 829 ids = malloc(alloc_size); 829 830 if (ids == NULL) 830 831 return ENOMEM; 831 832 } 832 833 833 834 *count = act_size / sizeof(category_id_t); 834 835 *data = ids; … … 868 869 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 869 870 { 870 fibril_mutex_lock(&loc_callback_mutex); 871 if (loc_callback_create() != EOK) { 872 fibril_mutex_unlock(&loc_callback_mutex); 871 if (loc_callback_create() != EOK) 873 872 return EIO; 874 } 875 873 876 874 cat_change_cb = cb_fun; 877 fibril_mutex_unlock(&loc_callback_mutex);878 879 875 return EOK; 880 876 }
Note:
See TracChangeset
for help on using the changeset viewer.