Changeset f55b12b in mainline for uspace/srv/loc/loc.c


Ignore:
Timestamp:
2011-08-18T18:41:03Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0cc32f2, a92cf94f, cf22ada
Parents:
3190e88 (diff), 763e0cd (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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loc/loc.c

    r3190e88 rf55b12b  
    8484/** Service directory ogranized by categories (yellow pages) */
    8585static categ_dir_t cdir;
     86
     87static FIBRIL_MUTEX_INITIALIZE(callback_sess_mutex);
     88static async_sess_t *callback_sess = NULL;
    8689
    8790service_id_t loc_create_id(void)
     
    533536}
    534537
     538static void loc_category_get_name(ipc_callid_t iid, ipc_call_t *icall)
     539{
     540        ipc_callid_t callid;
     541        size_t size;
     542        size_t act_size;
     543        category_t *cat;
     544       
     545        if (!async_data_read_receive(&callid, &size)) {
     546                async_answer_0(callid, EREFUSED);
     547                async_answer_0(iid, EREFUSED);
     548                return;
     549        }
     550       
     551        fibril_mutex_lock(&cdir.mutex);
     552       
     553        cat = category_get(&cdir, IPC_GET_ARG1(*icall));
     554        if (cat == NULL) {
     555                fibril_mutex_unlock(&cdir.mutex);
     556                async_answer_0(callid, ENOENT);
     557                async_answer_0(iid, ENOENT);
     558                return;
     559        }
     560       
     561        act_size = str_size(cat->name);
     562        if (act_size > size) {
     563                fibril_mutex_unlock(&cdir.mutex);
     564                async_answer_0(callid, EOVERFLOW);
     565                async_answer_0(iid, EOVERFLOW);
     566                return;
     567        }
     568       
     569        sysarg_t retval = async_data_read_finalize(callid, cat->name,
     570            min(size, act_size));
     571       
     572        fibril_mutex_unlock(&cdir.mutex);
     573       
     574        async_answer_0(iid, retval);
     575}
     576
    535577static void loc_service_get_name(ipc_callid_t iid, ipc_call_t *icall)
    536578{
     
    571613        async_answer_0(iid, retval);
    572614}
    573 
    574615
    575616/** Connect client to the service.
     
    728769 *
    729770 */
     771static void loc_callback_create(ipc_callid_t iid, ipc_call_t *icall)
     772{
     773        async_sess_t *cb_sess = async_callback_receive(EXCHANGE_SERIALIZE);
     774        if (cb_sess == NULL) {
     775                async_answer_0(iid, ENOMEM);
     776                return;
     777        }
     778       
     779        fibril_mutex_lock(&callback_sess_mutex);
     780        if (callback_sess != NULL) {
     781                fibril_mutex_unlock(&callback_sess_mutex);
     782                async_answer_0(iid, EEXIST);
     783                return;
     784        }
     785       
     786        callback_sess = cb_sess;
     787        fibril_mutex_unlock(&callback_sess_mutex);
     788       
     789        async_answer_0(iid, EOK);
     790}
     791
     792void loc_category_change_event(void)
     793{
     794        fibril_mutex_lock(&callback_sess_mutex);
     795
     796        if (callback_sess != NULL) {
     797                async_exch_t *exch = async_exchange_begin(callback_sess);
     798                async_msg_0(exch, LOC_EVENT_CAT_CHANGE);
     799                async_exchange_end(exch);
     800        }
     801
     802        fibril_mutex_unlock(&callback_sess_mutex);
     803}
     804
     805/** Find ID for category specified by name.
     806 *
     807 * On success, answer will contain EOK int retval and service ID in arg1.
     808 * On failure, error code will be sent in retval.
     809 *
     810 */
    730811static void loc_category_get_id(ipc_callid_t iid, ipc_call_t *icall)
    731812{
     
    11291210
    11301211        async_answer_0(iid, retval);
     1212
     1213        loc_category_change_event();
    11311214}
    11321215
     
    11561239
    11571240        cat = category_new("serial");
     1241        categ_dir_add_cat(&cdir, cat);
     1242
     1243        cat = category_new("usbhc");
    11581244        categ_dir_add_cat(&cdir, cat);
    11591245
     
    12441330                        loc_namespace_get_id(callid, &call);
    12451331                        break;
     1332                case LOC_CALLBACK_CREATE:
     1333                        loc_callback_create(callid, &call);
     1334                        break;
    12461335                case LOC_CATEGORY_GET_ID:
    12471336                        loc_category_get_id(callid, &call);
     1337                        break;
     1338                case LOC_CATEGORY_GET_NAME:
     1339                        loc_category_get_name(callid, &call);
    12481340                        break;
    12491341                case LOC_CATEGORY_GET_SVCS:
Note: See TracChangeset for help on using the changeset viewer.