Changeset a92cf94f in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-08-18T18:45:42Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1f44b056
Parents:
ee24574 (diff), f55b12b (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 libposix changes.

File:
1 edited

Legend:

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

    ree24574 ra92cf94f  
    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 
    361 static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
     334static void devman_add_function_to_cat(ipc_callid_t callid, ipc_call_t *call)
    362335{
    363336        devman_handle_t handle = IPC_GET_ARG1(*call);
     
    365338        int rc;
    366339       
    367         /* Get class name. */
    368         char *class_name;
    369         rc = async_data_write_accept((void **) &class_name, true,
     340        /* Get category name. */
     341        char *cat_name;
     342        rc = async_data_write_accept((void **) &cat_name, true,
    370343            0, 0, 0, 0);
    371344        if (rc != EOK) {
     
    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        
    388         rc = loc_category_get_id(class_name, &cat_id, IPC_FLAG_BLOCKING);
     355        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
    389356        if (rc == EOK) {
    390357                loc_service_add_to_cat(fun->service_id, cat_id);
    391358        } else {
    392359                log_msg(LVL_ERROR, "Failed adding function `%s' to category "
    393                     "`%s'.", fun->pathname, class_name);
    394         }
    395        
    396         log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
    397             fun->pathname, class_name, class_info->dev_name);
     360                    "`%s'.", fun->pathname, cat_name);
     361        }
     362       
     363        log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
     364            fun->pathname, cat_name);
    398365
    399366        async_answer_0(callid, EOK);
     
    449416                        devman_add_function(callid, &call);
    450417                        break;
    451                 case DEVMAN_ADD_DEVICE_TO_CLASS:
    452                         devman_add_function_to_class(callid, &call);
     418                case DEVMAN_ADD_DEVICE_TO_CATEGORY:
     419                        devman_add_function_to_cat(callid, &call);
    453420                        break;
    454421                default:
     
    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) {
     629                log_msg(LVL_WARN, "devman_connection_loc(): function "
     630                    "not found.\n");
    684631                async_answer_0(iid, ENOENT);
    685632                return;
     
    687634       
    688635        dev = fun->dev;
    689        
    690         if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    691                 async_answer_0(iid, EINVAL);
    692                 return;
    693         }
    694636       
    695637        async_exch_t *exch = async_exchange_begin(dev->drv->sess);
     
    753695        }
    754696
    755         init_class_list(&class_list);
    756        
    757697        /*
    758698         * !!! devman_connection ... as the device manager is not a real loc
Note: See TracChangeset for help on using the changeset viewer.