Changeset fc8c2b6 in mainline


Ignore:
Timestamp:
2011-03-30T14:26:13Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e72fb34
Parents:
3fddb55
Message:

devman can tell device handle by its class path

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/ipc/devman.h

    r3fddb55 rfc8c2b6  
    148148
    149149typedef enum {
    150         DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD
     150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
     151        DEVMAN_DEVICE_GET_HANDLE_BY_CLASS
    151152} client_to_devman_t;
    152153
  • uspace/srv/devman/devman.c

    r3fddb55 rfc8c2b6  
    11941194}
    11951195
     1196/** Find function node by its class name and index. */
     1197fun_node_t *find_fun_node_by_class(class_list_t *class_list,
     1198    const char *class_name, const char *dev_name)
     1199{
     1200        assert(class_list != NULL);
     1201        assert(class_name != NULL);
     1202        assert(dev_name != NULL);
     1203
     1204        fibril_rwlock_read_lock(&class_list->rwlock);
     1205
     1206        dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
     1207        if (cl == NULL) {
     1208                fibril_rwlock_read_unlock(&class_list->rwlock);
     1209                return NULL;
     1210        }
     1211
     1212        dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
     1213        if (dev == NULL) {
     1214                fibril_rwlock_read_unlock(&class_list->rwlock);
     1215                return NULL;
     1216        }
     1217
     1218        fun_node_t *fun = dev->fun;
     1219
     1220        fibril_rwlock_read_unlock(&class_list->rwlock);
     1221
     1222        return fun;
     1223}
     1224
     1225
    11961226/** Find child function node with a specified name.
    11971227 *
     
    13661396}
    13671397
     1398dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
     1399{
     1400        assert(dev_class != NULL);
     1401        assert(dev_name != NULL);
     1402
     1403        link_t *link;
     1404        for (link = dev_class->devices.next;
     1405            link != &dev_class->devices;
     1406            link = link->next) {
     1407                dev_class_info_t *dev = list_get_instance(link,
     1408                    dev_class_info_t, link);
     1409
     1410                if (str_cmp(dev->dev_name, dev_name) == 0) {
     1411                        return dev;
     1412                }
     1413        }
     1414
     1415        return NULL;
     1416}
     1417
    13681418void init_class_list(class_list_t *class_list)
    13691419{
  • uspace/srv/devman/devman.h

    r3fddb55 rfc8c2b6  
    339339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
    340340extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
     341extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    341342
    342343/* Device tree */
     
    360361extern dev_class_t *get_dev_class(class_list_t *, char *);
    361362extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
     363extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
    362364extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    363365
  • uspace/srv/devman/main.c

    r3fddb55 rfc8c2b6  
    448448}
    449449
     450/** Find handle for the device instance identified by device class name. */
     451static void devman_function_get_handle_by_class(ipc_callid_t iid,
     452    ipc_call_t *icall)
     453{
     454        char *classname;
     455        char *devname;
     456
     457        int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
     458        if (rc != EOK) {
     459                async_answer_0(iid, rc);
     460                return;
     461        }
     462        rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
     463        if (rc != EOK) {
     464                free(classname);
     465                async_answer_0(iid, rc);
     466                return;
     467        }
     468
     469
     470        fun_node_t *fun = find_fun_node_by_class(&class_list,
     471            classname, devname);
     472
     473        free(classname);
     474        free(devname);
     475
     476        if (fun == NULL) {
     477                async_answer_0(iid, ENOENT);
     478                return;
     479        }
     480
     481        async_answer_1(iid, EOK, fun->handle);
     482}
     483
    450484
    451485/** Function for handling connections from a client to the device manager. */
     
    466500                case DEVMAN_DEVICE_GET_HANDLE:
    467501                        devman_function_get_handle(callid, &call);
     502                        break;
     503                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
     504                        devman_function_get_handle_by_class(callid, &call);
    468505                        break;
    469506                default:
Note: See TracChangeset for help on using the changeset viewer.