source: mainline/uspace/lib/c/generic/ns.c@ 7fa8589

Last change on this file since 7fa8589 was 241f1985, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

  • Property mode set to 100644
File size: 4.1 KB
Line 
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
35#include <ns.h>
36#include <ipc/ns.h>
37#include <async.h>
38#include <macros.h>
39#include <errno.h>
40
41#include "private/taskman.h"
42
43static async_sess_t *session_ns = NULL;
44
45static async_exch_t *ns_exchange_begin(void)
46{
47 /* Lazily connect to our NS */
48 if (session_ns == NULL) {
49 session_ns = taskman_session_ns();
50 }
51
52 async_exch_t *exch = async_exchange_begin(session_ns);
53 return exch;
54}
55
56static void ns_exchange_end(async_exch_t *exch)
57{
58 async_exchange_end(exch);
59}
60
61errno_t service_register(service_t service, iface_t iface,
62 async_port_handler_t handler, void *data)
63{
64 port_id_t port;
65 errno_t rc = async_create_port(iface, handler, data, &port);
66 if (rc != EOK)
67 return rc;
68
69 async_exch_t *exch = ns_exchange_begin();
70
71 ipc_call_t answer;
72 aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
73 rc = async_connect_to_me(exch, iface, service, 0);
74
75 ns_exchange_end(exch);
76
77 if (rc != EOK) {
78 async_forget(req);
79 return rc;
80 }
81
82 errno_t retval;
83 async_wait_for(req, &retval);
84 return rc;
85}
86
87errno_t service_register_broker(service_t service, async_port_handler_t handler,
88 void *data)
89{
90 async_set_fallback_port_handler(handler, data);
91
92 async_exch_t *exch = ns_exchange_begin();
93
94 ipc_call_t answer;
95 aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
96 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
97
98 ns_exchange_end(exch);
99
100 if (rc != EOK) {
101 async_forget(req);
102 return rc;
103 }
104
105 errno_t retval;
106 async_wait_for(req, &retval);
107 return rc;
108}
109
110async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
111{
112 async_exch_t *exch = ns_exchange_begin();
113 if (exch == NULL)
114 return NULL;
115
116 async_sess_t *sess =
117 async_connect_me_to(exch, iface, service, arg3);
118 ns_exchange_end(exch);
119
120 if (sess == NULL)
121 return NULL;
122
123 /*
124 * FIXME Ugly hack to work around limitation of implementing
125 * parallel exchanges using multiple connections. Shift out
126 * first argument for non-initial connections.
127 */
128 async_sess_args_set(sess, iface, arg3, 0);
129
130 return sess;
131}
132
133async_sess_t *service_connect_blocking(service_t service, iface_t iface,
134 sysarg_t arg3)
135{
136 async_exch_t *exch = ns_exchange_begin();
137 async_sess_t *sess =
138 async_connect_me_to_blocking(exch, iface, service, arg3);
139 ns_exchange_end(exch);
140
141 if (sess == NULL)
142 return NULL;
143
144 /*
145 * FIXME Ugly hack to work around limitation of implementing
146 * parallel exchanges using multiple connections. Shift out
147 * first argument for non-initial connections.
148 */
149 async_sess_args_set(sess, iface, arg3, 0);
150
151 return sess;
152}
153
154errno_t ns_ping(void)
155{
156 async_exch_t *exch = ns_exchange_begin();
157 errno_t rc = async_req_0_0(exch, NS_PING);
158 ns_exchange_end(exch);
159
160 return rc;
161}
162
163/** @}
164 */
Note: See TracBrowser for help on using the repository browser.