Ignore:
File:
1 edited

Legend:

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

    rb927375 r7beb220  
    3939#include <assert.h>
    4040#include <ipc/services.h>
    41 #include <ipc/ns.h>
     41#include <ns.h>
    4242#include <async.h>
    4343#include <stdio.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <bool.h>
    4647#include <fibril_synch.h>
     
    5152#include <sys/stat.h>
    5253#include <ctype.h>
     54#include <io/log.h>
    5355#include <ipc/devman.h>
    5456#include <ipc/driver.h>
    5557#include <thread.h>
    56 #include <devmap.h>
     58#include <loc.h>
    5759
    5860#include "devman.h"
     
    6264static driver_list_t drivers_list;
    6365static dev_tree_t device_tree;
    64 static class_list_t class_list;
    6566
    6667/** Register running driver. */
     
    7172        driver_t *driver = NULL;
    7273
    73         printf(NAME ": devman_driver_register \n");
     74        log_msg(LVL_DEBUG, "devman_driver_register");
    7475       
    7576        iid = async_get_call(&icall);
     
    8889        }
    8990
    90         printf(NAME ": the %s driver is trying to register by the service.\n",
     91        log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
    9192            drv_name);
    9293       
    9394        /* Find driver structure. */
    9495        driver = find_driver(&drivers_list, drv_name);
    95        
    9696        if (driver == NULL) {
    97                 printf(NAME ": no driver named %s was found.\n", drv_name);
     97                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
    9898                free(drv_name);
    9999                drv_name = NULL;
     
    105105        drv_name = NULL;
    106106       
     107        fibril_mutex_lock(&driver->driver_mutex);
     108       
     109        if (driver->sess) {
     110                /* We already have a connection to the driver. */
     111                log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     112                    driver->name);
     113                fibril_mutex_unlock(&driver->driver_mutex);
     114                async_answer_0(iid, EEXISTS);
     115                return NULL;
     116        }
     117       
     118        switch (driver->state) {
     119        case DRIVER_NOT_STARTED:
     120                /* Somebody started the driver manually. */
     121                log_msg(LVL_NOTE, "Driver '%s' started manually.\n",
     122                    driver->name);
     123                driver->state = DRIVER_STARTING;
     124                break;
     125        case DRIVER_STARTING:
     126                /* The expected case */
     127                break;
     128        case DRIVER_RUNNING:
     129                /* Should not happen since we do not have a connected session */
     130                assert(false);
     131        }
     132       
    107133        /* Create connection to the driver. */
    108         printf(NAME ":  creating connection to the %s driver.\n", driver->name);
    109         ipc_call_t call;
    110         ipc_callid_t callid = async_get_call(&call);
    111         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    112                 async_answer_0(callid, ENOTSUP);
     134        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     135            driver->name);
     136        driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
     137        if (!driver->sess) {
     138                fibril_mutex_unlock(&driver->driver_mutex);
    113139                async_answer_0(iid, ENOTSUP);
    114140                return NULL;
    115141        }
    116142       
    117         /* Remember driver's phone. */
    118         set_driver_phone(driver, IPC_GET_ARG5(call));
    119        
    120         printf(NAME ": the %s driver was successfully registered as running.\n",
     143        fibril_mutex_unlock(&driver->driver_mutex);
     144       
     145        log_msg(LVL_NOTE,
     146            "The `%s' driver was successfully registered as running.",
    121147            driver->name);
    122148       
    123         async_answer_0(callid, EOK);
    124149        async_answer_0(iid, EOK);
    125150       
     
    142167        callid = async_get_call(&call);
    143168        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    144                 printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145                     "protocol.\n");
     169                log_msg(LVL_ERROR,
     170                    "Invalid protocol when trying to receive match id.");
    146171                async_answer_0(callid, EINVAL);
    147172                delete_match_id(match_id);
     
    150175       
    151176        if (match_id == NULL) {
    152                 printf(NAME ": ERROR: devman_receive_match_id - failed to "
    153                     "allocate match id.\n");
     177                log_msg(LVL_ERROR, "Failed to allocate match id.");
    154178                async_answer_0(callid, ENOMEM);
    155179                return ENOMEM;
     
    165189        if (rc != EOK) {
    166190                delete_match_id(match_id);
    167                 printf(NAME ": devman_receive_match_id - failed to receive "
    168                     "match id string.\n");
     191                log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
     192                    str_error(rc));
    169193                return rc;
    170194        }
     
    172196        list_append(&match_id->link, &match_ids->ids);
    173197       
    174         printf(NAME ": received match id '%s', score = %d \n",
     198        log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
    175199            match_id->id, match_id->score);
    176200        return rc;
     
    228252        if (ftype != fun_inner && ftype != fun_exposed) {
    229253                /* Unknown function type */
    230                 printf(NAME ": Error, unknown function type provided by driver!\n");
     254                log_msg(LVL_ERROR,
     255                    "Unknown function type %d provided by driver.",
     256                    (int) ftype);
    231257
    232258                fibril_rwlock_write_unlock(&tree->rwlock);
     
    243269        }
    244270       
     271        /* Check that function with same name is not there already. */
     272        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
     273                fibril_rwlock_write_unlock(&tree->rwlock);
     274                async_answer_0(callid, EEXISTS);
     275                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     276                    fun_name);
     277                free(fun_name);
     278                return;
     279        }
     280       
    245281        fun_node_t *fun = create_fun_node();
     282        fun->ftype = ftype;
     283       
    246284        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    247285                fibril_rwlock_write_unlock(&tree->rwlock);
     
    265303        fibril_rwlock_write_unlock(&tree->rwlock);
    266304       
    267         printf(NAME ": devman_add_function %s\n", fun->pathname);
     305        log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    268306       
    269307        devman_receive_match_ids(match_count, &fun->match_ids);
     
    289327                }
    290328        } else {
    291                 devmap_register_tree_function(fun, tree);
     329                loc_register_tree_function(fun, tree);
    292330        }
    293331       
     
    296334}
    297335
    298 static void devmap_register_class_dev(dev_class_info_t *cli)
    299 {
    300         /* Create devmap path and name for the device. */
    301         char *devmap_pathname = NULL;
    302 
    303         asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    304             cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    305         if (devmap_pathname == NULL)
    306                 return;
    307        
    308         /*
    309          * Register the device by the device mapper and remember its devmap
    310          * handle.
    311          */
    312         devmap_device_register_with_iface(devmap_pathname,
    313             &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    314        
    315         /*
    316          * Add device to the hash map of class devices registered by device
    317          * mapper.
    318          */
    319         class_add_devmap_function(&class_list, cli);
    320        
    321         free(devmap_pathname);
    322 }
    323 
    324 static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
     336static void devman_add_function_to_cat(ipc_callid_t callid, ipc_call_t *call)
    325337{
    326338        devman_handle_t handle = IPC_GET_ARG1(*call);
    327        
    328         /* Get class name. */
    329         char *class_name;
    330         int rc = async_data_write_accept((void **) &class_name, true,
     339        category_id_t cat_id;
     340        int rc;
     341       
     342        /* Get category name. */
     343        char *cat_name;
     344        rc = async_data_write_accept((void **) &cat_name, true,
    331345            0, 0, 0, 0);
    332346        if (rc != EOK) {
     
    341355        }
    342356       
    343         dev_class_t *cl = get_dev_class(&class_list, class_name);
    344         dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    345        
    346         /* Register the device's class alias by devmapper. */
    347         devmap_register_class_dev(class_info);
    348        
    349         printf(NAME ": function'%s' added to class '%s', class name '%s' was "
    350             "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
    351 
     357        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
     358        if (rc == EOK) {
     359                loc_service_add_to_cat(fun->service_id, cat_id);
     360        } else {
     361                log_msg(LVL_ERROR, "Failed adding function `%s' to category "
     362                    "`%s'.", fun->pathname, cat_name);
     363        }
     364       
     365        log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
     366            fun->pathname, cat_name);
     367
     368        async_answer_0(callid, EOK);
     369}
     370
     371/** Remove function. */
     372static void devman_remove_function(ipc_callid_t callid, ipc_call_t *call)
     373{
     374        devman_handle_t fun_handle = IPC_GET_ARG1(*call);
     375        dev_tree_t *tree = &device_tree;
     376        int rc;
     377       
     378        fibril_rwlock_write_lock(&tree->rwlock);
     379       
     380        fun_node_t *fun = find_fun_node_no_lock(&device_tree, fun_handle);
     381        if (fun == NULL) {
     382                fibril_rwlock_write_unlock(&tree->rwlock);
     383                async_answer_0(callid, ENOENT);
     384                return;
     385        }
     386       
     387        log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
     388       
     389        if (fun->ftype == fun_inner) {
     390                /* Handle possible descendants */
     391                /* TODO */
     392                log_msg(LVL_WARN, "devman_remove_function(): not handling "
     393                    "descendants\n");
     394        } else {
     395                /* Unregister from location service */
     396                rc = loc_service_unregister(fun->service_id);
     397                if (rc != EOK) {
     398                        log_msg(LVL_ERROR, "Failed unregistering tree service.");
     399                        fibril_rwlock_write_unlock(&tree->rwlock);
     400                        async_answer_0(callid, EIO);
     401                        return;
     402                }
     403        }
     404       
     405        remove_fun_node(&device_tree, fun);
     406        fibril_rwlock_write_unlock(&tree->rwlock);
     407        delete_fun_node(fun);
     408       
     409        log_msg(LVL_DEBUG, "devman_remove_function() succeeded.");
    352410        async_answer_0(callid, EOK);
    353411}
     
    363421       
    364422        initialize_running_driver(driver, &device_tree);
    365         printf(NAME ": the %s driver was successfully initialized. \n",
     423        log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
    366424            driver->name);
    367425        return 0;
     
    385443        fid_t fid = fibril_create(init_running_drv, driver);
    386444        if (fid == 0) {
    387                 printf(NAME ": Error creating fibril for the initialization of "
    388                     "the newly registered running driver.\n");
     445                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     446                    "for driver `%s'.", driver->name);
    389447                return;
    390448        }
    391449        fibril_add_ready(fid);
    392450       
    393         ipc_callid_t callid;
    394         ipc_call_t call;
    395         bool cont = true;
    396         while (cont) {
    397                 callid = async_get_call(&call);
     451        while (true) {
     452                ipc_call_t call;
     453                ipc_callid_t callid = async_get_call(&call);
     454               
     455                if (!IPC_GET_IMETHOD(call))
     456                        break;
    398457               
    399458                switch (IPC_GET_IMETHOD(call)) {
    400                 case IPC_M_PHONE_HUNGUP:
    401                         cont = false;
    402                         continue;
    403459                case DEVMAN_ADD_FUNCTION:
    404460                        devman_add_function(callid, &call);
    405461                        break;
    406                 case DEVMAN_ADD_DEVICE_TO_CLASS:
    407                         devman_add_function_to_class(callid, &call);
     462                case DEVMAN_ADD_DEVICE_TO_CATEGORY:
     463                        devman_add_function_to_cat(callid, &call);
     464                        break;
     465                case DEVMAN_REMOVE_FUNCTION:
     466                        devman_remove_function(callid, &call);
    408467                        break;
    409468                default:
     
    438497}
    439498
     499/** Get device name. */
     500static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall)
     501{
     502        devman_handle_t handle = IPC_GET_ARG1(*icall);
     503
     504        fun_node_t *fun = find_fun_node(&device_tree, handle);
     505        if (fun == NULL) {
     506                async_answer_0(iid, ENOMEM);
     507                return;
     508        }
     509
     510        ipc_callid_t data_callid;
     511        size_t data_len;
     512        if (!async_data_read_receive(&data_callid, &data_len)) {
     513                async_answer_0(iid, EINVAL);
     514                return;
     515        }
     516
     517        void *buffer = malloc(data_len);
     518        if (buffer == NULL) {
     519                async_answer_0(data_callid, ENOMEM);
     520                async_answer_0(iid, ENOMEM);
     521                return;
     522        }
     523
     524        size_t sent_length = str_size(fun->name);
     525        if (sent_length > data_len) {
     526                sent_length = data_len;
     527        }
     528
     529        async_data_read_finalize(data_callid, fun->name, sent_length);
     530        async_answer_0(iid, EOK);
     531
     532        free(buffer);
     533}
     534
     535
     536/** Get device path. */
     537static void devman_fun_get_path(ipc_callid_t iid, ipc_call_t *icall)
     538{
     539        devman_handle_t handle = IPC_GET_ARG1(*icall);
     540
     541        fun_node_t *fun = find_fun_node(&device_tree, handle);
     542        if (fun == NULL) {
     543                async_answer_0(iid, ENOMEM);
     544                return;
     545        }
     546
     547        ipc_callid_t data_callid;
     548        size_t data_len;
     549        if (!async_data_read_receive(&data_callid, &data_len)) {
     550                async_answer_0(iid, EINVAL);
     551                return;
     552        }
     553
     554        void *buffer = malloc(data_len);
     555        if (buffer == NULL) {
     556                async_answer_0(data_callid, ENOMEM);
     557                async_answer_0(iid, ENOMEM);
     558                return;
     559        }
     560
     561        size_t sent_length = str_size(fun->pathname);
     562        if (sent_length > data_len) {
     563                sent_length = data_len;
     564        }
     565
     566        async_data_read_finalize(data_callid, fun->pathname, sent_length);
     567        async_answer_0(iid, EOK);
     568
     569        free(buffer);
     570}
     571
     572static void devman_dev_get_functions(ipc_callid_t iid, ipc_call_t *icall)
     573{
     574        ipc_callid_t callid;
     575        size_t size;
     576        size_t act_size;
     577        int rc;
     578       
     579        if (!async_data_read_receive(&callid, &size)) {
     580                async_answer_0(callid, EREFUSED);
     581                async_answer_0(iid, EREFUSED);
     582                return;
     583        }
     584       
     585        fibril_rwlock_read_lock(&device_tree.rwlock);
     586       
     587        dev_node_t *dev = find_dev_node_no_lock(&device_tree,
     588            IPC_GET_ARG1(*icall));
     589        if (dev == NULL) {
     590                fibril_rwlock_read_unlock(&device_tree.rwlock);
     591                async_answer_0(callid, ENOENT);
     592                async_answer_0(iid, ENOENT);
     593                return;
     594        }
     595       
     596        devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size);
     597        if (hdl_buf == NULL) {
     598                fibril_rwlock_read_unlock(&device_tree.rwlock);
     599                async_answer_0(callid, ENOMEM);
     600                async_answer_0(iid, ENOMEM);
     601                return;
     602        }
     603       
     604        rc = dev_get_functions(&device_tree, dev, hdl_buf, size, &act_size);
     605        if (rc != EOK) {
     606                fibril_rwlock_read_unlock(&device_tree.rwlock);
     607                async_answer_0(callid, rc);
     608                async_answer_0(iid, rc);
     609                return;
     610        }
     611       
     612        fibril_rwlock_read_unlock(&device_tree.rwlock);
     613       
     614        sysarg_t retval = async_data_read_finalize(callid, hdl_buf, size);
     615        free(hdl_buf);
     616       
     617        async_answer_1(iid, retval, act_size);
     618}
     619
     620
     621/** Get handle for child device of a function. */
     622static void devman_fun_get_child(ipc_callid_t iid, ipc_call_t *icall)
     623{
     624        fun_node_t *fun;
     625       
     626        fibril_rwlock_read_lock(&device_tree.rwlock);
     627       
     628        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
     629        if (fun == NULL) {
     630                fibril_rwlock_read_unlock(&device_tree.rwlock);
     631                async_answer_0(iid, ENOENT);
     632                return;
     633        }
     634       
     635        if (fun->child == NULL) {
     636                fibril_rwlock_read_unlock(&device_tree.rwlock);
     637                async_answer_0(iid, ENOENT);
     638                return;
     639        }
     640       
     641        async_answer_1(iid, EOK, fun->child->handle);
     642       
     643        fibril_rwlock_read_unlock(&device_tree.rwlock);
     644}
     645
     646/** Find handle for the function instance identified by its service ID. */
     647static void devman_fun_sid_to_handle(ipc_callid_t iid, ipc_call_t *icall)
     648{
     649        fun_node_t *fun;
     650
     651        fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall));
     652       
     653        if (fun == NULL) {
     654                async_answer_0(iid, ENOENT);
     655                return;
     656        }
     657
     658        async_answer_1(iid, EOK, fun->handle);
     659}
    440660
    441661/** Function for handling connections from a client to the device manager. */
     
    445665        async_answer_0(iid, EOK);
    446666       
    447         bool cont = true;
    448         while (cont) {
     667        while (true) {
    449668                ipc_call_t call;
    450669                ipc_callid_t callid = async_get_call(&call);
    451670               
     671                if (!IPC_GET_IMETHOD(call))
     672                        break;
     673               
    452674                switch (IPC_GET_IMETHOD(call)) {
    453                 case IPC_M_PHONE_HUNGUP:
    454                         cont = false;
    455                         continue;
    456675                case DEVMAN_DEVICE_GET_HANDLE:
    457676                        devman_function_get_handle(callid, &call);
     677                        break;
     678                case DEVMAN_DEV_GET_FUNCTIONS:
     679                        devman_dev_get_functions(callid, &call);
     680                        break;
     681                case DEVMAN_FUN_GET_CHILD:
     682                        devman_fun_get_child(callid, &call);
     683                        break;
     684                case DEVMAN_FUN_GET_NAME:
     685                        devman_fun_get_name(callid, &call);
     686                        break;
     687                case DEVMAN_FUN_GET_PATH:
     688                        devman_fun_get_path(callid, &call);
     689                        break;
     690                case DEVMAN_FUN_SID_TO_HANDLE:
     691                        devman_fun_sid_to_handle(callid, &call);
    458692                        break;
    459693                default:
     
    477711                dev = fun->dev;
    478712
    479         if (fun == NULL && dev == NULL) {
    480                 printf(NAME ": devman_forward error - no device or function with "
    481                     "handle %" PRIun " was found.\n", handle);
     713        /*
     714         * For a valid function to connect to we need a device. The root
     715         * function, for example, has no device and cannot be connected to.
     716         * This means @c dev needs to be valid regardless whether we are
     717         * connecting to a device or to a function.
     718         */
     719        if (dev == NULL) {
     720                log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
     721                    "function with handle %" PRIun " was found.", handle);
    482722                async_answer_0(iid, ENOENT);
    483723                return;
     
    485725
    486726        if (fun == NULL && !drv_to_parent) {
    487                 printf(NAME ": devman_forward error - cannot connect to "
    488                     "handle %" PRIun ", refers to a device.\n", handle);
     727                log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
     728                    "connect to handle %" PRIun ", refers to a device.",
     729                    handle);
    489730                async_answer_0(iid, ENOENT);
    490731                return;
     
    507748       
    508749        if (driver == NULL) {
    509                 printf(NAME ": devman_forward error - the device is not in %" PRIun
    510                     " usable state.\n", handle);
     750                log_msg(LVL_ERROR, "IPC forwarding refused - " \
     751                    "the device %" PRIun " is not in usable state.", handle);
    511752                async_answer_0(iid, ENOENT);
    512753                return;
     
    519760                method = DRIVER_CLIENT;
    520761       
    521         if (driver->phone <= 0) {
    522                 printf(NAME ": devman_forward: cound not forward to driver %s ",
    523                     driver->name);
    524                 printf("the driver's phone is %" PRIun ").\n", driver->phone);
     762        if (!driver->sess) {
     763                log_msg(LVL_ERROR,
     764                    "Could not forward to driver `%s'.", driver->name);
    525765                async_answer_0(iid, EINVAL);
    526766                return;
     
    528768
    529769        if (fun != NULL) {
    530                 printf(NAME ": devman_forward: forward connection to function %s to "
    531                     "driver %s.\n", fun->pathname, driver->name);
     770                log_msg(LVL_DEBUG,
     771                    "Forwarding request for `%s' function to driver `%s'.",
     772                    fun->pathname, driver->name);
    532773        } else {
    533                 printf(NAME ": devman_forward: forward connection to device %s to "
    534                     "driver %s.\n", dev->pfun->pathname, driver->name);
    535         }
    536 
    537         async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
    538 }
    539 
    540 /** Function for handling connections from a client forwarded by the device
    541  * mapper to the device manager. */
    542 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    543 {
    544         devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
     774                log_msg(LVL_DEBUG,
     775                    "Forwarding request for `%s' device to driver `%s'.",
     776                    dev->pfun->pathname, driver->name);
     777        }
     778       
     779        async_exch_t *exch = async_exchange_begin(driver->sess);
     780        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
     781        async_exchange_end(exch);
     782}
     783
     784/** Function for handling connections from a client forwarded by the location
     785 * service to the device manager. */
     786static void devman_connection_loc(ipc_callid_t iid, ipc_call_t *icall)
     787{
     788        service_id_t service_id = IPC_GET_ARG2(*icall);
    545789        fun_node_t *fun;
    546790        dev_node_t *dev;
    547791
    548         fun = find_devmap_tree_function(&device_tree, devmap_handle);
    549         if (fun == NULL)
    550                 fun = find_devmap_class_function(&class_list, devmap_handle);
     792        fun = find_loc_tree_function(&device_tree, service_id);
    551793       
    552794        if (fun == NULL || fun->dev->drv == NULL) {
     795                log_msg(LVL_WARN, "devman_connection_loc(): function "
     796                    "not found.\n");
    553797                async_answer_0(iid, ENOENT);
    554798                return;
     
    557801        dev = fun->dev;
    558802       
    559         if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    560                 async_answer_0(iid, EINVAL);
    561                 return;
    562         }
    563        
    564         async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
     803        async_exch_t *exch = async_exchange_begin(dev->drv->sess);
     804        async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0,
    565805            IPC_FF_NONE);
    566         printf(NAME ": devman_connection_devmapper: forwarded connection to "
    567             "device %s to driver %s.\n", fun->pathname, dev->drv->name);
     806        async_exchange_end(exch);
     807       
     808        log_msg(LVL_DEBUG,
     809            "Forwarding loc service request for `%s' function to driver `%s'.",
     810            fun->pathname, dev->drv->name);
    568811}
    569812
    570813/** Function for handling connections to device manager. */
    571 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
     814static void devman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    572815{
    573816        /* Select interface. */
     
    583826                devman_forward(iid, icall, false);
    584827                break;
    585         case DEVMAN_CONNECT_FROM_DEVMAP:
    586                 /* Someone connected through devmap node. */
    587                 devman_connection_devmapper(iid, icall);
     828        case DEVMAN_CONNECT_FROM_LOC:
     829                /* Someone connected through loc node. */
     830                devman_connection_loc(iid, icall);
    588831                break;
    589832        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
     
    600843static bool devman_init(void)
    601844{
    602         printf(NAME ": devman_init - looking for available drivers.\n");
     845        log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
    603846       
    604847        /* Initialize list of available drivers. */
     
    606849        if (lookup_available_drivers(&drivers_list,
    607850            DRIVER_DEFAULT_STORE) == 0) {
    608                 printf(NAME " no drivers found.");
     851                log_msg(LVL_FATAL, "No drivers found.");
    609852                return false;
    610853        }
    611854
    612         printf(NAME ": devman_init  - list of drivers has been initialized.\n");
     855        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    613856
    614857        /* Create root device node. */
    615858        if (!init_device_tree(&device_tree, &drivers_list)) {
    616                 printf(NAME " failed to initialize device tree.");
     859                log_msg(LVL_FATAL, "Failed to initialize device tree.");
    617860                return false;
    618861        }
    619862
    620         init_class_list(&class_list);
    621        
    622863        /*
    623          * !!! devman_connection ... as the device manager is not a real devmap
     864         * !!! devman_connection ... as the device manager is not a real loc
    624865         * driver (it uses a completely different ipc protocol than an ordinary
    625          * devmap driver) forwarding a connection from client to the devman by
    626          * devmapper would not work.
     866         * loc driver) forwarding a connection from client to the devman by
     867         * location service would not work.
    627868         */
    628         devmap_driver_register(NAME, devman_connection);
     869        loc_server_register(NAME, devman_connection);
    629870       
    630871        return true;
     
    635876        printf(NAME ": HelenOS Device Manager\n");
    636877
     878        if (log_init(NAME, LVL_WARN) != EOK) {
     879                printf(NAME ": Error initializing logging subsystem.\n");
     880                return -1;
     881        }
     882
    637883        if (!devman_init()) {
    638                 printf(NAME ": Error while initializing service\n");
     884                log_msg(LVL_ERROR, "Error while initializing service.");
    639885                return -1;
    640886        }
     
    644890
    645891        /* Register device manager at naming service. */
    646         if (service_register(SERVICE_DEVMAN) != EOK)
     892        if (service_register(SERVICE_DEVMAN) != EOK) {
     893                log_msg(LVL_ERROR, "Failed registering as a service.");
    647894                return -1;
    648 
    649         printf(NAME ": Accepting connections\n");
     895        }
     896
     897        printf(NAME ": Accepting connections.\n");
     898        task_retval(0);
    650899        async_manager();
    651900
Note: See TracChangeset for help on using the changeset viewer.