Ignore:
File:
1 edited

Legend:

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

    r3f57fb7 r655cc56  
    245245       
    246246        fibril_rwlock_write_lock(&device_tree.rwlock);
    247        
     247
    248248        if (fun->state == FUN_ON_LINE) {
    249249                fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    259259                        return ENOMEM;
    260260                }
    261                
     261
    262262                insert_dev_node(&device_tree, dev, fun);
    263263                dev_add_ref(dev);
     
    272272                /* Give one reference over to assign_driver_fibril(). */
    273273                dev_add_ref(dev);
    274                
    275274                /*
    276275                 * Try to find a suitable driver and assign it to the device.  We do
     
    289288                }
    290289                fibril_add_ready(assign_fibril);
    291         } else
     290        } else {
    292291                loc_register_tree_function(fun, &device_tree);
     292        }
    293293       
    294294        fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    855855}
    856856
    857 /** Get function driver name. */
    858 static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall)
    859 {
    860         devman_handle_t handle = IPC_GET_ARG1(*icall);
    861 
    862         fun_node_t *fun = find_fun_node(&device_tree, handle);
    863         if (fun == NULL) {
    864                 async_answer_0(iid, ENOMEM);
    865                 return;
    866         }
    867 
    868         ipc_callid_t data_callid;
    869         size_t data_len;
    870         if (!async_data_read_receive(&data_callid, &data_len)) {
    871                 async_answer_0(iid, EINVAL);
    872                 fun_del_ref(fun);
    873                 return;
    874         }
    875 
    876         void *buffer = malloc(data_len);
    877         if (buffer == NULL) {
    878                 async_answer_0(data_callid, ENOMEM);
    879                 async_answer_0(iid, ENOMEM);
    880                 fun_del_ref(fun);
    881                 return;
    882         }
    883 
    884         fibril_rwlock_read_lock(&device_tree.rwlock);
    885 
    886         /* Check function state */
    887         if (fun->state == FUN_REMOVED) {
    888                 fibril_rwlock_read_unlock(&device_tree.rwlock);
    889                 free(buffer);
    890 
    891                 async_answer_0(data_callid, ENOENT);
    892                 async_answer_0(iid, ENOENT);
    893                 fun_del_ref(fun);
    894                 return;
    895         }
    896 
    897         /* Check whether function has a driver */
    898         if (fun->child == NULL || fun->child->drv == NULL) {
    899                 fibril_rwlock_read_unlock(&device_tree.rwlock);
    900                 free(buffer);
    901 
    902                 async_answer_0(data_callid, EINVAL);
    903                 async_answer_0(iid, EINVAL);
    904                 fun_del_ref(fun);
    905                 return;
    906         }
    907 
    908         size_t sent_length = str_size(fun->child->drv->name);
    909         if (sent_length > data_len) {
    910                 sent_length = data_len;
    911         }
    912 
    913         async_data_read_finalize(data_callid, fun->child->drv->name,
    914             sent_length);
    915         async_answer_0(iid, EOK);
    916 
    917         fibril_rwlock_read_unlock(&device_tree.rwlock);
    918         fun_del_ref(fun);
    919         free(buffer);
    920 }
    921857
    922858/** Get device path. */
     
    11471083                        devman_fun_get_name(callid, &call);
    11481084                        break;
    1149                 case DEVMAN_FUN_GET_DRIVER_NAME:
    1150                         devman_fun_get_driver_name(callid, &call);
    1151                         break;
    11521085                case DEVMAN_FUN_GET_PATH:
    11531086                        devman_fun_get_path(callid, &call);
     
    12161149                if (dev->pfun->dev != NULL)
    12171150                        driver = dev->pfun->dev->drv;
    1218                
    12191151                fwd_h = dev->pfun->handle;
    12201152        } else if (dev->state == DEVICE_USABLE) {
     
    12221154                driver = dev->drv;
    12231155                assert(driver != NULL);
    1224                
     1156
    12251157                fwd_h = handle;
    12261158        }
     
    12491181
    12501182        if (fun != NULL) {
    1251                 log_msg(LVL_DEBUG,
     1183                log_msg(LVL_DEBUG, 
    12521184                    "Forwarding request for `%s' function to driver `%s'.",
    12531185                    fun->pathname, driver->name);
    12541186        } else {
    1255                 log_msg(LVL_DEBUG,
     1187                log_msg(LVL_DEBUG, 
    12561188                    "Forwarding request for `%s' device to driver `%s'.",
    12571189                    dev->pfun->pathname, driver->name);
     
    12611193        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
    12621194        async_exchange_end(exch);
    1263        
     1195
    12641196cleanup:
    12651197        if (dev != NULL)
    12661198                dev_del_ref(dev);
    1267        
    12681199        if (fun != NULL)
    12691200                fun_del_ref(fun);
     
    13681299                return false;
    13691300        }
    1370        
     1301
    13711302        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    1372        
     1303
    13731304        /* Create root device node. */
    13741305        if (!init_device_tree(&device_tree, &drivers_list)) {
     
    13761307                return false;
    13771308        }
    1378        
     1309
    13791310        /*
    1380          * Caution: As the device manager is not a real loc
    1381          * driver (it uses a completely different IPC protocol
    1382          * than an ordinary loc driver), forwarding a connection
    1383          * from client to the devman by location service will
    1384          * not work.
     1311         * !!! devman_connection ... as the device manager is not a real loc
     1312         * driver (it uses a completely different ipc protocol than an ordinary
     1313         * loc driver) forwarding a connection from client to the devman by
     1314         * location service would not work.
    13851315         */
    1386         loc_server_register(NAME);
     1316        loc_server_register(NAME, devman_connection);
    13871317       
    13881318        return true;
     
    13911321int main(int argc, char *argv[])
    13921322{
    1393         printf("%s: HelenOS Device Manager\n", NAME);
    1394        
    1395         int rc = log_init(NAME, LVL_WARN);
    1396         if (rc != EOK) {
    1397                 printf("%s: Error initializing logging subsystem.\n", NAME);
    1398                 return rc;
     1323        printf(NAME ": HelenOS Device Manager\n");
     1324
     1325        if (log_init(NAME, LVL_WARN) != EOK) {
     1326                printf(NAME ": Error initializing logging subsystem.\n");
     1327                return -1;
     1328        }
     1329
     1330        if (!devman_init()) {
     1331                log_msg(LVL_ERROR, "Error while initializing service.");
     1332                return -1;
    13991333        }
    14001334       
     
    14031337        async_set_client_data_destructor(devman_client_data_destroy);
    14041338        async_set_client_connection(devman_connection);
    1405        
    1406         if (!devman_init()) {
    1407                 log_msg(LVL_ERROR, "Error while initializing service.");
     1339
     1340        /* Register device manager at naming service. */
     1341        if (service_register(SERVICE_DEVMAN) != EOK) {
     1342                log_msg(LVL_ERROR, "Failed registering as a service.");
    14081343                return -1;
    14091344        }
    1410        
    1411         /* Register device manager at naming service. */
    1412         rc = service_register(SERVICE_DEVMAN);
    1413         if (rc != EOK) {
    1414                 log_msg(LVL_ERROR, "Failed registering as a service.");
    1415                 return rc;
    1416         }
    1417        
    1418         printf("%s: Accepting connections.\n", NAME);
     1345
     1346        printf(NAME ": Accepting connections.\n");
    14191347        task_retval(0);
    14201348        async_manager();
    1421        
     1349
    14221350        /* Never reached. */
    14231351        return 0;
Note: See TracChangeset for help on using the changeset viewer.