1 | /*
|
---|
2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
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 |
|
---|
33 | /** @file
|
---|
34 | * Generic module functions implementation.
|
---|
35 | *
|
---|
36 | * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS
|
---|
37 | * FUNCTIONALITY OR VIA INTEGRATING ITS FUNCTIONALITY MORE TIGHTLY WITH THE REST
|
---|
38 | * OF THE SYSTEM.
|
---|
39 | */
|
---|
40 |
|
---|
41 | #include <async.h>
|
---|
42 | #include <malloc.h>
|
---|
43 | #include <errno.h>
|
---|
44 | #include <sys/time.h>
|
---|
45 | #include <ipc/services.h>
|
---|
46 | #include <net/modules.h>
|
---|
47 | #include <ns.h>
|
---|
48 |
|
---|
49 | /** Answer a call.
|
---|
50 | *
|
---|
51 | * @param[in] callid Call identifier.
|
---|
52 | * @param[in] result Message processing result.
|
---|
53 | * @param[in] answer Message processing answer.
|
---|
54 | * @param[in] count Number of answer parameters.
|
---|
55 | *
|
---|
56 | */
|
---|
57 | void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,
|
---|
58 | size_t count)
|
---|
59 | {
|
---|
60 | /* Choose the most efficient function */
|
---|
61 | if ((answer != NULL) || (count == 0)) {
|
---|
62 | switch (count) {
|
---|
63 | case 0:
|
---|
64 | async_answer_0(callid, (sysarg_t) result);
|
---|
65 | break;
|
---|
66 | case 1:
|
---|
67 | async_answer_1(callid, (sysarg_t) result,
|
---|
68 | IPC_GET_ARG1(*answer));
|
---|
69 | break;
|
---|
70 | case 2:
|
---|
71 | async_answer_2(callid, (sysarg_t) result,
|
---|
72 | IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
|
---|
73 | break;
|
---|
74 | case 3:
|
---|
75 | async_answer_3(callid, (sysarg_t) result,
|
---|
76 | IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
|
---|
77 | IPC_GET_ARG3(*answer));
|
---|
78 | break;
|
---|
79 | case 4:
|
---|
80 | async_answer_4(callid, (sysarg_t) result,
|
---|
81 | IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
|
---|
82 | IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
|
---|
83 | break;
|
---|
84 | case 5:
|
---|
85 | default:
|
---|
86 | async_answer_5(callid, (sysarg_t) result,
|
---|
87 | IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
|
---|
88 | IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer),
|
---|
89 | IPC_GET_ARG5(*answer));
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | /** Connect to the needed module.
|
---|
96 | *
|
---|
97 | * @param[in] need Needed module service.
|
---|
98 | *
|
---|
99 | * @return Session to the needed service.
|
---|
100 | * @return NULL if the connection timeouted.
|
---|
101 | *
|
---|
102 | */
|
---|
103 | static async_sess_t *connect_to_service(services_t need)
|
---|
104 | {
|
---|
105 | return service_connect_blocking(EXCHANGE_SERIALIZE, need, 0, 0);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /** Create bidirectional connection with the needed module service and register
|
---|
109 | * the message receiver.
|
---|
110 | *
|
---|
111 | * @param[in] need Needed module service.
|
---|
112 | * @param[in] arg1 First parameter.
|
---|
113 | * @param[in] arg2 Second parameter.
|
---|
114 | * @param[in] arg3 Third parameter.
|
---|
115 | * @param[in] client_receiver Message receiver.
|
---|
116 | *
|
---|
117 | * @return Session to the needed service.
|
---|
118 | * @return Other error codes as defined for the async_connect_to_me()
|
---|
119 | * function.
|
---|
120 | *
|
---|
121 | */
|
---|
122 | async_sess_t *bind_service(services_t need, sysarg_t arg1, sysarg_t arg2,
|
---|
123 | sysarg_t arg3, async_client_conn_t client_receiver)
|
---|
124 | {
|
---|
125 | /* Connect to the needed service */
|
---|
126 | async_sess_t *sess = connect_to_service(need);
|
---|
127 | if (sess != NULL) {
|
---|
128 | /* Request the bidirectional connection */
|
---|
129 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
130 | int rc = async_connect_to_me(exch, arg1, arg2, arg3,
|
---|
131 | client_receiver, NULL);
|
---|
132 | async_exchange_end(exch);
|
---|
133 |
|
---|
134 | if (rc != EOK) {
|
---|
135 | async_hangup(sess);
|
---|
136 | errno = rc;
|
---|
137 | return NULL;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | return sess;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /** Refresh answer structure and argument count.
|
---|
145 | *
|
---|
146 | * Erase all arguments.
|
---|
147 | *
|
---|
148 | * @param[in,out] answer Message processing answer structure.
|
---|
149 | * @param[in,out] count Number of answer arguments.
|
---|
150 | *
|
---|
151 | */
|
---|
152 | void refresh_answer(ipc_call_t *answer, size_t *count)
|
---|
153 | {
|
---|
154 | if (count != NULL)
|
---|
155 | *count = 0;
|
---|
156 |
|
---|
157 | if (answer != NULL) {
|
---|
158 | IPC_SET_RETVAL(*answer, 0);
|
---|
159 | IPC_SET_IMETHOD(*answer, 0);
|
---|
160 | IPC_SET_ARG1(*answer, 0);
|
---|
161 | IPC_SET_ARG2(*answer, 0);
|
---|
162 | IPC_SET_ARG3(*answer, 0);
|
---|
163 | IPC_SET_ARG4(*answer, 0);
|
---|
164 | IPC_SET_ARG5(*answer, 0);
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** @}
|
---|
169 | */
|
---|