source: mainline/uspace/lib/c/generic/ns.c@ edc64c0

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

remove obsolete non-interface connection routines

  • Property mode set to 100644
File size: 4.2 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#include "private/ns.h"
41
42/*
43 * XXX ns does not know about session_ns, so we create an extra session for
44 * actual communicaton
45 */
46static async_sess_t *sess_ns = NULL;
47
48errno_t service_register(service_t service)
49{
50 errno_t retval;
51 ipc_call_t answer;
52
53 async_sess_t *sess = ns_session_get();
54 if (sess == NULL)
55 return EIO;
56
57 async_exch_t *exch = async_exchange_begin(sess);
58 aid_t req = async_send_1(exch, NS_REGISTER, service, &answer);
59 errno_t rc = async_connect_to_me(exch, 0, service, 0);
60
61 async_exchange_end(exch);
62
63 if (rc != EOK) {
64 async_forget(req);
65 return rc;
66 }
67
68 async_wait_for(req, &retval);
69 return rc;
70}
71
72async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
73{
74 async_sess_t *sess = ns_session_get();
75 if (sess == NULL)
76 return NULL;
77
78 async_exch_t *exch = async_exchange_begin(sess);
79 if (exch == NULL)
80 return NULL;
81
82 async_sess_t *csess =
83 async_connect_me_to(exch, iface, service, arg3);
84 async_exchange_end(exch);
85
86 if (csess == NULL)
87 return NULL;
88
89 /*
90 * FIXME Ugly hack to work around limitation of implementing
91 * parallel exchanges using multiple connections. Shift out
92 * first argument for non-initial connections.
93 */
94 async_sess_args_set(csess, iface, arg3, 0);
95
96 return csess;
97}
98
99async_sess_t *service_connect_blocking(service_t service, iface_t iface,
100 sysarg_t arg3)
101{
102 async_sess_t *sess = ns_session_get();
103 if (sess == NULL)
104 return NULL;
105
106 async_exch_t *exch = async_exchange_begin(sess);
107 async_sess_t *csess =
108 async_connect_me_to_blocking(exch, iface, service, arg3);
109 async_exchange_end(exch);
110
111 if (csess == NULL)
112 return NULL;
113
114 /*
115 * FIXME Ugly hack to work around limitation of implementing
116 * parallel exchanges using multiple connections. Shift out
117 * first argument for non-initial connections.
118 */
119 async_sess_args_set(csess, iface, arg3, 0);
120
121 return csess;
122}
123
124
125errno_t ns_ping(void)
126{
127 async_sess_t *sess = ns_session_get();
128 if (sess == NULL)
129 return EIO;
130
131 async_exch_t *exch = async_exchange_begin(sess);
132 errno_t rc = async_req_0_0(exch, NS_PING);
133 async_exchange_end(exch);
134
135 return rc;
136}
137
138errno_t ns_intro(task_id_t id)
139{
140 async_exch_t *exch;
141 async_sess_t *sess = ns_session_get();
142 if (sess == NULL)
143 return EIO;
144
145 exch = async_exchange_begin(sess);
146 errno_t rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
147 async_exchange_end(exch);
148
149 return rc;
150}
151
152async_sess_t *ns_session_get(void)
153{
154 async_exch_t *exch;
155
156 if (sess_ns == NULL) {
157 exch = async_exchange_begin(&session_ns);
158 sess_ns = async_connect_me_to(exch, 0, 0, 0);
159 async_exchange_end(exch);
160 if (sess_ns == NULL)
161 return NULL;
162 }
163
164 return sess_ns;
165}
166
167/** @}
168 */
Note: See TracBrowser for help on using the repository browser.