Ignore:
File:
1 edited

Legend:

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

    ra3fcfba r0fe52ef  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
    49 static loc_cat_change_cb_t cat_change_cb = NULL;
    5049
    5150static async_sess_t *loc_supp_block_sess = NULL;
     
    5554static async_sess_t *loc_consumer_sess = NULL;
    5655
     56static loc_cat_change_cb_t cat_change_cb = NULL;
     57
    5758static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5859{
     60        loc_cat_change_cb_t cb_fun;
     61       
    5962        while (true) {
    6063                ipc_call_t call;
     
    6669                }
    6770               
     71                int retval;
     72               
    6873                switch (IPC_GET_IMETHOD(call)) {
    6974                case LOC_EVENT_CAT_CHANGE:
    7075                        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                        }
    7280                        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;
    7982                        break;
    8083                default:
    81                         async_answer_0(callid, ENOTSUP);
     84                        retval = ENOTSUP;
    8285                }
     86               
     87                async_answer_0(callid, retval);
    8388        }
    8489}
     
    96101}
    97102
    98 /** Create callback
    99  *
    100  * Must be called with loc_callback_mutex locked.
    101  *
    102  * @return EOK on success.
    103  *
    104  */
    105103static int loc_callback_create(void)
    106104{
     105        async_exch_t *exch;
     106        sysarg_t retval;
     107        int rc = EOK;
     108
     109        fibril_mutex_lock(&loc_callback_mutex);
     110       
    107111        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);
    110113               
    111114                ipc_call_t answer;
    112115                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);
    114117                loc_exchange_end(exch);
    115118               
     119                async_wait_for(req, &retval);
    116120                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                }
    123127               
    124128                loc_callback_created = true;
    125129        }
    126130       
    127         return EOK;
     131        rc = EOK;
     132done:
     133        fibril_mutex_unlock(&loc_callback_mutex);
     134        return rc;
    128135}
    129136
     
    235242
    236243/** Register new driver with loc. */
    237 int loc_server_register(const char *name)
     244int loc_server_register(const char *name, async_client_conn_t conn)
    238245{
    239246        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    246253       
    247254        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);
    251260       
    252261        exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
     
    285294       
    286295        if (retval != EOK) {
    287                 async_forget(req);
     296                async_wait_for(req, NULL);
    288297                return retval;
    289298        }
     
    352361       
    353362        if (retval != EOK) {
    354                 async_forget(req);
     363                async_wait_for(req, NULL);
    355364                return retval;
    356365        }
     
    401410       
    402411        if (dretval != EOK) {
    403                 async_forget(req);
     412                async_wait_for(req, NULL);
    404413                return dretval;
    405414        }
     
    448457{
    449458        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  */
    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);
    464459}
    465460
     
    485480       
    486481        if (retval != EOK) {
    487                 async_forget(req);
     482                async_wait_for(req, NULL);
    488483                return retval;
    489484        }
     
    534529       
    535530        if (retval != EOK) {
    536                 async_forget(req);
     531                async_wait_for(req, NULL);
    537532                return retval;
    538533        }
     
    697692               
    698693                if (rc != EOK) {
    699                         async_forget(req);
     694                        async_wait_for(req, NULL);
    700695                        free(devs);
    701696                        return 0;
     
    746741               
    747742                if (rc != EOK) {
    748                         async_forget(req);
     743                        async_wait_for(req, NULL);
    749744                        free(devs);
    750745                        return 0;
     
    774769       
    775770        if (rc != EOK) {
    776                 async_forget(req);
     771                async_wait_for(req, NULL);
    777772                return rc;
    778773        }
     
    802797    sysarg_t **data, size_t *count)
    803798{
     799        service_id_t *ids;
     800        size_t act_size;
     801        size_t alloc_size;
     802        int rc;
     803
    804804        *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,
    809808            &act_size);
    810809        if (rc != EOK)
    811810                return rc;
    812        
    813         size_t alloc_size = act_size;
    814         service_id_t *ids = malloc(alloc_size);
     811
     812        alloc_size = act_size;
     813        ids = malloc(alloc_size);
    815814        if (ids == NULL)
    816815                return ENOMEM;
    817        
     816
    818817        while (true) {
    819818                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    821820                if (rc != EOK)
    822821                        return rc;
    823                
     822
    824823                if (act_size <= alloc_size)
    825824                        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);
    829830                if (ids == NULL)
    830831                        return ENOMEM;
    831832        }
    832        
     833
    833834        *count = act_size / sizeof(category_id_t);
    834835        *data = ids;
     
    868869int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    869870{
    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)
    873872                return EIO;
    874         }
    875        
     873
    876874        cat_change_cb = cb_fun;
    877         fibril_mutex_unlock(&loc_callback_mutex);
    878        
    879875        return EOK;
    880876}
Note: See TracChangeset for help on using the changeset viewer.