Changeset e280857 in mainline


Ignore:
Timestamp:
2011-08-18T12:35:59Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
99ac5cf
Parents:
12f9f0d0
Message:

Remove class infrastructure from devman.

Location:
uspace
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/lsusb/main.c

    r12f9f0d0 re280857  
    5050
    5151#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
    52 #define MAX_FAILED_ATTEMPTS 10
    5352#define MAX_PATH_LENGTH 1024
    5453
    55 static void print_found_hc(size_t class_index, const char *path)
     54static void print_found_hc(service_id_t sid, const char *path)
    5655{
    5756        // printf(NAME ": host controller %zu is `%s'.\n", class_index, path);
    58         printf("Bus %02zu: %s\n", class_index, path);
     57        printf("Bus %" PRIun ": %s\n", sid, path);
    5958}
    6059static void print_found_dev(usb_address_t addr, const char *path)
     
    9594int main(int argc, char *argv[])
    9695{
    97         size_t class_index = 0;
    98         size_t failed_attempts = 0;
     96        category_id_t usbhc_cat;
     97        service_id_t *svcs;
     98        size_t count;
     99        size_t i;
     100        int rc;
    99101
    100         while (failed_attempts < MAX_FAILED_ATTEMPTS) {
    101                 class_index++;
     102        rc = loc_category_get_id(USB_HC_DDF_CLASS_NAME, &usbhc_cat, 0);
     103        if (rc != EOK) {
     104                printf(NAME ": Error resolving category '%s'",
     105                    USB_HC_DDF_CLASS_NAME);
     106                return 1;
     107        }
     108
     109        rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
     110        if (rc != EOK) {
     111                printf(NAME ": Error getting list of host controllers.\n");
     112                return 1;
     113        }
     114
     115        for (i = 0; i < count; i++) {
    102116                devman_handle_t hc_handle = 0;
    103                 int rc = usb_ddf_get_hc_handle_by_class(class_index, &hc_handle);
     117                int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
    104118                if (rc != EOK) {
    105                         failed_attempts++;
     119                        printf(NAME ": Error resolving handle of HC with SID %"
     120                            PRIun ", skipping.\n", svcs[i]);
    106121                        continue;
    107122                }
     
    109124                rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
    110125                if (rc != EOK) {
     126                        printf(NAME ": Error resolving path of HC with SID %"
     127                            PRIun ", skipping.\n", svcs[i]);
    111128                        continue;
    112129                }
    113                 print_found_hc(class_index, path);
     130                print_found_hc(svcs[i], path);
    114131                print_hc_devices(hc_handle);
    115132        }
     133
     134        free(svcs);
    116135
    117136        return 0;
  • uspace/lib/c/generic/devman.c

    r12f9f0d0 re280857  
    333333                exch = devman_exchange_begin(DEVMAN_CLIENT);
    334334                if (exch == NULL)
    335                         return errno;
     335                        return ENOMEM;
    336336        }
    337337       
     
    364364}
    365365
    366 int devman_device_get_handle_by_class(const char *classname,
    367     const char *devname, devman_handle_t *handle, unsigned int flags)
    368 {
    369         async_exch_t *exch;
    370        
    371         if (flags & IPC_FLAG_BLOCKING)
    372                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
    373         else {
    374                 exch = devman_exchange_begin(DEVMAN_CLIENT);
    375                 if (exch == NULL)
    376                         return errno;
    377         }
    378        
    379         ipc_call_t answer;
    380         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    381             flags, &answer);
    382         sysarg_t retval = async_data_write_start(exch, classname,
    383             str_size(classname));
    384        
    385         if (retval != EOK) {
    386                 devman_exchange_end(exch);
    387                 async_wait_for(req, NULL);
    388                 return retval;
    389         }
    390        
    391         retval = async_data_write_start(exch, devname,
    392             str_size(devname));
    393        
    394         devman_exchange_end(exch);
    395        
    396         if (retval != EOK) {
    397                 async_wait_for(req, NULL);
    398                 return retval;
    399         }
    400        
    401         async_wait_for(req, &retval);
    402        
    403         if (retval != EOK) {
    404                 if (handle != NULL)
    405                         *handle = (devman_handle_t) -1;
    406                
    407                 return retval;
    408         }
    409        
    410         if (handle != NULL)
    411                 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
    412        
    413         return retval;
    414 }
    415 
    416366int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
    417367{
    418368        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
    419369        if (exch == NULL)
    420                 return errno;
     370                return ENOMEM;
    421371       
    422372        ipc_call_t answer;
     
    463413}
    464414
     415int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
     416{
     417        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     418        if (exch == NULL)
     419                return ENOMEM;
     420       
     421        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
     422            sid, handle);
     423       
     424        devman_exchange_end(exch);
     425        return (int) retval;
     426}
     427
    465428/** @}
    466429 */
  • uspace/lib/c/include/devman.h

    r12f9f0d0 re280857  
    3838
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <async.h>
    4142#include <bool.h>
     
    5657extern int devman_device_get_handle(const char *, devman_handle_t *,
    5758    unsigned int);
    58 extern int devman_device_get_handle_by_class(const char *, const char *,
    59     devman_handle_t *, unsigned int);
    6059extern int devman_get_device_path(devman_handle_t, char *, size_t);
    6160
    6261extern int devman_add_device_to_class(devman_handle_t, const char *);
     62extern int devman_fun_sid_to_handle(service_id_t, devman_handle_t *);
    6363
    6464#endif
  • uspace/lib/c/include/ipc/devman.h

    r12f9f0d0 re280857  
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    152         DEVMAN_DEVICE_GET_DEVICE_PATH
     151        DEVMAN_DEVICE_GET_DEVICE_PATH,
     152        DEVMAN_FUN_SID_TO_HANDLE
    153153} client_to_devman_t;
    154154
  • uspace/lib/usb/include/usb/hc.h

    r12f9f0d0 re280857  
    3838#include <sys/types.h>
    3939#include <ipc/devman.h>
     40#include <ipc/loc.h>
    4041#include <ddf/driver.h>
    4142#include <bool.h>
     
    6869    devman_handle_t *);
    6970
    70 int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *);
     71int usb_ddf_get_hc_handle_by_sid(service_id_t, devman_handle_t *);
    7172
    7273
  • uspace/lib/usb/src/hc.c

    r12f9f0d0 re280857  
    201201/** Get host controller handle by its class index.
    202202 *
    203  * @param class_index Class index for the host controller.
     203 * @param sid Service ID of the HC function.
    204204 * @param hc_handle Where to store the HC handle
    205205 *      (can be NULL for existence test only).
    206206 * @return Error code.
    207207 */
    208 int usb_ddf_get_hc_handle_by_class(size_t class_index,
    209     devman_handle_t *hc_handle)
    210 {
    211         char *class_index_str;
    212         devman_handle_t hc_handle_tmp;
     208int usb_ddf_get_hc_handle_by_sid(service_id_t sid, devman_handle_t *hc_handle)
     209{
     210        devman_handle_t handle;
    213211        int rc;
    214 
    215         rc = asprintf(&class_index_str, "%zu", class_index);
    216         if (rc < 0) {
    217                 return ENOMEM;
    218         }
    219         rc = devman_device_get_handle_by_class("usbhc", class_index_str,
    220             &hc_handle_tmp, 0);
    221         free(class_index_str);
    222         if (rc != EOK) {
    223                 return rc;
    224         }
    225 
    226         if (hc_handle != NULL) {
    227                 *hc_handle = hc_handle_tmp;
    228         }
    229 
    230         return EOK;
     212       
     213        rc = devman_fun_sid_to_handle(sid, &handle);
     214        if (hc_handle != NULL)
     215                *hc_handle = handle;
     216       
     217        return rc;
    231218}
    232219
  • uspace/lib/usb/src/resolve.c

    r12f9f0d0 re280857  
    4646    devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    4747{
    48         size_t class_index;
     48        uint64_t sid;
    4949        size_t address;
    5050        int rc;
    5151        char *ptr;
    5252
    53         rc = str_size_t(path, &ptr, 10, false, &class_index);
     53        rc = str_uint64(path, &ptr, 10, false, &sid);
    5454        if (rc != EOK) {
    5555                return false;
     
    6464                return false;
    6565        }
    66         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
     66        rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle);
    6767        if (rc != EOK) {
    6868                return false;
  • uspace/srv/devman/devman.c

    r12f9f0d0 re280857  
    7373}
    7474
    75 static int loc_devices_class_compare(unsigned long key[], hash_count_t keys,
    76     link_t *item)
    77 {
    78         dev_class_info_t *class_info
    79             = hash_table_get_instance(item, dev_class_info_t, loc_link);
    80         assert(class_info != NULL);
    81 
    82         return (class_info->service_id == (service_id_t) key[0]);
    83 }
    84 
    8575static void devices_remove_callback(link_t *item)
    8676{
     
    10292        .hash = devices_hash,
    10393        .compare = loc_functions_compare,
    104         .remove_callback = devices_remove_callback
    105 };
    106 
    107 static hash_table_operations_t loc_devices_class_ops = {
    108         .hash = devices_hash,
    109         .compare = loc_devices_class_compare,
    11094        .remove_callback = devices_remove_callback
    11195};
     
    950934                link_initialize(&res->dev_functions);
    951935                list_initialize(&res->match_ids.ids);
    952                 list_initialize(&res->classes);
    953936                link_initialize(&res->devman_fun);
    954937                link_initialize(&res->loc_fun);
     
    11931176}
    11941177
    1195 /** Find function node by its class name and index. */
    1196 fun_node_t *find_fun_node_by_class(class_list_t *class_list,
    1197     const char *class_name, const char *dev_name)
    1198 {
    1199         assert(class_list != NULL);
    1200         assert(class_name != NULL);
    1201         assert(dev_name != NULL);
    1202 
    1203         fibril_rwlock_read_lock(&class_list->rwlock);
    1204 
    1205         dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
    1206         if (cl == NULL) {
    1207                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1208                 return NULL;
    1209         }
    1210 
    1211         dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
    1212         if (dev == NULL) {
    1213                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1214                 return NULL;
    1215         }
    1216 
    1217         fun_node_t *fun = dev->fun;
    1218 
    1219         fibril_rwlock_read_unlock(&class_list->rwlock);
    1220 
    1221         return fun;
    1222 }
    1223 
    1224 
    12251178/** Find child function node with a specified name.
    12261179 *
     
    12351188        return find_fun_node_in_device(pfun->child, name);
    12361189}
    1237 
    1238 /* Device classes */
    1239 
    1240 /** Create device class.
    1241  *
    1242  * @return      Device class.
    1243  */
    1244 dev_class_t *create_dev_class(void)
    1245 {
    1246         dev_class_t *cl;
    1247        
    1248         cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    1249         if (cl != NULL) {
    1250                 memset(cl, 0, sizeof(dev_class_t));
    1251                 list_initialize(&cl->devices);
    1252                 fibril_mutex_initialize(&cl->mutex);
    1253         }
    1254        
    1255         return cl;
    1256 }
    1257 
    1258 /** Create device class info.
    1259  *
    1260  * @return              Device class info.
    1261  */
    1262 dev_class_info_t *create_dev_class_info(void)
    1263 {
    1264         dev_class_info_t *info;
    1265        
    1266         info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    1267         if (info != NULL) {
    1268                 memset(info, 0, sizeof(dev_class_info_t));
    1269                 link_initialize(&info->dev_classes);
    1270                 link_initialize(&info->loc_link);
    1271                 link_initialize(&info->link);
    1272         }
    1273        
    1274         return info;
    1275 }
    1276 
    1277 size_t get_new_class_dev_idx(dev_class_t *cl)
    1278 {
    1279         size_t dev_idx;
    1280        
    1281         fibril_mutex_lock(&cl->mutex);
    1282         dev_idx = ++cl->curr_dev_idx;
    1283         fibril_mutex_unlock(&cl->mutex);
    1284        
    1285         return dev_idx;
    1286 }
    1287 
    1288 
    1289 /** Create unique device name within the class.
    1290  *
    1291  * @param cl            The class.
    1292  * @param base_dev_name Contains the base name for the device if it was
    1293  *                      specified by the driver when it registered the device by
    1294  *                      the class; NULL if driver specified no base name.
    1295  * @return              The unique name for the device within the class.
    1296  */
    1297 char *create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name)
    1298 {
    1299         char *dev_name;
    1300         const char *base_name;
    1301        
    1302         if (base_dev_name != NULL)
    1303                 base_name = base_dev_name;
    1304         else
    1305                 base_name = cl->base_dev_name;
    1306        
    1307         size_t idx = get_new_class_dev_idx(cl);
    1308         asprintf(&dev_name, "%s%zu", base_name, idx);
    1309        
    1310         return dev_name;
    1311 }
    1312 
    1313 /** Add the device function to the class.
    1314  *
    1315  * The device may be added to multiple classes and a class may contain multiple
    1316  * devices. The class and the device are associated with each other by the
    1317  * dev_class_info_t structure.
    1318  *
    1319  * @param dev           The device.
    1320  * @param class         The class.
    1321  * @param base_dev_name The base name of the device within the class if
    1322  *                      specified by the driver, NULL otherwise.
    1323  * @return              dev_class_info_t structure which associates the device
    1324  *                      with the class.
    1325  */
    1326 dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
    1327     const char *base_dev_name)
    1328 {
    1329         dev_class_info_t *info;
    1330 
    1331         assert(fun != NULL);
    1332         assert(cl != NULL);
    1333 
    1334         info = create_dev_class_info();
    1335 
    1336        
    1337         if (info != NULL) {
    1338                 info->dev_class = cl;
    1339                 info->fun = fun;
    1340                
    1341                 /* Add the device to the class. */
    1342                 fibril_mutex_lock(&cl->mutex);
    1343                 list_append(&info->link, &cl->devices);
    1344                 fibril_mutex_unlock(&cl->mutex);
    1345                
    1346                 /* Add the class to the device. */
    1347                 list_append(&info->dev_classes, &fun->classes);
    1348                
    1349                 /* Create unique name for the device within the class. */
    1350                 info->dev_name = create_dev_name_for_class(cl, base_dev_name);
    1351         }
    1352        
    1353         return info;
    1354 }
    1355 
    1356 dev_class_t *get_dev_class(class_list_t *class_list, char *class_name)
    1357 {
    1358         dev_class_t *cl;
    1359        
    1360         fibril_rwlock_write_lock(&class_list->rwlock);
    1361         cl = find_dev_class_no_lock(class_list, class_name);
    1362         if (cl == NULL) {
    1363                 cl = create_dev_class();
    1364                 if (cl != NULL) {
    1365                         cl->name = class_name;
    1366                         cl->base_dev_name = "";
    1367                         add_dev_class_no_lock(class_list, cl);
    1368                 }
    1369         }
    1370 
    1371         fibril_rwlock_write_unlock(&class_list->rwlock);
    1372         return cl;
    1373 }
    1374 
    1375 dev_class_t *find_dev_class_no_lock(class_list_t *class_list,
    1376     const char *class_name)
    1377 {
    1378         dev_class_t *cl;
    1379        
    1380         list_foreach(class_list->classes, link) {
    1381                 cl = list_get_instance(link, dev_class_t, link);
    1382                 if (str_cmp(cl->name, class_name) == 0) {
    1383                         return cl;
    1384                 }
    1385         }
    1386        
    1387         return NULL;
    1388 }
    1389 
    1390 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
    1391 {
    1392         list_append(&cl->link, &class_list->classes);
    1393 }
    1394 
    1395 dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
    1396 {
    1397         assert(dev_class != NULL);
    1398         assert(dev_name != NULL);
    1399 
    1400         list_foreach(dev_class->devices, link) {
    1401                 dev_class_info_t *dev = list_get_instance(link,
    1402                     dev_class_info_t, link);
    1403 
    1404                 if (str_cmp(dev->dev_name, dev_name) == 0) {
    1405                         return dev;
    1406                 }
    1407         }
    1408 
    1409         return NULL;
    1410 }
    1411 
    1412 void init_class_list(class_list_t *class_list)
    1413 {
    1414         list_initialize(&class_list->classes);
    1415         fibril_rwlock_initialize(&class_list->rwlock);
    1416         hash_table_create(&class_list->loc_functions, DEVICE_BUCKETS, 1,
    1417             &loc_devices_class_ops);
    1418 }
    1419 
    14201190
    14211191/* loc devices */
     
    14361206}
    14371207
    1438 fun_node_t *find_loc_class_function(class_list_t *classes,
    1439     service_id_t service_id)
    1440 {
    1441         fun_node_t *fun = NULL;
    1442         dev_class_info_t *cli;
    1443         link_t *link;
    1444         unsigned long key = (unsigned long)service_id;
    1445        
    1446         fibril_rwlock_read_lock(&classes->rwlock);
    1447         link = hash_table_find(&classes->loc_functions, &key);
    1448         if (link != NULL) {
    1449                 cli = hash_table_get_instance(link, dev_class_info_t,
    1450                     loc_link);
    1451                 fun = cli->fun;
    1452         }
    1453         fibril_rwlock_read_unlock(&classes->rwlock);
    1454        
    1455         return fun;
    1456 }
    1457 
    1458 void class_add_loc_function(class_list_t *class_list, dev_class_info_t *cli)
    1459 {
    1460         unsigned long key = (unsigned long) cli->service_id;
    1461        
    1462         fibril_rwlock_write_lock(&class_list->rwlock);
    1463         hash_table_insert(&class_list->loc_functions, &key, &cli->loc_link);
    1464         fibril_rwlock_write_unlock(&class_list->rwlock);
    1465 
    1466         assert(find_loc_class_function(class_list, cli->service_id) != NULL);
    1467 }
    1468 
    14691208void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun)
    14701209{
  • uspace/srv/devman/devman.h

    r12f9f0d0 re280857  
    5353#define DEVICE_BUCKETS 256
    5454
    55 #define LOC_CLASS_NAMESPACE "class"
    5655#define LOC_DEVICE_NAMESPACE "devices"
    5756#define LOC_SEPARATOR '\\'
     
    170169        match_id_list_t match_ids;
    171170       
    172         /** List of device classes to which this device function belongs. */
    173         list_t classes;
    174171        /** Service ID if the device function is registered with loc. */
    175172        service_id_t service_id;
     
    213210        hash_table_t loc_functions;
    214211} dev_tree_t;
    215 
    216 typedef struct dev_class {
    217         /** The name of the class. */
    218         const char *name;
    219        
    220         /**
    221          * Pointer to the previous and next class in the list of registered
    222          * classes.
    223          */
    224         link_t link;
    225        
    226         /**
    227          * List of dev_class_info structures - one for each device registered by
    228          * this class.
    229          */
    230         list_t devices;
    231        
    232         /**
    233          * Default base name for the device within the class, might be overrided
    234          * by the driver.
    235          */
    236         const char *base_dev_name;
    237        
    238         /** Unique numerical identifier of the newly added device. */
    239         size_t curr_dev_idx;
    240         /** Synchronize access to the list of devices in this class. */
    241         fibril_mutex_t mutex;
    242 } dev_class_t;
    243 
    244 /**
    245  * Provides n-to-m mapping between function nodes and classes - each function
    246  * can register in an arbitrary number of classes and each class can contain
    247  * an arbitrary number of device functions.
    248  */
    249 typedef struct dev_class_info {
    250         /** The class. */
    251         dev_class_t *dev_class;
    252         /** The device. */
    253         fun_node_t *fun;
    254        
    255         /**
    256          * Pointer to the previous and next class info in the list of devices
    257          * registered by the class.
    258          */
    259         link_t link;
    260        
    261         /**
    262          * Pointer to the previous and next class info in the list of classes
    263          * by which the device is registered.
    264          */
    265         link_t dev_classes;
    266        
    267         /** The name of the device function within the class. */
    268         char *dev_name;
    269         /** Service ID in the class namespace. */
    270         service_id_t service_id;
    271        
    272         /**
    273          * Link to hash table of services registered with location service using
    274          * their class names.
    275          */
    276         link_t loc_link;
    277 } dev_class_info_t;
    278 
    279 /** The list of device classes. */
    280 typedef struct class_list {
    281         /** List of classes. */
    282         list_t classes;
    283        
    284         /**
    285          * Hash table of services registered with location service using their
    286          * class name, indexed by service IDs.
    287          */
    288         hash_table_t loc_functions;
    289        
    290         /** Fibril mutex for list of classes. */
    291         fibril_rwlock_t rwlock;
    292 } class_list_t;
    293212
    294213/* Match ids and scores */
     
    339258extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
    340259extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
    341 extern fun_node_t *find_fun_node_by_class(class_list_t *, const char *, const char *);
    342260
    343261/* Device tree */
     
    348266extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
    349267
    350 /* Device classes */
    351 
    352 extern dev_class_t *create_dev_class(void);
    353 extern dev_class_info_t *create_dev_class_info(void);
    354 extern size_t get_new_class_dev_idx(dev_class_t *);
    355 extern char *create_dev_name_for_class(dev_class_t *, const char *);
    356 extern dev_class_info_t *add_function_to_class(fun_node_t *, dev_class_t *,
    357     const char *);
    358 
    359 extern void init_class_list(class_list_t *);
    360 
    361 extern dev_class_t *get_dev_class(class_list_t *, char *);
    362 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
    363 extern dev_class_info_t *find_dev_in_class(dev_class_t *, const char *);
    364 extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    365 
    366268/* Loc services */
    367269
     
    369271
    370272extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
    371 extern fun_node_t *find_loc_class_function(class_list_t *, service_id_t);
    372 
    373 extern void class_add_loc_function(class_list_t *, dev_class_info_t *);
     273
    374274extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
    375275
  • uspace/srv/devman/main.c

    r12f9f0d0 re280857  
    6464static driver_list_t drivers_list;
    6565static dev_tree_t device_tree;
    66 static class_list_t class_list;
    6766
    6867/** Register running driver. */
     
    333332}
    334333
    335 static void loc_register_class_dev(dev_class_info_t *cli)
    336 {
    337         /* Create loc path and name for the service. */
    338         char *loc_pathname = NULL;
    339 
    340         asprintf(&loc_pathname, "%s/%s%c%s", LOC_CLASS_NAMESPACE,
    341             cli->dev_class->name, LOC_SEPARATOR, cli->dev_name);
    342         if (loc_pathname == NULL)
    343                 return;
    344        
    345         /*
    346          * Register the device with location service and remember its
    347          * service ID.
    348          */
    349         loc_service_register_with_iface(loc_pathname,
    350             &cli->service_id, DEVMAN_CONNECT_FROM_LOC);
    351        
    352         /*
    353          * Add device to the hash map of class devices registered with
    354          * location service.
    355          */
    356         class_add_loc_function(&class_list, cli);
    357        
    358         free(loc_pathname);
    359 }
    360 
    361334static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
    362335{
     
    380353        }
    381354       
    382         dev_class_t *cl = get_dev_class(&class_list, class_name);
    383         dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    384        
    385         /* Register the device's class alias with location service. */
    386         loc_register_class_dev(class_info);
    387        
    388355        rc = loc_category_get_id(class_name, &cat_id, IPC_FLAG_BLOCKING);
    389356        if (rc == EOK) {
     
    394361        }
    395362       
    396         log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
    397             fun->pathname, class_name, class_info->dev_name);
     363        log_msg(LVL_NOTE, "Function `%s' added to class `%s'.",
     364            fun->pathname, class_name);
    398365
    399366        async_answer_0(callid, EOK);
     
    483450}
    484451
    485 /** Find handle for the device instance identified by device class name. */
    486 static void devman_function_get_handle_by_class(ipc_callid_t iid,
    487     ipc_call_t *icall)
    488 {
    489         char *classname;
    490         char *devname;
    491 
    492         int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
    493         if (rc != EOK) {
    494                 async_answer_0(iid, rc);
    495                 return;
    496         }
    497         rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
    498         if (rc != EOK) {
    499                 free(classname);
    500                 async_answer_0(iid, rc);
    501                 return;
    502         }
    503 
    504 
    505         fun_node_t *fun = find_fun_node_by_class(&class_list,
    506             classname, devname);
    507 
    508         free(classname);
    509         free(devname);
    510 
    511         if (fun == NULL) {
    512                 async_answer_0(iid, ENOENT);
    513                 return;
    514         }
    515 
    516         async_answer_1(iid, EOK, fun->handle);
    517 }
    518 
    519452/** Find device path by its handle. */
    520453static void devman_get_device_path_by_handle(ipc_callid_t iid,
     
    554487}
    555488
     489/** Find handle for the function instance identified by its service ID. */
     490static void devman_fun_sid_to_handle(ipc_callid_t iid, ipc_call_t *icall)
     491{
     492        fun_node_t *fun;
     493
     494        fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall));
     495       
     496        if (fun == NULL) {
     497                async_answer_0(iid, ENOENT);
     498                return;
     499        }
     500
     501        async_answer_1(iid, EOK, fun->handle);
     502}
    556503
    557504/** Function for handling connections from a client to the device manager. */
     
    572519                        devman_function_get_handle(callid, &call);
    573520                        break;
    574                 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    575                         devman_function_get_handle_by_class(callid, &call);
    576                         break;
    577521                case DEVMAN_DEVICE_GET_DEVICE_PATH:
    578522                        devman_get_device_path_by_handle(callid, &call);
     523                        break;
     524                case DEVMAN_FUN_SID_TO_HANDLE:
     525                        devman_fun_sid_to_handle(callid, &call);
    579526                        break;
    580527                default:
     
    678625
    679626        fun = find_loc_tree_function(&device_tree, service_id);
    680         if (fun == NULL)
    681                 fun = find_loc_class_function(&class_list, service_id);
    682627       
    683628        if (fun == NULL || fun->dev->drv == NULL) {
     
    750695        }
    751696
    752         init_class_list(&class_list);
    753        
    754697        /*
    755698         * !!! devman_connection ... as the device manager is not a real loc
  • uspace/srv/loc/loc.c

    r12f9f0d0 re280857  
    12031203        categ_dir_add_cat(&cdir, cat);
    12041204
     1205        cat = category_new("usbhc");
     1206        categ_dir_add_cat(&cdir, cat);
     1207
    12051208        return true;
    12061209}
Note: See TracChangeset for help on using the changeset viewer.