Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/net/modules.c

    rc7a8442 r64d2b10  
    3232
    3333/** @file
    34  * Generic module functions implementation. 
     34 * Generic module functions implementation.
    3535 *
    3636 * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS
     
    4141#include <async.h>
    4242#include <malloc.h>
    43 #include <err.h>
     43#include <errno.h>
    4444#include <sys/time.h>
    45 
    46 #include <ipc/ipc.h>
    4745#include <ipc/services.h>
    48 
    4946#include <net/modules.h>
    5047
     
    5249#define MODULE_WAIT_TIME        (10 * 1000)
    5350
    54 /** Answers the call.
    55  *
    56  * @param[in] callid    The call identifier.
    57  * @param[in] result    The message processing result.
    58  * @param[in] answer    The message processing answer.
    59  * @param[in] answer_count The number of answer parameters.
    60  */
    61 void
    62 answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,
    63     int answer_count)
    64 {
    65         // choose the most efficient answer function
    66         if (answer || (!answer_count)) {
    67                 switch (answer_count) {
     51/** Answer a call.
     52 *
     53 * @param[in] callid Call identifier.
     54 * @param[in] result Message processing result.
     55 * @param[in] answer Message processing answer.
     56 * @param[in] count  Number of answer parameters.
     57 *
     58 */
     59void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,
     60    size_t count)
     61{
     62        /* Choose the most efficient function */
     63        if ((answer != NULL) || (count == 0)) {
     64                switch (count) {
    6865                case 0:
    69                         ipc_answer_0(callid, (ipcarg_t) result);
     66                        async_answer_0(callid, (sysarg_t) result);
    7067                        break;
    7168                case 1:
    72                         ipc_answer_1(callid, (ipcarg_t) result,
     69                        async_answer_1(callid, (sysarg_t) result,
    7370                            IPC_GET_ARG1(*answer));
    7471                        break;
    7572                case 2:
    76                         ipc_answer_2(callid, (ipcarg_t) result,
     73                        async_answer_2(callid, (sysarg_t) result,
    7774                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
    7875                        break;
    7976                case 3:
    80                         ipc_answer_3(callid, (ipcarg_t) result,
     77                        async_answer_3(callid, (sysarg_t) result,
    8178                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    8279                            IPC_GET_ARG3(*answer));
    8380                        break;
    8481                case 4:
    85                         ipc_answer_4(callid, (ipcarg_t) result,
     82                        async_answer_4(callid, (sysarg_t) result,
    8683                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    8784                            IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
     
    8986                case 5:
    9087                default:
    91                         ipc_answer_5(callid, (ipcarg_t) result,
     88                        async_answer_5(callid, (sysarg_t) result,
    9289                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    9390                            IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer),
     
    111108 *                      function.
    112109 */
    113 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,
     110int bind_service(services_t need, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    114111    async_client_conn_t client_receiver)
    115112{
     
    134131 *
    135132 */
    136 int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2,
    137     ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
    138 {
    139         ERROR_DECLARE;
    140        
     133int bind_service_timeout(services_t need, sysarg_t arg1, sysarg_t arg2,
     134    sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     135{
    141136        /* Connect to the needed service */
    142137        int phone = connect_to_service_timeout(need, timeout);
    143138        if (phone >= 0) {
    144139                /* Request the bidirectional connection */
    145                 ipcarg_t phonehash;
    146                 if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
    147                     &phonehash))) {
    148                         ipc_hangup(phone);
    149                         return ERROR_CODE;
     140                int rc = async_connect_to_me(phone, arg1, arg2, arg3, client_receiver);
     141                if (rc != EOK) {
     142                        async_hangup(phone);
     143                        return rc;
    150144                }
    151                 async_new_connection(phonehash, 0, NULL, client_receiver);
    152145        }
    153146       
     
    158151 *
    159152 * @param[in] need      The needed module service.
    160  * @returns             The phone of the needed service.
     153 * @return              The phone of the needed service.
    161154 */
    162155int connect_to_service(services_t need)
     
    170163 *  @param[in] timeout  The connection timeout in microseconds. No timeout if
    171164 *                      set to zero (0).
    172  *  @returns            The phone of the needed service.
    173  *  @returns            ETIMEOUT if the connection timeouted.
     165 *  @return             The phone of the needed service.
     166 *  @return             ETIMEOUT if the connection timeouted.
    174167 */
    175168int connect_to_service_timeout(services_t need, suseconds_t timeout)
     
    177170        int phone;
    178171
    179         // if no timeout is set
     172        /* If no timeout is set */
    180173        if (timeout <= 0)
    181174                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
     
    186179                        return phone;
    187180
    188                 // end if no time is left
     181                /* Abort if no time is left */
    189182                if (timeout <= 0)
    190183                        return ETIMEOUT;
    191184
    192                 // wait the minimum of the module wait time and the timeout
     185                /* Wait the minimum of the module wait time and the timeout */
    193186                usleep((timeout <= MODULE_WAIT_TIME) ?
    194187                    timeout : MODULE_WAIT_TIME);
     
    197190}
    198191
    199 /** Receives data from the other party.
    200  *
    201  * The received data buffer is allocated and returned.
    202  *
    203  * @param[out] data     The data buffer to be filled.
    204  * @param[out] length   The buffer length.
    205  * @returns             EOK on success.
    206  * @returns             EBADMEM if the data or the length parameter is NULL.
    207  * @returns             EINVAL if the client does not send data.
    208  * @returns             ENOMEM if there is not enough memory left.
    209  * @returns             Other error codes as defined for the
    210  *                      async_data_write_finalize() function.
    211  */
    212 int data_receive(void **data, size_t *length)
    213 {
    214         ERROR_DECLARE;
    215 
    216         ipc_callid_t callid;
    217 
    218         if (!data || !length)
    219                 return EBADMEM;
    220 
    221         // fetch the request
    222         if (!async_data_write_receive(&callid, length))
    223                 return EINVAL;
    224 
    225         // allocate the buffer
    226         *data = malloc(*length);
    227         if (!*data)
    228                 return ENOMEM;
    229 
    230         // fetch the data
    231         if (ERROR_OCCURRED(async_data_write_finalize(callid, *data, *length))) {
    232                 free(data);
    233                 return ERROR_CODE;
    234         }
    235 
    236         return EOK;
    237 }
    238 
    239192/** Replies the data to the other party.
    240193 *
    241194 * @param[in] data      The data buffer to be sent.
    242195 * @param[in] data_length The buffer length.
    243  * @returns             EOK on success.
    244  * @returns             EINVAL if the client does not expect the data.
    245  * @returns             EOVERFLOW if the client does not expect all the data.
     196 * @return              EOK on success.
     197 * @return              EINVAL if the client does not expect the data.
     198 * @return              EOVERFLOW if the client does not expect all the data.
    246199 *                      Only partial data are transfered.
    247  * @returns             Other error codes as defined for the
     200 * @return              Other error codes as defined for the
    248201 *                      async_data_read_finalize() function.
    249202 */
     
    253206        ipc_callid_t callid;
    254207
    255         // fetch the request
     208        /* Fetch the request */
    256209        if (!async_data_read_receive(&callid, &length))
    257210                return EINVAL;
    258211
    259         // check the requested data size
     212        /* Check the requested data size */
    260213        if (length < data_length) {
    261214                async_data_read_finalize(callid, data, length);
     
    263216        }
    264217
    265         // send the data
     218        /* Send the data */
    266219        return async_data_read_finalize(callid, data, data_length);
    267220}
    268221
    269 /** Refreshes answer structure and parameters count.
    270  *
    271  * Erases all attributes.
    272  *
    273  * @param[in,out] answer The message processing answer structure.
    274  * @param[in,out] answer_count The number of answer parameters.
    275  */
    276 void refresh_answer(ipc_call_t *answer, int *answer_count)
    277 {
    278         if (answer_count)
    279                 *answer_count = 0;
    280 
    281         if (answer) {
     222/** Refresh answer structure and argument count.
     223 *
     224 * Erase all arguments.
     225 *
     226 * @param[in,out] answer Message processing answer structure.
     227 * @param[in,out] count  Number of answer arguments.
     228 *
     229 */
     230void refresh_answer(ipc_call_t *answer, size_t *count)
     231{
     232        if (count != NULL)
     233                *count = 0;
     234       
     235        if (answer != NULL) {
    282236                IPC_SET_RETVAL(*answer, 0);
    283                 // just to be precize
    284                 IPC_SET_METHOD(*answer, 0);
     237                IPC_SET_IMETHOD(*answer, 0);
    285238                IPC_SET_ARG1(*answer, 0);
    286239                IPC_SET_ARG2(*answer, 0);
Note: See TracChangeset for help on using the changeset viewer.