Changeset 12f9f0d0 in mainline for uspace/lib/c/generic/loc.c


Ignore:
Timestamp:
2011-08-17T13:39:53Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e280857
Parents:
45058baa
Message:

Notifications on changes in loc categories. Limitations:

  • cannot specify single category to watch
  • max one task can register notifications with loc service
  • max one user callback function can be registered with C library

Remove devman tests as they are not applicable anymore.

File:
1 edited

Legend:

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

    r45058baa r12f9f0d0  
    4545static FIBRIL_MUTEX_INITIALIZE(loc_consumer_mutex);
    4646
     47static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
     48static bool loc_callback_created = false;
     49
    4750static async_sess_t *loc_supp_block_sess = NULL;
    4851static async_sess_t *loc_cons_block_sess = NULL;
     
    5154static async_sess_t *loc_consumer_sess = NULL;
    5255
     56static loc_cat_change_cb_t cat_change_cb = NULL;
     57
     58static 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
    5392static void clone_session(fibril_mutex_t *mtx, async_sess_t *src,
    5493    async_sess_t **dst)
     
    6099       
    61100        fibril_mutex_unlock(mtx);
     101}
     102
     103static 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;
     132done:
     133        fibril_mutex_unlock(&loc_callback_mutex);
     134        return rc;
    62135}
    63136
     
    749822            data, count);
    750823}
     824
     825int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
     826{
     827        if (loc_callback_create() != EOK)
     828                return EIO;
     829
     830        cat_change_cb = cb_fun;
     831        return EOK;
     832}
Note: See TracChangeset for help on using the changeset viewer.