source: mainline/uspace/lib/c/generic/async_obsolete.c@ 58cbf8d5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 58cbf8d5 was b76a7329, checked in by Martin Decky <martin@…>, 14 years ago

make async_sess_t and async_exch_t structures private
(to avoid any possible temptation to access their members directly)

  • Property mode set to 100644
File size: 13.4 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#define LIBC_ASYNC_C_
36#define LIBC_ASYNC_OBSOLETE_C_
37#include <ipc/ipc.h>
38#include <async.h>
39#include <async_obsolete.h>
40#include "private/async.h"
41#undef LIBC_ASYNC_C_
42#undef LIBC_ASYNC_OBSOLETE_C_
43
44#include <fibril.h>
45#include <malloc.h>
46#include <errno.h>
47
48/** Send message and return id of the sent message.
49 *
50 * The return value can be used as input for async_wait() to wait for
51 * completion.
52 *
53 * @param phoneid Handle of the phone that will be used for the send.
54 * @param method Service-defined method.
55 * @param arg1 Service-defined payload argument.
56 * @param arg2 Service-defined payload argument.
57 * @param arg3 Service-defined payload argument.
58 * @param arg4 Service-defined payload argument.
59 * @param dataptr If non-NULL, storage where the reply data will be
60 * stored.
61 *
62 * @return Hash of the sent message or 0 on error.
63 *
64 */
65aid_t async_obsolete_send_fast(int phoneid, sysarg_t method, sysarg_t arg1,
66 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
67{
68 amsg_t *msg = malloc(sizeof(amsg_t));
69
70 if (!msg)
71 return 0;
72
73 msg->done = false;
74 msg->dataptr = dataptr;
75
76 msg->wdata.to_event.inlist = false;
77
78 /*
79 * We may sleep in the next method,
80 * but it will use its own means
81 */
82 msg->wdata.active = true;
83
84 ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, msg,
85 reply_received, true);
86
87 return (aid_t) msg;
88}
89
90/** Pseudo-synchronous message sending - fast version.
91 *
92 * Send message asynchronously and return only after the reply arrives.
93 *
94 * This function can only transfer 4 register payload arguments. For
95 * transferring more arguments, see the slower async_req_slow().
96 *
97 * @param phoneid Hash of the phone through which to make the call.
98 * @param method Method of the call.
99 * @param arg1 Service-defined payload argument.
100 * @param arg2 Service-defined payload argument.
101 * @param arg3 Service-defined payload argument.
102 * @param arg4 Service-defined payload argument.
103 * @param r1 If non-NULL, storage for the 1st reply argument.
104 * @param r2 If non-NULL, storage for the 2nd reply argument.
105 * @param r3 If non-NULL, storage for the 3rd reply argument.
106 * @param r4 If non-NULL, storage for the 4th reply argument.
107 * @param r5 If non-NULL, storage for the 5th reply argument.
108 *
109 * @return Return code of the reply or a negative error code.
110 *
111 */
112sysarg_t async_obsolete_req_fast(int phoneid, sysarg_t method, sysarg_t arg1,
113 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2,
114 sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
115{
116 ipc_call_t result;
117 aid_t eid = async_obsolete_send_4(phoneid, method, arg1, arg2, arg3, arg4,
118 &result);
119
120 sysarg_t rc;
121 async_wait_for(eid, &rc);
122
123 if (r1)
124 *r1 = IPC_GET_ARG1(result);
125
126 if (r2)
127 *r2 = IPC_GET_ARG2(result);
128
129 if (r3)
130 *r3 = IPC_GET_ARG3(result);
131
132 if (r4)
133 *r4 = IPC_GET_ARG4(result);
134
135 if (r5)
136 *r5 = IPC_GET_ARG5(result);
137
138 return rc;
139}
140
141/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
142 *
143 * @param phoneid Phone that will be used to contact the receiving side.
144 * @param src Source address space area base address.
145 * @param flags Flags to be used for sharing. Bits can be only cleared.
146 *
147 * @return Zero on success or a negative error code from errno.h.
148 *
149 */
150int async_obsolete_share_out_start(int phoneid, void *src, unsigned int flags)
151{
152 return async_obsolete_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
153 (sysarg_t) flags);
154}
155
156/** Wrapper for ipc_hangup.
157 *
158 * @param phone Phone handle to hung up.
159 *
160 * @return Zero on success or a negative error code.
161 *
162 */
163int async_obsolete_hangup(int phone)
164{
165 return ipc_hangup(phone);
166}
167
168/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
169 *
170 * @param phoneid Phone that will be used to contact the receiving side.
171 * @param src Address of the beginning of the source buffer.
172 * @param size Size of the source buffer.
173 * @param flags Flags to control the data transfer.
174 *
175 * @return Zero on success or a negative error code from errno.h.
176 *
177 */
178int async_obsolete_data_write_start_generic(int phoneid, const void *src, size_t size,
179 int flags)
180{
181 return async_obsolete_req_3_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src,
182 (sysarg_t) size, (sysarg_t) flags);
183}
184
185/** Start IPC_M_DATA_READ using the async framework.
186 *
187 * @param phoneid Phone that will be used to contact the receiving side.
188 * @param dst Address of the beginning of the destination buffer.
189 * @param size Size of the destination buffer (in bytes).
190 * @param dataptr Storage of call data (arg 2 holds actual data size).
191 *
192 * @return Hash of the sent message or 0 on error.
193 *
194 */
195aid_t async_obsolete_data_read(int phone, void *dst, size_t size,
196 ipc_call_t *dataptr)
197{
198 return async_obsolete_send_2(phone, IPC_M_DATA_READ, (sysarg_t) dst,
199 (sysarg_t) size, dataptr);
200}
201
202/** Wrapper for IPC_M_DATA_READ calls using the async framework.
203 *
204 * @param phoneid Phone that will be used to contact the receiving side.
205 * @param dst Address of the beginning of the destination buffer.
206 * @param size Size of the destination buffer.
207 * @param flags Flags to control the data transfer.
208 *
209 * @return Zero on success or a negative error code from errno.h.
210 *
211 */
212int async_obsolete_data_read_start_generic(int phoneid, void *dst, size_t size, int flags)
213{
214 return async_obsolete_req_3_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst,
215 (sysarg_t) size, (sysarg_t) flags);
216}
217
218/** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
219 *
220 * Ask through phone for a new connection to some service.
221 *
222 * @param phone Phone handle used for contacting the other side.
223 * @param arg1 User defined argument.
224 * @param arg2 User defined argument.
225 * @param arg3 User defined argument.
226 * @param client_receiver Connection handing routine.
227 *
228 * @return New phone handle on success or a negative error code.
229 *
230 */
231int async_obsolete_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
232 sysarg_t arg3, async_client_conn_t client_receiver, void *carg)
233{
234 sysarg_t task_hash;
235 sysarg_t phone_hash;
236 int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
237 NULL, NULL, NULL, &task_hash, &phone_hash);
238 if (rc != EOK)
239 return rc;
240
241 if (client_receiver != NULL)
242 async_new_connection(task_hash, phone_hash, 0, NULL,
243 client_receiver, carg);
244
245 return EOK;
246}
247
248/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
249 *
250 * Ask through phone for a new connection to some service.
251 *
252 * @param phone Phone handle used for contacting the other side.
253 * @param arg1 User defined argument.
254 * @param arg2 User defined argument.
255 * @param arg3 User defined argument.
256 *
257 * @return New phone handle on success or a negative error code.
258 *
259 */
260int async_obsolete_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2,
261 sysarg_t arg3)
262{
263 sysarg_t newphid;
264 int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
265 NULL, NULL, NULL, NULL, &newphid);
266
267 if (rc != EOK)
268 return rc;
269
270 return newphid;
271}
272
273/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
274 *
275 * Ask through phone for a new connection to some service and block until
276 * success.
277 *
278 * @param phoneid Phone handle used for contacting the other side.
279 * @param arg1 User defined argument.
280 * @param arg2 User defined argument.
281 * @param arg3 User defined argument.
282 *
283 * @return New phone handle on success or a negative error code.
284 *
285 */
286int async_obsolete_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
287 sysarg_t arg3)
288{
289 sysarg_t newphid;
290 int rc = async_obsolete_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
291 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
292
293 if (rc != EOK)
294 return rc;
295
296 return newphid;
297}
298
299/** Send message and return id of the sent message
300 *
301 * The return value can be used as input for async_wait() to wait for
302 * completion.
303 *
304 * @param phoneid Handle of the phone that will be used for the send.
305 * @param method Service-defined method.
306 * @param arg1 Service-defined payload argument.
307 * @param arg2 Service-defined payload argument.
308 * @param arg3 Service-defined payload argument.
309 * @param arg4 Service-defined payload argument.
310 * @param arg5 Service-defined payload argument.
311 * @param dataptr If non-NULL, storage where the reply data will be
312 * stored.
313 *
314 * @return Hash of the sent message or 0 on error.
315 *
316 */
317aid_t async_obsolete_send_slow(int phoneid, sysarg_t method, sysarg_t arg1,
318 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
319 ipc_call_t *dataptr)
320{
321 amsg_t *msg = malloc(sizeof(amsg_t));
322
323 if (!msg)
324 return 0;
325
326 msg->done = false;
327 msg->dataptr = dataptr;
328
329 msg->wdata.to_event.inlist = false;
330
331 /*
332 * We may sleep in the next method,
333 * but it will use its own means
334 */
335 msg->wdata.active = true;
336
337 ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, msg,
338 reply_received, true);
339
340 return (aid_t) msg;
341}
342
343void async_obsolete_msg_0(int phone, sysarg_t imethod)
344{
345 ipc_call_async_0(phone, imethod, NULL, NULL, true);
346}
347
348void async_obsolete_msg_1(int phone, sysarg_t imethod, sysarg_t arg1)
349{
350 ipc_call_async_1(phone, imethod, arg1, NULL, NULL, true);
351}
352
353void async_obsolete_msg_2(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2)
354{
355 ipc_call_async_2(phone, imethod, arg1, arg2, NULL, NULL, true);
356}
357
358void async_obsolete_msg_3(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
359 sysarg_t arg3)
360{
361 ipc_call_async_3(phone, imethod, arg1, arg2, arg3, NULL, NULL, true);
362}
363
364void async_obsolete_msg_4(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
365 sysarg_t arg3, sysarg_t arg4)
366{
367 ipc_call_async_4(phone, imethod, arg1, arg2, arg3, arg4, NULL, NULL,
368 true);
369}
370
371void async_obsolete_msg_5(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
372 sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
373{
374 ipc_call_async_5(phone, imethod, arg1, arg2, arg3, arg4, arg5, NULL,
375 NULL, true);
376}
377
378/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
379 *
380 * @param phoneid Phone that will be used to contact the receiving side.
381 * @param dst Destination address space area base.
382 * @param size Size of the destination address space area.
383 * @param arg User defined argument.
384 * @param flags Storage for the received flags. Can be NULL.
385 *
386 * @return Zero on success or a negative error code from errno.h.
387 *
388 */
389int async_obsolete_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
390 unsigned int *flags)
391{
392 sysarg_t tmp_flags;
393 int res = async_obsolete_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
394 (sysarg_t) size, arg, NULL, &tmp_flags);
395
396 if (flags)
397 *flags = (unsigned int) tmp_flags;
398
399 return res;
400}
401
402int async_obsolete_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
403 sysarg_t arg1, sysarg_t arg2, unsigned int mode)
404{
405 return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
406}
407
408int async_obsolete_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
409 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
410 unsigned int mode)
411{
412 return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
413 arg5, mode);
414}
415
416/** Wrapper for forwarding any data that is about to be received
417 *
418 */
419int async_obsolete_data_write_forward_fast(int phoneid, sysarg_t method, sysarg_t arg1,
420 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
421{
422 ipc_callid_t callid;
423 if (!async_data_write_receive(&callid, NULL)) {
424 ipc_answer_0(callid, EINVAL);
425 return EINVAL;
426 }
427
428 aid_t msg = async_obsolete_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
429 dataptr);
430 if (msg == 0) {
431 ipc_answer_0(callid, EINVAL);
432 return EINVAL;
433 }
434
435 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
436 IPC_FF_ROUTE_FROM_ME);
437 if (retval != EOK) {
438 async_wait_for(msg, NULL);
439 ipc_answer_0(callid, retval);
440 return retval;
441 }
442
443 sysarg_t rc;
444 async_wait_for(msg, &rc);
445
446 return (int) rc;
447}
448
449/** @}
450 */
Note: See TracBrowser for help on using the repository browser.