Changeset 79ae36dd in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

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

    r764d71e r79ae36dd  
    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);
     
    559551        async_answer_0(iid, EOK);
    560552       
    561         bool cont = true;
    562         while (cont) {
     553        while (true) {
    563554                ipc_call_t call;
    564555                ipc_callid_t callid = async_get_call(&call);
    565556               
     557                if (!IPC_GET_IMETHOD(call))
     558                        break;
     559               
    566560                switch (IPC_GET_IMETHOD(call)) {
    567                 case IPC_M_PHONE_HUNGUP:
    568                         cont = false;
    569                         continue;
    570561                case DEVMAN_DEVICE_GET_HANDLE:
    571562                        devman_function_get_handle(callid, &call);
     
    635626        if (driver == NULL) {
    636627                log_msg(LVL_ERROR, "IPC forwarding refused - " \
    637                     "the device %" PRIun "(%s) is not in usable state.",
    638                     handle, dev->pfun->pathname);
     628                    "the device %" PRIun " is not in usable state.", handle);
    639629                async_answer_0(iid, ENOENT);
    640630                return;
     
    647637                method = DRIVER_CLIENT;
    648638       
    649         if (driver->phone < 0) {
    650                 log_msg(LVL_ERROR,
    651                     "Could not forward to driver `%s' (phone is %d).",
    652                     driver->name, (int) driver->phone);
     639        if (!driver->sess) {
     640                log_msg(LVL_ERROR,
     641                    "Could not forward to driver `%s'.", driver->name);
    653642                async_answer_0(iid, EINVAL);
    654643                return;
     
    664653                    dev->pfun->pathname, driver->name);
    665654        }
    666 
    667         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);
    668659}
    669660
     
    687678        dev = fun->dev;
    688679       
    689         if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     680        if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    690681                async_answer_0(iid, EINVAL);
    691682                return;
    692683        }
    693684       
    694         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,
    695687            IPC_FF_NONE);
    696         log_msg(LVL_DEBUG,
     688        async_exchange_end(exch);
     689       
     690        log_msg(LVL_DEBUG,
    697691            "Forwarding devmapper request for `%s' function to driver `%s'.",
    698692            fun->pathname, dev->drv->name);
     
    786780
    787781        printf(NAME ": Accepting connections.\n");
     782        task_retval(0);
    788783        async_manager();
    789784
Note: See TracChangeset for help on using the changeset viewer.