source: mainline/uspace/lib/c/generic/ns.c@ 566992e1

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

extremely rudimentary support for interfaces and ports
(does not do much, but it is backward and forward compatible)

  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[007e6efa]1/*
2 * Copyright (c) 2011 Martin Decky
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
[79ae36dd]35#include <ns.h>
[007e6efa]36#include <ipc/ns.h>
[79ae36dd]37#include <async.h>
38#include <macros.h>
[b1bd89ea]39#include <errno.h>
[79ae36dd]40#include "private/ns.h"
[007e6efa]41
[566992e1]42int service_register(service_t service)
[007e6efa]43{
[79ae36dd]44 async_exch_t *exch = async_exchange_begin(session_ns);
[2133e02]45 int rc = async_connect_to_me(exch, 0, service, 0, NULL, NULL);
[79ae36dd]46 async_exchange_end(exch);
47
48 return rc;
49}
50
[2133e02]51async_sess_t *service_connect_iface(exch_mgmt_t mgmt, sysarg_t iface,
52 service_t service, sysarg_t arg3)
53{
54 async_exch_t *exch = async_exchange_begin(session_ns);
55 if (!exch)
56 return NULL;
57
58 async_sess_t *sess =
59 async_connect_me_to(mgmt, exch, iface, service, arg3);
60 async_exchange_end(exch);
61
62 if (!sess)
63 return NULL;
64
65 /*
66 * FIXME Ugly hack to work around limitation of implementing
67 * parallel exchanges using multiple connections. Shift out
68 * first argument for non-initial connections.
69 */
70 async_sess_args_set(sess, iface, arg3, 0);
71
72 return sess;
73}
74
75async_sess_t *service_connect(exch_mgmt_t mgmt, service_t service, sysarg_t arg3)
[79ae36dd]76{
77 async_exch_t *exch = async_exchange_begin(session_ns);
[d1e18573]78 if (!exch)
79 return NULL;
[f51b1d3]80
[79ae36dd]81 async_sess_t *sess =
[2133e02]82 async_connect_me_to(mgmt, exch, 0, service, arg3);
[79ae36dd]83 async_exchange_end(exch);
[f51b1d3]84
[d1e18573]85 if (!sess)
86 return NULL;
[79ae36dd]87
[0f4532e]88 /*
89 * FIXME Ugly hack to work around limitation of implementing
90 * parallel exchanges using multiple connections. Shift out
91 * first argument for non-initial connections.
92 */
[2133e02]93 async_sess_args_set(sess, 0, arg3, 0);
94
95 return sess;
96}
97
98async_sess_t *service_connect_blocking_iface(exch_mgmt_t mgmt, sysarg_t iface,
99 service_t service, sysarg_t arg3)
100{
101 async_exch_t *exch = async_exchange_begin(session_ns);
102 if (!exch)
103 return NULL;
104 async_sess_t *sess =
105 async_connect_me_to_blocking(mgmt, exch, iface, service, arg3);
106 async_exchange_end(exch);
107
108 if (!sess)
109 return NULL;
110
111 /*
112 * FIXME Ugly hack to work around limitation of implementing
113 * parallel exchanges using multiple connections. Shift out
114 * first argument for non-initial connections.
115 */
116 async_sess_args_set(sess, iface, arg3, 0);
[0f4532e]117
[79ae36dd]118 return sess;
119}
120
[566992e1]121async_sess_t *service_connect_blocking_iface_extended(service_t service,
122 iface_t iface, sysarg_t arg3)
123{
124 async_exch_t *exch = async_exchange_begin(session_ns);
125 async_sess_t *sess =
126 async_connect_me_to_blocking_iface(exch, iface, service, arg3);
127 async_exchange_end(exch);
128
129 if (!sess)
130 return NULL;
131
132 /*
133 * FIXME Ugly hack to work around limitation of implementing
134 * parallel exchanges using multiple connections. Shift out
135 * first argument for non-initial connections.
136 */
137 async_sess_args_set(sess, iface, arg3, 0);
138
139 return sess;
140}
141
[6a8ce16e]142async_sess_t *service_connect_blocking(exch_mgmt_t mgmt, service_t service,
[2133e02]143 sysarg_t arg3)
[79ae36dd]144{
145 async_exch_t *exch = async_exchange_begin(session_ns);
146 async_sess_t *sess =
[2133e02]147 async_connect_me_to_blocking(mgmt, exch, 0, service, arg3);
[79ae36dd]148 async_exchange_end(exch);
[b1bd89ea]149
[8fa6d4c7]150 if (!sess)
151 return NULL;
[79ae36dd]152
[422722e]153 /*
154 * FIXME Ugly hack to work around limitation of implementing
155 * parallel exchanges using multiple connections. Shift out
156 * first argument for non-initial connections.
157 */
[2133e02]158 async_sess_args_set(sess, 0, arg3, 0);
[422722e]159
[79ae36dd]160 return sess;
[007e6efa]161}
162
[b1bd89ea]163/** Create bidirectional connection with a service
164 *
165 * @param[in] service Service.
166 * @param[in] arg1 First parameter.
167 * @param[in] arg2 Second parameter.
168 * @param[in] arg3 Third parameter.
169 * @param[in] client_receiver Message receiver.
170 *
171 * @return Session to the service.
172 * @return Other error codes as defined by async_connect_to_me().
173 *
174 */
[6a8ce16e]175async_sess_t *service_bind(service_t service, sysarg_t arg1, sysarg_t arg2,
[b688fd8]176 sysarg_t arg3, async_port_handler_t client_receiver)
[b1bd89ea]177{
178 /* Connect to the needed service */
179 async_sess_t *sess =
[2133e02]180 service_connect_blocking(EXCHANGE_SERIALIZE, service, 0);
[b1bd89ea]181 if (sess != NULL) {
182 /* Request callback connection */
183 async_exch_t *exch = async_exchange_begin(sess);
184 int rc = async_connect_to_me(exch, arg1, arg2, arg3,
185 client_receiver, NULL);
186 async_exchange_end(exch);
187
188 if (rc != EOK) {
189 async_hangup(sess);
190 errno = rc;
191 return NULL;
192 }
193 }
194
195 return sess;
196}
197
[79ae36dd]198int ns_ping(void)
[007e6efa]199{
[79ae36dd]200 async_exch_t *exch = async_exchange_begin(session_ns);
201 int rc = async_req_0_0(exch, NS_PING);
202 async_exchange_end(exch);
203
204 return rc;
[007e6efa]205}
206
[79ae36dd]207int ns_intro(task_id_t id)
[007e6efa]208{
[79ae36dd]209 async_exch_t *exch = async_exchange_begin(session_ns);
210 int rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
211 async_exchange_end(exch);
212
213 return rc;
[007e6efa]214}
215
216/** @}
217 */
Note: See TracBrowser for help on using the repository browser.