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 net
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file
|
---|
34 | * Generic module functions.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef __NET_MODULES_H__
|
---|
38 | #define __NET_MODULES_H__
|
---|
39 |
|
---|
40 | #include <async.h>
|
---|
41 |
|
---|
42 | #include <ipc/ipc.h>
|
---|
43 | #include <ipc/services.h>
|
---|
44 |
|
---|
45 | #include <sys/time.h>
|
---|
46 |
|
---|
47 | /** Converts the data length between different types.
|
---|
48 | * @param[in] type_from The source type.
|
---|
49 | * @param[in] type_to The destination type.
|
---|
50 | * @param[in] count The number units of the source type size.
|
---|
51 | */
|
---|
52 | #define CONVERT_SIZE(type_from, type_to, count) ((sizeof(type_from) / sizeof(type_to)) * (count))
|
---|
53 |
|
---|
54 | /** Registers the module service at the name server.
|
---|
55 | * @param[in] me The module service.
|
---|
56 | * @param[out] phonehash The created phone hash.
|
---|
57 | */
|
---|
58 | #define REGISTER_ME(me, phonehash) ipc_connect_to_me(PHONE_NS, (me), 0, 0, (phonehash))
|
---|
59 |
|
---|
60 | /** Connect to the needed module function type definition.
|
---|
61 | * @param[in] need The needed module service.
|
---|
62 | * @returns The phone of the needed service.
|
---|
63 | */
|
---|
64 | typedef int connect_module_t(services_t need);
|
---|
65 |
|
---|
66 | /** Answers the call.
|
---|
67 | * @param[in] callid The call identifier.
|
---|
68 | * @param[in] result The message processing result.
|
---|
69 | * @param[in] answer The message processing answer.
|
---|
70 | * @param[in] answer_count The number of answer parameters.
|
---|
71 | */
|
---|
72 | void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count);
|
---|
73 |
|
---|
74 | /** Creates bidirectional connection with the needed module service and registers the message receiver.
|
---|
75 | * @param[in] need The needed module service.
|
---|
76 | * @param[in] arg1 The first parameter.
|
---|
77 | * @param[in] arg2 The second parameter.
|
---|
78 | * @param[in] arg3 The third parameter.
|
---|
79 | * @param[in] client_receiver The message receiver.
|
---|
80 | * @returns The phone of the needed service.
|
---|
81 | * @returns Other error codes as defined for the ipc_connect_to_me() function.
|
---|
82 | */
|
---|
83 | int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver);
|
---|
84 |
|
---|
85 | /** Creates bidirectional connection with the needed module service and registers the message receiver.
|
---|
86 | * @param[in] need The needed module service.
|
---|
87 | * @param[in] arg1 The first parameter.
|
---|
88 | * @param[in] arg2 The second parameter.
|
---|
89 | * @param[in] arg3 The third parameter.
|
---|
90 | * @param[in] client_receiver The message receiver.
|
---|
91 | * @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
|
---|
92 | * @returns The phone of the needed service.
|
---|
93 | * @returns ETIMEOUT if the connection timeouted.
|
---|
94 | * @returns Other error codes as defined for the ipc_connect_to_me() function.
|
---|
95 | */
|
---|
96 | int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout);
|
---|
97 |
|
---|
98 | /** Connects to the needed module.
|
---|
99 | * @param[in] need The needed module service.
|
---|
100 | * @returns The phone of the needed service.
|
---|
101 | */
|
---|
102 | int connect_to_service(services_t need);
|
---|
103 |
|
---|
104 | /** Connects to the needed module.
|
---|
105 | * @param[in] need The needed module service.
|
---|
106 | * @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
|
---|
107 | * @returns The phone of the needed service.
|
---|
108 | * @returns ETIMEOUT if the connection timeouted.
|
---|
109 | */
|
---|
110 | int connect_to_service_timeout(services_t need, suseconds_t timeout);
|
---|
111 |
|
---|
112 | /** Receives data from the other party.
|
---|
113 | * The received data buffer is allocated and returned.
|
---|
114 | * @param[out] data The data buffer to be filled.
|
---|
115 | * @param[out] length The buffer length.
|
---|
116 | * @returns EOK on success.
|
---|
117 | * @returns EBADMEM if the data or the length parameter is NULL.
|
---|
118 | * @returns EINVAL if the client does not send data.
|
---|
119 | * @returns ENOMEM if there is not enough memory left.
|
---|
120 | * @returns Other error codes as defined for the async_data_write_finalize() function.
|
---|
121 | */
|
---|
122 | int data_receive(void ** data, size_t * length);
|
---|
123 |
|
---|
124 | /** Replies the data to the other party.
|
---|
125 | * @param[in] data The data buffer to be sent.
|
---|
126 | * @param[in] data_length The buffer length.
|
---|
127 | * @returns EOK on success.
|
---|
128 | * @returns EINVAL if the client does not expect the data.
|
---|
129 | * @returns EOVERFLOW if the client does not expect all the data. Only partial data are transfered.
|
---|
130 | * @returns Other error codes as defined for the async_data_read_finalize() function.
|
---|
131 | */
|
---|
132 | int data_reply(void * data, size_t data_length);
|
---|
133 |
|
---|
134 | /** Refreshes answer structure and parameters count.
|
---|
135 | * Erases all attributes.
|
---|
136 | * @param[in,out] answer The message processing answer structure.
|
---|
137 | * @param[in,out] answer_count The number of answer parameters.
|
---|
138 | */
|
---|
139 | void refresh_answer(ipc_call_t * answer, int * answer_count);
|
---|
140 |
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | /** @}
|
---|
144 | */
|
---|