source: mainline/uspace/lib/c/generic/net/modules.c@ 32fef47

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

remove obsolete stuff

  • Property mode set to 100644
File size: 4.9 KB
RevLine 
[c7a8442]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
[774e6d1a]34 * Generic module functions implementation.
[c7a8442]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>
[16ac756]43#include <errno.h>
[c7a8442]44#include <sys/time.h>
45#include <ipc/services.h>
46#include <net/modules.h>
[79ae36dd]47#include <ns.h>
[c7a8442]48
[774e6d1a]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.
[c7a8442]55 *
56 */
[774e6d1a]57void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,
58 size_t count)
[c7a8442]59{
[774e6d1a]60 /* Choose the most efficient function */
61 if ((answer != NULL) || (count == 0)) {
62 switch (count) {
[c7a8442]63 case 0:
[64d2b10]64 async_answer_0(callid, (sysarg_t) result);
[c7a8442]65 break;
66 case 1:
[64d2b10]67 async_answer_1(callid, (sysarg_t) result,
[c7a8442]68 IPC_GET_ARG1(*answer));
69 break;
70 case 2:
[64d2b10]71 async_answer_2(callid, (sysarg_t) result,
[c7a8442]72 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
73 break;
74 case 3:
[64d2b10]75 async_answer_3(callid, (sysarg_t) result,
[c7a8442]76 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer),
77 IPC_GET_ARG3(*answer));
78 break;
79 case 4:
[64d2b10]80 async_answer_4(callid, (sysarg_t) result,
[c7a8442]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:
[64d2b10]86 async_answer_5(callid, (sysarg_t) result,
[c7a8442]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
[32fef47]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 */
103static async_sess_t *connect_to_service(services_t need)
104{
105 return service_connect_blocking(EXCHANGE_SERIALIZE, need, 0, 0);
106}
107
[6b82009]108/** Create bidirectional connection with the needed module service and register
[c7a8442]109 * the message receiver.
110 *
[6b82009]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.
[c7a8442]120 *
121 */
[6b82009]122async_sess_t *bind_service(services_t need, sysarg_t arg1, sysarg_t arg2,
123 sysarg_t arg3, async_client_conn_t client_receiver)
[c7a8442]124{
125 /* Connect to the needed service */
[6b82009]126 async_sess_t *sess = connect_to_service(need);
127 if (sess != NULL) {
[c7a8442]128 /* Request the bidirectional connection */
[6b82009]129 async_exch_t *exch = async_exchange_begin(sess);
130 int rc = async_connect_to_me(exch, arg1, arg2, arg3,
[9934f7d]131 client_receiver, NULL);
[6b82009]132 async_exchange_end(exch);
133
[16ac756]134 if (rc != EOK) {
[6b82009]135 async_hangup(sess);
136 errno = rc;
137 return NULL;
[c7a8442]138 }
139 }
140
[6b82009]141 return sess;
[c7a8442]142}
143
[774e6d1a]144/** Refresh answer structure and argument count.
145 *
146 * Erase all arguments.
[c7a8442]147 *
[774e6d1a]148 * @param[in,out] answer Message processing answer structure.
149 * @param[in,out] count Number of answer arguments.
[c7a8442]150 *
151 */
[774e6d1a]152void refresh_answer(ipc_call_t *answer, size_t *count)
[c7a8442]153{
[774e6d1a]154 if (count != NULL)
155 *count = 0;
156
157 if (answer != NULL) {
[c7a8442]158 IPC_SET_RETVAL(*answer, 0);
[228e490]159 IPC_SET_IMETHOD(*answer, 0);
[c7a8442]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 */
Note: See TracBrowser for help on using the repository browser.