Changeset eb522e8 in mainline for uspace/lib/c/generic/net/modules.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/modules.c
r9e2e715 reb522e8 32 32 33 33 /** @file 34 * Generic module functions implementation. 34 * Generic module functions implementation. 35 35 * 36 36 * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS … … 43 43 #include <errno.h> 44 44 #include <sys/time.h> 45 46 #include <ipc/ipc.h>47 45 #include <ipc/services.h> 48 49 46 #include <net/modules.h> 50 47 … … 52 49 #define MODULE_WAIT_TIME (10 * 1000) 53 50 54 /** Answer s thecall.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 function66 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 */ 59 void 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) { 68 65 case 0: 69 ipc_answer_0(callid, (ipcarg_t) result);66 async_answer_0(callid, (sysarg_t) result); 70 67 break; 71 68 case 1: 72 ipc_answer_1(callid, (ipcarg_t) result,69 async_answer_1(callid, (sysarg_t) result, 73 70 IPC_GET_ARG1(*answer)); 74 71 break; 75 72 case 2: 76 ipc_answer_2(callid, (ipcarg_t) result,73 async_answer_2(callid, (sysarg_t) result, 77 74 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer)); 78 75 break; 79 76 case 3: 80 ipc_answer_3(callid, (ipcarg_t) result,77 async_answer_3(callid, (sysarg_t) result, 81 78 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 82 79 IPC_GET_ARG3(*answer)); 83 80 break; 84 81 case 4: 85 ipc_answer_4(callid, (ipcarg_t) result,82 async_answer_4(callid, (sysarg_t) result, 86 83 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 87 84 IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer)); … … 89 86 case 5: 90 87 default: 91 ipc_answer_5(callid, (ipcarg_t) result,88 async_answer_5(callid, (sysarg_t) result, 92 89 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 93 90 IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer), … … 111 108 * function. 112 109 */ 113 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,110 int bind_service(services_t need, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 114 111 async_client_conn_t client_receiver) 115 112 { … … 134 131 * 135 132 */ 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 int rc; 140 133 int 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 { 141 136 /* Connect to the needed service */ 142 137 int phone = connect_to_service_timeout(need, timeout); 143 138 if (phone >= 0) { 144 139 /* Request the bidirectional connection */ 145 ipcarg_t phonehash; 146 147 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash); 140 int rc = async_connect_to_me(phone, arg1, arg2, arg3, client_receiver); 148 141 if (rc != EOK) { 149 ipc_hangup(phone);142 async_hangup(phone); 150 143 return rc; 151 144 } 152 async_new_connection(phonehash, 0, NULL, client_receiver);153 145 } 154 146 … … 159 151 * 160 152 * @param[in] need The needed module service. 161 * @return sThe phone of the needed service.153 * @return The phone of the needed service. 162 154 */ 163 155 int connect_to_service(services_t need) … … 171 163 * @param[in] timeout The connection timeout in microseconds. No timeout if 172 164 * set to zero (0). 173 * @return sThe phone of the needed service.174 * @return sETIMEOUT if the connection timeouted.165 * @return The phone of the needed service. 166 * @return ETIMEOUT if the connection timeouted. 175 167 */ 176 168 int connect_to_service_timeout(services_t need, suseconds_t timeout) … … 178 170 int phone; 179 171 180 / / if no timeout is set172 /* If no timeout is set */ 181 173 if (timeout <= 0) 182 174 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0); … … 187 179 return phone; 188 180 189 / / end if no time is left181 /* Abort if no time is left */ 190 182 if (timeout <= 0) 191 183 return ETIMEOUT; 192 184 193 / / wait the minimum of the module wait time and the timeout185 /* Wait the minimum of the module wait time and the timeout */ 194 186 usleep((timeout <= MODULE_WAIT_TIME) ? 195 187 timeout : MODULE_WAIT_TIME); … … 198 190 } 199 191 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 * @returns EOK on success.207 * @returns EBADMEM if the data or the length parameter is NULL.208 * @returns EINVAL if the client does not send data.209 * @returns ENOMEM if there is not enough memory left.210 * @returns Other error codes as defined for the211 * 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 request222 if (!async_data_write_receive(&callid, length))223 return EINVAL;224 225 // allocate the buffer226 *data = malloc(*length);227 if (!*data)228 return ENOMEM;229 230 // fetch the data231 rc = async_data_write_finalize(callid, *data, *length);232 if (rc != EOK) {233 free(data);234 return rc;235 }236 237 return EOK;238 }239 240 192 /** Replies the data to the other party. 241 193 * 242 194 * @param[in] data The data buffer to be sent. 243 195 * @param[in] data_length The buffer length. 244 * @return sEOK on success.245 * @return sEINVAL if the client does not expect the data.246 * @return sEOVERFLOW 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. 247 199 * Only partial data are transfered. 248 * @return sOther error codes as defined for the200 * @return Other error codes as defined for the 249 201 * async_data_read_finalize() function. 250 202 */ … … 254 206 ipc_callid_t callid; 255 207 256 / / fetch the request208 /* Fetch the request */ 257 209 if (!async_data_read_receive(&callid, &length)) 258 210 return EINVAL; 259 211 260 / / check the requested data size212 /* Check the requested data size */ 261 213 if (length < data_length) { 262 214 async_data_read_finalize(callid, data, length); … … 264 216 } 265 217 266 / / send the data218 /* Send the data */ 267 219 return async_data_read_finalize(callid, data, data_length); 268 220 } 269 221 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) { 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 */ 230 void refresh_answer(ipc_call_t *answer, size_t *count) 231 { 232 if (count != NULL) 233 *count = 0; 234 235 if (answer != NULL) { 283 236 IPC_SET_RETVAL(*answer, 0); 284 // just to be precize 285 IPC_SET_METHOD(*answer, 0); 237 IPC_SET_IMETHOD(*answer, 0); 286 238 IPC_SET_ARG1(*answer, 0); 287 239 IPC_SET_ARG2(*answer, 0);
Note:
See TracChangeset
for help on using the changeset viewer.