Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    r79a141a r26fa82bc  
    285285        async_answer_0(iid, EOK);
    286286       
    287         while (true) {
     287        bool cont = true;
     288        while (cont) {
    288289                ipc_call_t call;
    289290                ipc_callid_t callid = async_get_call(&call);
    290291               
    291                 if (!IPC_GET_IMETHOD(call))
    292                         break;
    293                
    294292                switch (IPC_GET_IMETHOD(call)) {
     293                case IPC_M_PHONE_HUNGUP:
     294                        cont = false;
     295                        continue;
    295296                case DRIVER_ADD_DEVICE:
    296297                        driver_add_device(callid, &call);
     
    302303}
    303304
    304 /** Generic client connection handler both for applications and drivers.
    305  *
    306  * @param drv True for driver client, false for other clients
    307  *            (applications, services, etc.).
    308  *
     305/**
     306 * Generic client connection handler both for applications and drivers.
     307 *
     308 * @param drv           True for driver client, false for other clients
     309 *                      (applications, services etc.).
    309310 */
    310311static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
     
    316317        devman_handle_t handle = IPC_GET_ARG2(*icall);
    317318        ddf_fun_t *fun = driver_get_function(&functions, handle);
    318        
     319
    319320        if (fun == NULL) {
    320321                printf("%s: driver_connection_gen error - no function with handle"
     
    324325        }
    325326       
     327       
    326328        /*
    327329         * TODO - if the client is not a driver, check whether it is allowed to
     
    338340                return;
    339341       
    340         while (true) {
     342        while (1) {
    341343                ipc_callid_t callid;
    342344                ipc_call_t call;
    343345                callid = async_get_call(&call);
    344346                sysarg_t method = IPC_GET_IMETHOD(call);
     347                int iface_idx;
    345348               
    346                 if (!method) {
     349                switch  (method) {
     350                case IPC_M_PHONE_HUNGUP:
    347351                        /* Close device function */
    348352                        if (fun->ops != NULL && fun->ops->close != NULL)
     
    350354                        async_answer_0(callid, EOK);
    351355                        return;
    352                 }
    353                
    354                 /* Convert ipc interface id to interface index */
    355                
    356                 int iface_idx = DEV_IFACE_IDX(method);
    357                
    358                 if (!is_valid_iface_idx(iface_idx)) {
    359                         remote_handler_t *default_handler =
    360                             function_get_default_handler(fun);
    361                         if (default_handler != NULL) {
    362                                 (*default_handler)(fun, callid, &call);
    363                                 continue;
     356                default:
     357                        /* convert ipc interface id to interface index */
     358                       
     359                        iface_idx = DEV_IFACE_IDX(method);
     360                       
     361                        if (!is_valid_iface_idx(iface_idx)) {
     362                                remote_handler_t *default_handler =
     363                                    function_get_default_handler(fun);
     364                                if (default_handler != NULL) {
     365                                        (*default_handler)(fun, callid, &call);
     366                                        break;
     367                                }
     368                               
     369                                /*
     370                                 * Function has no such interface and
     371                                 * default handler is not provided.
     372                                 */
     373                                printf("%s: driver_connection_gen error - "
     374                                    "invalid interface id %d.",
     375                                    driver->name, iface_idx);
     376                                async_answer_0(callid, ENOTSUP);
     377                                break;
     378                        }
     379                       
     380                        /* calling one of the function's interfaces */
     381                       
     382                        /* Get the interface ops structure. */
     383                        void *ops = function_get_ops(fun, iface_idx);
     384                        if (ops == NULL) {
     385                                printf("%s: driver_connection_gen error - ",
     386                                    driver->name);
     387                                printf("Function with handle %" PRIun " has no interface "
     388                                    "with id %d.\n", handle, iface_idx);
     389                                async_answer_0(callid, ENOTSUP);
     390                                break;
    364391                        }
    365392                       
    366393                        /*
    367                          * Function has no such interface and
    368                          * default handler is not provided.
     394                         * Get the corresponding interface for remote request
     395                         * handling ("remote interface").
    369396                         */
    370                         printf("%s: driver_connection_gen error - "
    371                             "invalid interface id %d.",
    372                             driver->name, iface_idx);
    373                         async_answer_0(callid, ENOTSUP);
    374                         continue;
     397                        remote_iface_t *rem_iface = get_remote_iface(iface_idx);
     398                        assert(rem_iface != NULL);
     399                       
     400                        /* get the method of the remote interface */
     401                        sysarg_t iface_method_idx = IPC_GET_ARG1(call);
     402                        remote_iface_func_ptr_t iface_method_ptr =
     403                            get_remote_method(rem_iface, iface_method_idx);
     404                        if (iface_method_ptr == NULL) {
     405                                /* The interface has not such method */
     406                                printf("%s: driver_connection_gen error - "
     407                                    "invalid interface method.", driver->name);
     408                                async_answer_0(callid, ENOTSUP);
     409                                break;
     410                        }
     411                       
     412                        /*
     413                         * Call the remote interface's method, which will
     414                         * receive parameters from the remote client and it will
     415                         * pass it to the corresponding local interface method
     416                         * associated with the function by its driver.
     417                         */
     418                        (*iface_method_ptr)(fun, ops, callid, &call);
     419                        break;
    375420                }
    376                
    377                 /* Calling one of the function's interfaces */
    378                
    379                 /* Get the interface ops structure. */
    380                 void *ops = function_get_ops(fun, iface_idx);
    381                 if (ops == NULL) {
    382                         printf("%s: driver_connection_gen error - ", driver->name);
    383                         printf("Function with handle %" PRIun " has no interface "
    384                             "with id %d.\n", handle, iface_idx);
    385                         async_answer_0(callid, ENOTSUP);
    386                         continue;
    387                 }
    388                
    389                 /*
    390                  * Get the corresponding interface for remote request
    391                  * handling ("remote interface").
    392                  */
    393                 remote_iface_t *rem_iface = get_remote_iface(iface_idx);
    394                 assert(rem_iface != NULL);
    395                
    396                 /* get the method of the remote interface */
    397                 sysarg_t iface_method_idx = IPC_GET_ARG1(call);
    398                 remote_iface_func_ptr_t iface_method_ptr =
    399                     get_remote_method(rem_iface, iface_method_idx);
    400                 if (iface_method_ptr == NULL) {
    401                         /* The interface has not such method */
    402                         printf("%s: driver_connection_gen error - "
    403                             "invalid interface method.", driver->name);
    404                         async_answer_0(callid, ENOTSUP);
    405                         continue;
    406                 }
    407                
    408                 /*
    409                  * Call the remote interface's method, which will
    410                  * receive parameters from the remote client and it will
    411                  * pass it to the corresponding local interface method
    412                  * associated with the function by its driver.
    413                  */
    414                 (*iface_method_ptr)(fun, ops, callid, &call);
    415421        }
    416422}
Note: See TracChangeset for help on using the changeset viewer.