Ignore:
File:
1 edited

Legend:

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

    r9b415c9 rebcb05a  
    7373        driver_t *driver = NULL;
    7474
    75         log_msg(LVL_DEBUG, "devman_driver_register\n");
     75        log_msg(LVL_DEBUG, "devman_driver_register");
    7676       
    7777        iid = async_get_call(&icall);
     
    9090        }
    9191
    92         log_msg(LVL_DEBUG, "The `%s' driver is trying to register.\n",
     92        log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
    9393            drv_name);
    9494       
     
    9797       
    9898        if (driver == NULL) {
    99                 log_msg(LVL_ERROR, "No driver named `%s' was found.\n", drv_name);
     99                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
    100100                free(drv_name);
    101101                drv_name = NULL;
     
    108108       
    109109        /* Create connection to the driver. */
    110         log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.\n",
     110        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
    111111            driver->name);
    112112        ipc_call_t call;
     
    122122       
    123123        log_msg(LVL_NOTE,
    124             "The `%s' driver was successfully registered as running.\n",
     124            "The `%s' driver was successfully registered as running.",
    125125            driver->name);
    126126       
     
    147147        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    148148                log_msg(LVL_ERROR,
    149                     "Invalid protocol when trying to receive match id.\n");
     149                    "Invalid protocol when trying to receive match id.");
    150150                async_answer_0(callid, EINVAL);
    151151                delete_match_id(match_id);
     
    154154       
    155155        if (match_id == NULL) {
    156                 log_msg(LVL_ERROR, "Failed to allocate match id.\n");
     156                log_msg(LVL_ERROR, "Failed to allocate match id.");
    157157                async_answer_0(callid, ENOMEM);
    158158                return ENOMEM;
     
    168168        if (rc != EOK) {
    169169                delete_match_id(match_id);
    170                 log_msg(LVL_ERROR, "Failed to receive match id string: %s.\n",
     170                log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
    171171                    str_error(rc));
    172172                return rc;
     
    175175        list_append(&match_id->link, &match_ids->ids);
    176176       
    177         log_msg(LVL_DEBUG, "Received match id `%s', score %d.\n",
     177        log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
    178178            match_id->id, match_id->score);
    179179        return rc;
     
    232232                /* Unknown function type */
    233233                log_msg(LVL_ERROR,
    234                     "Unknown function type %d provided by driver.\n",
     234                    "Unknown function type %d provided by driver.",
    235235                    (int) ftype);
    236236
     
    248248        }
    249249       
     250        /* Check that function with same name is not there already. */
     251        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
     252                fibril_rwlock_write_unlock(&tree->rwlock);
     253                async_answer_0(callid, EEXISTS);
     254                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     255                    fun_name);
     256                free(fun_name);
     257                return;
     258        }
     259
    250260        fun_node_t *fun = create_fun_node();
    251261        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
     
    270280        fibril_rwlock_write_unlock(&tree->rwlock);
    271281       
    272         log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")\n", fun->pathname);
     282        log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    273283       
    274284        devman_receive_match_ids(match_count, &fun->match_ids);
     
    352362        devmap_register_class_dev(class_info);
    353363       
    354         log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.\n",
     364        log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
    355365            fun->pathname, class_name, class_info->dev_name);
    356366
     
    368378       
    369379        initialize_running_driver(driver, &device_tree);
    370         log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.\n",
     380        log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
    371381            driver->name);
    372382        return 0;
     
    391401        if (fid == 0) {
    392402                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
    393                     "for driver `%s' .\n", driver->name);
     403                    "for driver `%s'.", driver->name);
    394404                return;
    395405        }
     
    443453}
    444454
     455/** Find handle for the device instance identified by device class name. */
     456static void devman_function_get_handle_by_class(ipc_callid_t iid,
     457    ipc_call_t *icall)
     458{
     459        char *classname;
     460        char *devname;
     461
     462        int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
     463        if (rc != EOK) {
     464                async_answer_0(iid, rc);
     465                return;
     466        }
     467        rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
     468        if (rc != EOK) {
     469                free(classname);
     470                async_answer_0(iid, rc);
     471                return;
     472        }
     473
     474
     475        fun_node_t *fun = find_fun_node_by_class(&class_list,
     476            classname, devname);
     477
     478        free(classname);
     479        free(devname);
     480
     481        if (fun == NULL) {
     482                async_answer_0(iid, ENOENT);
     483                return;
     484        }
     485
     486        async_answer_1(iid, EOK, fun->handle);
     487}
     488
    445489
    446490/** Function for handling connections from a client to the device manager. */
     
    462506                        devman_function_get_handle(callid, &call);
    463507                        break;
     508                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
     509                        devman_function_get_handle_by_class(callid, &call);
     510                        break;
    464511                default:
    465512                        async_answer_0(callid, ENOENT);
     
    490537        if (dev == NULL) {
    491538                log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
    492                     "function with handle %" PRIun " was found.\n", handle);
     539                    "function with handle %" PRIun " was found.", handle);
    493540                async_answer_0(iid, ENOENT);
    494541                return;
     
    497544        if (fun == NULL && !drv_to_parent) {
    498545                log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
    499                     "connect to handle %" PRIun ", refers to a device.\n",
     546                    "connect to handle %" PRIun ", refers to a device.",
    500547                    handle);
    501548                async_answer_0(iid, ENOENT);
     
    520567        if (driver == NULL) {
    521568                log_msg(LVL_ERROR, "IPC forwarding refused - " \
    522                     "the device %" PRIun " is not in usable state.\n", handle);
     569                    "the device %" PRIun " is not in usable state.", handle);
    523570                async_answer_0(iid, ENOENT);
    524571                return;
     
    533580        if (driver->phone <= 0) {
    534581                log_msg(LVL_ERROR,
    535                     "Could not forward to driver `%s' (phone is %d).\n",
     582                    "Could not forward to driver `%s' (phone is %d).",
    536583                    driver->name, (int) driver->phone);
    537584                async_answer_0(iid, EINVAL);
     
    541588        if (fun != NULL) {
    542589                log_msg(LVL_DEBUG,
    543                     "Forwarding request for `%s' function to driver `%s'.\n",
     590                    "Forwarding request for `%s' function to driver `%s'.",
    544591                    fun->pathname, driver->name);
    545592        } else {
    546593                log_msg(LVL_DEBUG,
    547                     "Forwarding request for `%s' device to driver `%s'.\n",
     594                    "Forwarding request for `%s' device to driver `%s'.",
    548595                    dev->pfun->pathname, driver->name);
    549596        }
     
    579626            IPC_FF_NONE);
    580627        log_msg(LVL_DEBUG,
    581             "Forwarding devmapper request for `%s' function to driver `%s'.\n",
     628            "Forwarding devmapper request for `%s' function to driver `%s'.",
    582629            fun->pathname, dev->drv->name);
    583630}
     
    615662static bool devman_init(void)
    616663{
    617         log_msg(LVL_DEBUG, "devman_init - looking for available drivers.\n");
     664        log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
    618665       
    619666        /* Initialize list of available drivers. */
     
    621668        if (lookup_available_drivers(&drivers_list,
    622669            DRIVER_DEFAULT_STORE) == 0) {
    623                 log_msg(LVL_FATAL, "no drivers found.");
     670                log_msg(LVL_FATAL, "No drivers found.");
    624671                return false;
    625672        }
    626673
    627         log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.\n");
     674        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    628675
    629676        /* Create root device node. */
     
    656703
    657704        if (!devman_init()) {
    658                 log_msg(LVL_ERROR, "Error while initializing service.\n");
     705                log_msg(LVL_ERROR, "Error while initializing service.");
    659706                return -1;
    660707        }
     
    665712        /* Register device manager at naming service. */
    666713        if (service_register(SERVICE_DEVMAN) != EOK) {
    667                 log_msg(LVL_ERROR, "Failed registering as a service.\n");
     714                log_msg(LVL_ERROR, "Failed registering as a service.");
    668715                return -1;
    669716        }
Note: See TracChangeset for help on using the changeset viewer.