Changeset 41811af in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-06-10T10:14:26Z (14 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab547063
Parents:
9536e6e (diff), 390d80d (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 mainline

File:
1 edited

Legend:

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

    r9536e6e r41811af  
    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>
     
    108108        fibril_mutex_lock(&driver->driver_mutex);
    109109       
    110         if (driver->phone >= 0) {
     110        if (driver->sess) {
    111111                /* We already have a connection to the driver. */
    112112                log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     
    128128                break;
    129129        case DRIVER_RUNNING:
    130                 /* Should not happen since we do not have a connected phone */
     130                /* Should not happen since we do not have a connected session */
    131131                assert(false);
    132132        }
     
    135135        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
    136136            driver->name);
    137         ipc_call_t call;
    138         ipc_callid_t callid = async_get_call(&call);
    139         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     137        driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
     138        if (!driver->sess) {
    140139                fibril_mutex_unlock(&driver->driver_mutex);
    141                 async_answer_0(callid, ENOTSUP);
    142140                async_answer_0(iid, ENOTSUP);
    143141                return NULL;
    144142        }
    145143       
    146         /* Remember driver's phone. */
    147         driver->phone = IPC_GET_ARG5(call);
    148        
    149144        fibril_mutex_unlock(&driver->driver_mutex);
    150145       
    151         log_msg(LVL_NOTE, 
     146        log_msg(LVL_NOTE,
    152147            "The `%s' driver was successfully registered as running.",
    153148            driver->name);
    154149       
    155         async_answer_0(callid, EOK);
    156150        async_answer_0(iid, EOK);
    157151       
     
    434428        fibril_add_ready(fid);
    435429       
    436         ipc_callid_t callid;
    437         ipc_call_t call;
    438         bool cont = true;
    439         while (cont) {
    440                 callid = async_get_call(&call);
     430        while (true) {
     431                ipc_call_t call;
     432                ipc_callid_t callid = async_get_call(&call);
     433               
     434                if (!IPC_GET_IMETHOD(call))
     435                        break;
    441436               
    442437                switch (IPC_GET_IMETHOD(call)) {
    443                 case IPC_M_PHONE_HUNGUP:
    444                         cont = false;
    445                         continue;
    446438                case DEVMAN_ADD_FUNCTION:
    447439                        devman_add_function(callid, &call);
     
    515507}
    516508
     509/** Find device path by its handle. */
     510static void devman_get_device_path_by_handle(ipc_callid_t iid,
     511    ipc_call_t *icall)
     512{
     513        devman_handle_t handle = IPC_GET_ARG1(*icall);
     514
     515        fun_node_t *fun = find_fun_node(&device_tree, handle);
     516        if (fun == NULL) {
     517                async_answer_0(iid, ENOMEM);
     518                return;
     519        }
     520
     521        ipc_callid_t data_callid;
     522        size_t data_len;
     523        if (!async_data_read_receive(&data_callid, &data_len)) {
     524                async_answer_0(iid, EINVAL);
     525                return;
     526        }
     527
     528        void *buffer = malloc(data_len);
     529        if (buffer == NULL) {
     530                async_answer_0(data_callid, ENOMEM);
     531                async_answer_0(iid, ENOMEM);
     532                return;
     533        }
     534
     535        size_t sent_length = str_size(fun->pathname);
     536        if (sent_length > data_len) {
     537                sent_length = data_len;
     538        }
     539
     540        async_data_read_finalize(data_callid, fun->pathname, sent_length);
     541        async_answer_0(iid, EOK);
     542
     543        free(buffer);
     544}
     545
    517546
    518547/** Function for handling connections from a client to the device manager. */
     
    522551        async_answer_0(iid, EOK);
    523552       
    524         bool cont = true;
    525         while (cont) {
     553        while (true) {
    526554                ipc_call_t call;
    527555                ipc_callid_t callid = async_get_call(&call);
    528556               
     557                if (!IPC_GET_IMETHOD(call))
     558                        break;
     559               
    529560                switch (IPC_GET_IMETHOD(call)) {
    530                 case IPC_M_PHONE_HUNGUP:
    531                         cont = false;
    532                         continue;
    533561                case DEVMAN_DEVICE_GET_HANDLE:
    534562                        devman_function_get_handle(callid, &call);
     
    536564                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    537565                        devman_function_get_handle_by_class(callid, &call);
     566                        break;
     567                case DEVMAN_DEVICE_GET_DEVICE_PATH:
     568                        devman_get_device_path_by_handle(callid, &call);
    538569                        break;
    539570                default:
     
    606637                method = DRIVER_CLIENT;
    607638       
    608         if (driver->phone < 0) {
    609                 log_msg(LVL_ERROR,
    610                     "Could not forward to driver `%s' (phone is %d).",
    611                     driver->name, (int) driver->phone);
     639        if (!driver->sess) {
     640                log_msg(LVL_ERROR,
     641                    "Could not forward to driver `%s'.", driver->name);
    612642                async_answer_0(iid, EINVAL);
    613643                return;
     
    623653                    dev->pfun->pathname, driver->name);
    624654        }
    625 
    626         async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
     655       
     656        async_exch_t *exch = async_exchange_begin(driver->sess);
     657        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
     658        async_exchange_end(exch);
    627659}
    628660
     
    646678        dev = fun->dev;
    647679       
    648         if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     680        if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    649681                async_answer_0(iid, EINVAL);
    650682                return;
    651683        }
    652684       
    653         async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
     685        async_exch_t *exch = async_exchange_begin(dev->drv->sess);
     686        async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0,
    654687            IPC_FF_NONE);
    655         log_msg(LVL_DEBUG,
     688        async_exchange_end(exch);
     689       
     690        log_msg(LVL_DEBUG,
    656691            "Forwarding devmapper request for `%s' function to driver `%s'.",
    657692            fun->pathname, dev->drv->name);
     
    745780
    746781        printf(NAME ": Accepting connections.\n");
     782        task_retval(0);
    747783        async_manager();
    748784
Note: See TracChangeset for help on using the changeset viewer.