Changeset 4c9b28a in mainline for uspace/srv/devman/client_conn.c


Ignore:
Timestamp:
2013-09-11T17:32:45Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5759975a
Parents:
1db5669
Message:

Printing match IDs of drivers and functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/client_conn.c

    r1db5669 r4c9b28a  
    9999}
    100100
     101/** Get device match ID. */
     102static void devman_fun_get_match_id(ipc_callid_t iid, ipc_call_t *icall)
     103{
     104        devman_handle_t handle = IPC_GET_ARG1(*icall);
     105        size_t index = IPC_GET_ARG2(*icall);
     106        void *buffer = NULL;
     107
     108        fun_node_t *fun = find_fun_node(&device_tree, handle);
     109        if (fun == NULL) {
     110                async_answer_0(iid, ENOMEM);
     111                return;
     112        }
     113
     114        ipc_callid_t data_callid;
     115        size_t data_len;
     116        if (!async_data_read_receive(&data_callid, &data_len)) {
     117                async_answer_0(iid, EINVAL);
     118                fun_del_ref(fun);
     119                return;
     120        }
     121
     122        buffer = malloc(data_len);
     123        if (buffer == NULL) {
     124                async_answer_0(data_callid, ENOMEM);
     125                async_answer_0(iid, ENOMEM);
     126                fun_del_ref(fun);
     127                return;
     128        }
     129
     130        fibril_rwlock_read_lock(&device_tree.rwlock);
     131
     132        /* Check function state */
     133        if (fun->state == FUN_REMOVED)
     134                goto error;
     135
     136        link_t *link = list_nth(&fun->match_ids.ids, index);
     137        if (link == NULL)
     138                goto error;
     139
     140        match_id_t *mid = list_get_instance(link, match_id_t, link);
     141
     142        size_t sent_length = str_size(mid->id);
     143        if (sent_length > data_len) {
     144                sent_length = data_len;
     145        }
     146
     147        async_data_read_finalize(data_callid, mid->id, sent_length);
     148        async_answer_1(iid, EOK, mid->score);
     149
     150        fibril_rwlock_read_unlock(&device_tree.rwlock);
     151        fun_del_ref(fun);
     152        free(buffer);
     153
     154        return;
     155error:
     156        fibril_rwlock_read_unlock(&device_tree.rwlock);
     157        free(buffer);
     158
     159        async_answer_0(data_callid, ENOENT);
     160        async_answer_0(iid, ENOENT);
     161        fun_del_ref(fun);
     162}
     163
    101164/** Get device name. */
    102165static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall)
     
    539602}
    540603
     604/** Get driver match ID. */
     605static void devman_driver_get_match_id(ipc_callid_t iid, ipc_call_t *icall)
     606{
     607        devman_handle_t handle = IPC_GET_ARG1(*icall);
     608        size_t index = IPC_GET_ARG2(*icall);
     609
     610        driver_t *drv = driver_find(&drivers_list, handle);
     611        if (drv == NULL) {
     612                async_answer_0(iid, ENOMEM);
     613                return;
     614        }
     615
     616        ipc_callid_t data_callid;
     617        size_t data_len;
     618        if (!async_data_read_receive(&data_callid, &data_len)) {
     619                async_answer_0(iid, EINVAL);
     620                return;
     621        }
     622
     623        void *buffer = malloc(data_len);
     624        if (buffer == NULL) {
     625                async_answer_0(data_callid, ENOMEM);
     626                async_answer_0(iid, ENOMEM);
     627                return;
     628        }
     629
     630        fibril_mutex_lock(&drv->driver_mutex);
     631        link_t *link = list_nth(&drv->match_ids.ids, index);
     632        if (link == NULL) {
     633                fibril_mutex_unlock(&drv->driver_mutex);
     634                async_answer_0(data_callid, ENOMEM);
     635                async_answer_0(iid, ENOMEM);
     636                return;
     637        }
     638
     639        match_id_t *mid = list_get_instance(link, match_id_t, link);
     640
     641        size_t sent_length = str_size(mid->id);
     642        if (sent_length > data_len) {
     643                sent_length = data_len;
     644        }
     645
     646        async_data_read_finalize(data_callid, mid->id, sent_length);
     647        async_answer_1(iid, EOK, mid->score);
     648
     649        fibril_mutex_unlock(&drv->driver_mutex);
     650
     651        free(buffer);
     652}
     653
    541654/** Get driver name. */
    542655static void devman_driver_get_name(ipc_callid_t iid, ipc_call_t *icall)
     
    638751                        devman_fun_get_child(callid, &call);
    639752                        break;
     753                case DEVMAN_FUN_GET_MATCH_ID:
     754                        devman_fun_get_match_id(callid, &call);
     755                        break;
    640756                case DEVMAN_FUN_GET_NAME:
    641757                        devman_fun_get_name(callid, &call);
     
    664780                case DEVMAN_DRIVER_GET_HANDLE:
    665781                        devman_driver_get_handle(callid, &call);
     782                        break;
     783                case DEVMAN_DRIVER_GET_MATCH_ID:
     784                        devman_driver_get_match_id(callid, &call);
    666785                        break;
    667786                case DEVMAN_DRIVER_GET_NAME:
Note: See TracChangeset for help on using the changeset viewer.