Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loc.c

    r0fe52ef ra3fcfba  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
     49static loc_cat_change_cb_t cat_change_cb = NULL;
    4950
    5051static async_sess_t *loc_supp_block_sess = NULL;
     
    5455static async_sess_t *loc_consumer_sess = NULL;
    5556
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    5857static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5958{
    60         loc_cat_change_cb_t cb_fun;
    61        
    6259        while (true) {
    6360                ipc_call_t call;
     
    6966                }
    7067               
    71                 int retval;
    72                
    7368                switch (IPC_GET_IMETHOD(call)) {
    7469                case LOC_EVENT_CAT_CHANGE:
    7570                        fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
     71                        loc_cat_change_cb_t cb_fun = cat_change_cb;
     72                        fibril_mutex_unlock(&loc_callback_mutex);
     73                       
     74                        async_answer_0(callid, EOK);
     75                       
     76                        if (cb_fun != NULL)
    7877                                (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
     78                       
    8279                        break;
    8380                default:
    84                         retval = ENOTSUP;
     81                        async_answer_0(callid, ENOTSUP);
    8582                }
    86                
    87                 async_answer_0(callid, retval);
    8883        }
    8984}
     
    10196}
    10297
     98/** Create callback
     99 *
     100 * Must be called with loc_callback_mutex locked.
     101 *
     102 * @return EOK on success.
     103 *
     104 */
    103105static int loc_callback_create(void)
    104106{
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111107        if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     108                async_exch_t *exch =
     109                    loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113110               
    114111                ipc_call_t answer;
    115112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113                int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117114                loc_exchange_end(exch);
    118115               
     116                if (rc != EOK)
     117                        return rc;
     118               
     119                sysarg_t retval;
    119120                async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
     121                if (retval != EOK)
     122                        return retval;
    127123               
    128124                loc_callback_created = true;
    129125        }
    130126       
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
     127        return EOK;
    135128}
    136129
     
    242235
    243236/** Register new driver with loc. */
    244 int loc_server_register(const char *name, async_client_conn_t conn)
     237int loc_server_register(const char *name)
    245238{
    246239        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    253246       
    254247        if (retval != EOK) {
    255                 async_wait_for(req, NULL);
    256                 return retval;
    257         }
    258        
    259         async_set_client_connection(conn);
     248                async_forget(req);
     249                return retval;
     250        }
    260251       
    261252        exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
     
    294285       
    295286        if (retval != EOK) {
    296                 async_wait_for(req, NULL);
     287                async_forget(req);
    297288                return retval;
    298289        }
     
    361352       
    362353        if (retval != EOK) {
    363                 async_wait_for(req, NULL);
     354                async_forget(req);
    364355                return retval;
    365356        }
     
    410401       
    411402        if (dretval != EOK) {
    412                 async_wait_for(req, NULL);
     403                async_forget(req);
    413404                return dretval;
    414405        }
     
    457448{
    458449        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 ID
     457 * @param name          Place to store pointer to new string. Caller should
     458 *                      free it using free().
     459 * @return              EOK on success or negative error code
     460 */
     461int 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);
    459464}
    460465
     
    480485       
    481486        if (retval != EOK) {
    482                 async_wait_for(req, NULL);
     487                async_forget(req);
    483488                return retval;
    484489        }
     
    529534       
    530535        if (retval != EOK) {
    531                 async_wait_for(req, NULL);
     536                async_forget(req);
    532537                return retval;
    533538        }
     
    692697               
    693698                if (rc != EOK) {
    694                         async_wait_for(req, NULL);
     699                        async_forget(req);
    695700                        free(devs);
    696701                        return 0;
     
    741746               
    742747                if (rc != EOK) {
    743                         async_wait_for(req, NULL);
     748                        async_forget(req);
    744749                        free(devs);
    745750                        return 0;
     
    769774       
    770775        if (rc != EOK) {
    771                 async_wait_for(req, NULL);
     776                async_forget(req);
    772777                return rc;
    773778        }
     
    797802    sysarg_t **data, size_t *count)
    798803{
    799         service_id_t *ids;
    800         size_t act_size;
    801         size_t alloc_size;
    802         int rc;
    803 
    804804        *data = NULL;
    805         act_size = 0;   /* silence warning */
    806 
    807         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     805        *count = 0;
     806       
     807        size_t act_size = 0;
     808        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    808809            &act_size);
    809810        if (rc != EOK)
    810811                return rc;
    811 
    812         alloc_size = act_size;
    813         ids = malloc(alloc_size);
     812       
     813        size_t alloc_size = act_size;
     814        service_id_t *ids = malloc(alloc_size);
    814815        if (ids == NULL)
    815816                return ENOMEM;
    816 
     817       
    817818        while (true) {
    818819                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    820821                if (rc != EOK)
    821822                        return rc;
    822 
     823               
    823824                if (act_size <= alloc_size)
    824825                        break;
    825 
    826                 alloc_size *= 2;
    827                 free(ids);
    828 
    829                 ids = malloc(alloc_size);
     826               
     827                alloc_size = act_size;
     828                ids = realloc(ids, alloc_size);
    830829                if (ids == NULL)
    831830                        return ENOMEM;
    832831        }
    833 
     832       
    834833        *count = act_size / sizeof(category_id_t);
    835834        *data = ids;
     
    869868int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    870869{
    871         if (loc_callback_create() != EOK)
     870        fibril_mutex_lock(&loc_callback_mutex);
     871        if (loc_callback_create() != EOK) {
     872                fibril_mutex_unlock(&loc_callback_mutex);
    872873                return EIO;
    873 
     874        }
     875       
    874876        cat_change_cb = cb_fun;
     877        fibril_mutex_unlock(&loc_callback_mutex);
     878       
    875879        return EOK;
    876880}
Note: See TracChangeset for help on using the changeset viewer.