Changeset 357b5f5 in mainline for uspace/lib/c/generic/net/modules.c


Ignore:
Timestamp:
2011-01-23T20:09:13Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdb9982c
Parents:
cead2aa (diff), 7e36c8d (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 changes.

File:
1 edited

Legend:

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

    rcead2aa r357b5f5  
    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
     
    5252#define MODULE_WAIT_TIME        (10 * 1000)
    5353
    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) {
     54/** Answer a call.
     55 *
     56 * @param[in] callid Call identifier.
     57 * @param[in] result Message processing result.
     58 * @param[in] answer Message processing answer.
     59 * @param[in] count  Number of answer parameters.
     60 *
     61 */
     62void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,
     63    size_t count)
     64{
     65        /* Choose the most efficient function */
     66        if ((answer != NULL) || (count == 0)) {
     67                switch (count) {
    6868                case 0:
    69                         ipc_answer_0(callid, (ipcarg_t) result);
     69                        ipc_answer_0(callid, (sysarg_t) result);
    7070                        break;
    7171                case 1:
    72                         ipc_answer_1(callid, (ipcarg_t) result,
     72                        ipc_answer_1(callid, (sysarg_t) result,
    7373                            IPC_GET_ARG1(*answer));
    7474                        break;
    7575                case 2:
    76                         ipc_answer_2(callid, (ipcarg_t) result,
     76                        ipc_answer_2(callid, (sysarg_t) result,
    7777                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
    7878                        break;
    7979                case 3:
    80                         ipc_answer_3(callid, (ipcarg_t) result,
     80                        ipc_answer_3(callid, (sysarg_t) result,
    8181                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    8282                            IPC_GET_ARG3(*answer));
    8383                        break;
    8484                case 4:
    85                         ipc_answer_4(callid, (ipcarg_t) result,
     85                        ipc_answer_4(callid, (sysarg_t) result,
    8686                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    8787                            IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
     
    8989                case 5:
    9090                default:
    91                         ipc_answer_5(callid, (ipcarg_t) result,
     91                        ipc_answer_5(callid, (sysarg_t) result,
    9292                            IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
    9393                            IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer),
     
    111111 *                      function.
    112112 */
    113 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,
     113int bind_service(services_t need, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    114114    async_client_conn_t client_receiver)
    115115{
     
    134134 *
    135135 */
    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)
     136int bind_service_timeout(services_t need, sysarg_t arg1, sysarg_t arg2,
     137    sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
    138138{
    139139        int rc;
     
    143143        if (phone >= 0) {
    144144                /* Request the bidirectional connection */
    145                 ipcarg_t phonehash;
     145                sysarg_t phonehash;
    146146               
    147147                rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash);
     
    178178        int phone;
    179179
    180         // if no timeout is set
     180        /* If no timeout is set */
    181181        if (timeout <= 0)
    182182                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
     
    187187                        return phone;
    188188
    189                 // end if no time is left
     189                /* Abort if no time is left */
    190190                if (timeout <= 0)
    191191                        return ETIMEOUT;
    192192
    193                 // wait the minimum of the module wait time and the timeout
     193                /* Wait the minimum of the module wait time and the timeout */
    194194                usleep((timeout <= MODULE_WAIT_TIME) ?
    195195                    timeout : MODULE_WAIT_TIME);
    196196                timeout -= MODULE_WAIT_TIME;
    197197        }
    198 }
    199 
    200 /** Receives data from the other party.
    201  *
    202  * The received data buffer is allocated and returned.
    203  *
    204  * @param[out] data     The data buffer to be filled.
    205  * @param[out] length   The buffer length.
    206  * @return              EOK on success.
    207  * @return              EBADMEM if the data or the length parameter is NULL.
    208  * @return              EINVAL if the client does not send data.
    209  * @return              ENOMEM if there is not enough memory left.
    210  * @return              Other error codes as defined for the
    211  *                      async_data_write_finalize() function.
    212  */
    213 int data_receive(void **data, size_t *length)
    214 {
    215         ipc_callid_t callid;
    216         int rc;
    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         rc = async_data_write_finalize(callid, *data, *length);
    232         if (rc != EOK) {
    233                 free(data);
    234                 return rc;
    235         }
    236 
    237         return EOK;
    238198}
    239199
     
    254214        ipc_callid_t callid;
    255215
    256         // fetch the request
     216        /* Fetch the request */
    257217        if (!async_data_read_receive(&callid, &length))
    258218                return EINVAL;
    259219
    260         // check the requested data size
     220        /* Check the requested data size */
    261221        if (length < data_length) {
    262222                async_data_read_finalize(callid, data, length);
     
    264224        }
    265225
    266         // send the data
     226        /* Send the data */
    267227        return async_data_read_finalize(callid, data, data_length);
    268228}
    269229
    270 /** Refreshes answer structure and parameters count.
    271  *
    272  * Erases all attributes.
    273  *
    274  * @param[in,out] answer The message processing answer structure.
    275  * @param[in,out] answer_count The number of answer parameters.
    276  */
    277 void refresh_answer(ipc_call_t *answer, int *answer_count)
    278 {
    279         if (answer_count)
    280                 *answer_count = 0;
    281 
    282         if (answer) {
     230/** Refresh answer structure and argument count.
     231 *
     232 * Erase all arguments.
     233 *
     234 * @param[in,out] answer Message processing answer structure.
     235 * @param[in,out] count  Number of answer arguments.
     236 *
     237 */
     238void refresh_answer(ipc_call_t *answer, size_t *count)
     239{
     240        if (count != NULL)
     241                *count = 0;
     242       
     243        if (answer != NULL) {
    283244                IPC_SET_RETVAL(*answer, 0);
    284                 // just to be precize
    285                 IPC_SET_METHOD(*answer, 0);
     245                IPC_SET_IMETHOD(*answer, 0);
    286246                IPC_SET_ARG1(*answer, 0);
    287247                IPC_SET_ARG2(*answer, 0);
Note: See TracChangeset for help on using the changeset viewer.