Ignore:
File:
1 edited

Legend:

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

    r763e0cd r45058baa  
    4545static FIBRIL_MUTEX_INITIALIZE(loc_consumer_mutex);
    4646
    47 static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    48 static bool loc_callback_created = false;
    49 
    5047static async_sess_t *loc_supp_block_sess = NULL;
    5148static async_sess_t *loc_cons_block_sess = NULL;
     
    5451static async_sess_t *loc_consumer_sess = NULL;
    5552
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    58 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    59 {
    60         loc_cat_change_cb_t cb_fun;
    61        
    62         while (true) {
    63                 ipc_call_t call;
    64                 ipc_callid_t callid = async_get_call(&call);
    65                
    66                 if (!IPC_GET_IMETHOD(call)) {
    67                         /* TODO: Handle hangup */
    68                         return;
    69                 }
    70                
    71                 int retval;
    72                
    73                 switch (IPC_GET_IMETHOD(call)) {
    74                 case LOC_EVENT_CAT_CHANGE:
    75                         fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
    78                                 (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
    82                         break;
    83                 default:
    84                         retval = ENOTSUP;
    85                 }
    86                
    87                 async_answer_0(callid, retval);
    88         }
    89 }
    90 
    91 
    9253static void clone_session(fibril_mutex_t *mtx, async_sess_t *src,
    9354    async_sess_t **dst)
     
    9960       
    10061        fibril_mutex_unlock(mtx);
    101 }
    102 
    103 static int loc_callback_create(void)
    104 {
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111         if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113                
    114                 ipc_call_t answer;
    115                 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117                 loc_exchange_end(exch);
    118                
    119                 async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
    127                
    128                 loc_callback_created = true;
    129         }
    130        
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
    13562}
    13663
     
    364291}
    365292
    366 /** Get object name.
    367  *
    368  * Provided ID of an object, return its name.
    369  *
    370  * @param method        IPC method
    371  * @param id            Object ID
     293/** Get service name.
     294 *
     295 * Provided ID of a service, return its name.
     296 *
     297 * @param svc_id        Service ID
    372298 * @param name          Place to store pointer to new string. Caller should
    373299 *                      free it using free().
    374300 * @return              EOK on success or negative error code
    375301 */
    376 static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name)
     302int loc_service_get_name(service_id_t svc_id, char **name)
    377303{
    378304        async_exch_t *exch;
     
    386312       
    387313        ipc_call_t answer;
    388         aid_t req = async_send_1(exch, method, id, &answer);
     314        aid_t req = async_send_1(exch, LOC_SERVICE_GET_NAME, svc_id, &answer);
    389315        aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN,
    390316            &dreply);
     
    415341}
    416342
    417 /** Get category name.
    418  *
    419  * Provided ID of a service, return its name.
    420  *
    421  * @param cat_id        Category ID
    422  * @param name          Place to store pointer to new string. Caller should
    423  *                      free it using free().
    424  * @return              EOK on success or negative error code
    425  */
    426 int loc_category_get_name(category_id_t cat_id, char **name)
    427 {
    428         return loc_get_name_internal(LOC_CATEGORY_GET_NAME, cat_id, name);
    429 }
    430 
    431 /** Get service name.
    432  *
    433  * Provided ID of a service, return its name.
    434  *
    435  * @param svc_id        Service ID
    436  * @param name          Place to store pointer to new string. Caller should
    437  *                      free it using free().
    438  * @return              EOK on success or negative error code
    439  */
    440 int loc_service_get_name(service_id_t svc_id, char **name)
    441 {
    442         return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name);
    443 }
    444343
    445344int loc_namespace_get_id(const char *name, service_id_t *handle,
     
    850749            data, count);
    851750}
    852 
    853 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    854 {
    855         if (loc_callback_create() != EOK)
    856                 return EIO;
    857 
    858         cat_change_cb = cb_fun;
    859         return EOK;
    860 }
Note: See TracChangeset for help on using the changeset viewer.