Rev 1547 | Rev 1596 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1472 | palkovsky | 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 | |||
| 1394 | palkovsky | 29 | #ifndef _libc_ASYNC_H_ |
| 30 | #define _libc_ASYNC_H_ |
||
| 31 | |||
| 32 | #include <ipc/ipc.h> |
||
| 1407 | palkovsky | 33 | #include <psthread.h> |
| 1449 | palkovsky | 34 | #include <sys/time.h> |
| 1463 | palkovsky | 35 | #include <atomic.h> |
| 1394 | palkovsky | 36 | |
| 1427 | palkovsky | 37 | typedef ipc_callid_t aid_t; |
| 1490 | palkovsky | 38 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
| 1427 | palkovsky | 39 | |
| 1394 | palkovsky | 40 | int async_manager(void); |
| 1500 | palkovsky | 41 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
| 42 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
||
| 43 | { |
||
| 44 | return async_get_call_timeout(data, 0); |
||
| 45 | } |
||
| 1394 | palkovsky | 46 | |
| 1427 | palkovsky | 47 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
| 48 | ipc_call_t *dataptr); |
||
| 1547 | palkovsky | 49 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
| 50 | ipcarg_t arg3, ipc_call_t *dataptr); |
||
| 1427 | palkovsky | 51 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
| 1441 | palkovsky | 52 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
| 1464 | palkovsky | 53 | |
| 54 | /** Pseudo-synchronous message sending |
||
| 55 | * |
||
| 56 | * Send message through IPC, wait in the event loop, until it is received |
||
| 57 | * |
||
| 58 | * @return Return code of message |
||
| 59 | */ |
||
| 60 | static inline ipcarg_t sync_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2) |
||
| 61 | { |
||
| 62 | ipc_call_t result; |
||
| 63 | ipcarg_t rc; |
||
| 64 | |||
| 65 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
||
| 66 | async_wait_for(eid, &rc); |
||
| 67 | if (r1) |
||
| 68 | *r1 = IPC_GET_ARG1(result); |
||
| 69 | if (r2) |
||
| 70 | *r2 = IPC_GET_ARG2(result); |
||
| 71 | return rc; |
||
| 72 | } |
||
| 1552 | palkovsky | 73 | #define sync_send(phoneid, method, arg1, r1) sync_send_2(phoneid, method, arg1, 0, r1, 0) |
| 74 | |||
| 1547 | palkovsky | 75 | static inline ipcarg_t sync_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
| 76 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, |
||
| 77 | ipcarg_t *r2, ipcarg_t *r3) |
||
| 78 | { |
||
| 79 | ipc_call_t result; |
||
| 80 | ipcarg_t rc; |
||
| 1464 | palkovsky | 81 | |
| 1547 | palkovsky | 82 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result); |
| 83 | async_wait_for(eid, &rc); |
||
| 84 | if (r1) |
||
| 85 | *r1 = IPC_GET_ARG1(result); |
||
| 86 | if (r2) |
||
| 87 | *r2 = IPC_GET_ARG2(result); |
||
| 88 | if (r3) |
||
| 89 | *r3 = IPC_GET_ARG3(result); |
||
| 90 | return rc; |
||
| 91 | } |
||
| 1464 | palkovsky | 92 | |
| 1547 | palkovsky | 93 | |
| 1452 | palkovsky | 94 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
| 95 | ipc_call_t *call, |
||
| 96 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
||
| 97 | void async_usleep(suseconds_t timeout); |
||
| 1464 | palkovsky | 98 | void async_create_manager(void); |
| 99 | void async_destroy_manager(void); |
||
| 1490 | palkovsky | 100 | void async_set_client_connection(async_client_conn_t conn); |
| 1464 | palkovsky | 101 | int _async_init(void); |
| 1427 | palkovsky | 102 | |
| 103 | /* Should be defined by application */ |
||
| 1452 | palkovsky | 104 | void interrupt_received(ipc_call_t *call) __attribute__((weak)); |
| 1394 | palkovsky | 105 | |
| 1463 | palkovsky | 106 | |
| 107 | extern atomic_t async_futex; |
||
| 108 | |||
| 1394 | palkovsky | 109 | #endif |