source: mainline/uspace/lib/c/generic/ns.c@ 25a179e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 25a179e was 25a179e, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

IPC return values are always errno constants. Adjust types to reflect that.

In principle, IPC server is not allowed to return non-errno values via
the "main" return value, because kernel interprets it (e.g. EHANGUP).
It's still possible to return arbitrary additional return values alongside EOK,
which are not interpreted in normal communication.

  • Property mode set to 100644
File size: 4.2 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
[7b616e2]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
[566992e1]48int service_register(service_t service)
[007e6efa]49{
[25a179e]50 int retval;
[7b616e2]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);
[f9b2cb4c]59 int rc = async_connect_to_me(exch, 0, service, 0);
[7b616e2]60
[79ae36dd]61 async_exchange_end(exch);
62
[7b616e2]63 if (rc != EOK) {
64 async_forget(req);
65 return rc;
66 }
67
68 async_wait_for(req, &retval);
[79ae36dd]69 return rc;
70}
71
[f9b2cb4c]72async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
[0dd16778]73{
[7b616e2]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)
[0dd16778]80 return NULL;
81
[7b616e2]82 async_sess_t *csess =
[0dd16778]83 async_connect_me_to_iface(exch, iface, service, arg3);
84 async_exchange_end(exch);
85
[7b616e2]86 if (csess == NULL)
[0dd16778]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 */
[7b616e2]94 async_sess_args_set(csess, iface, arg3, 0);
[0dd16778]95
[7b616e2]96 return csess;
[0dd16778]97}
98
[f9b2cb4c]99async_sess_t *service_connect_blocking(service_t service, iface_t iface,
100 sysarg_t arg3)
[566992e1]101{
[7b616e2]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 =
[566992e1]108 async_connect_me_to_blocking_iface(exch, iface, service, arg3);
109 async_exchange_end(exch);
110
[7b616e2]111 if (csess == NULL)
[566992e1]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 */
[7b616e2]119 async_sess_args_set(csess, iface, arg3, 0);
[566992e1]120
[7b616e2]121 return csess;
[566992e1]122}
123
[b1bd89ea]124
[79ae36dd]125int ns_ping(void)
[007e6efa]126{
[7b616e2]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);
[79ae36dd]132 int rc = async_req_0_0(exch, NS_PING);
133 async_exchange_end(exch);
134
135 return rc;
[007e6efa]136}
137
[79ae36dd]138int ns_intro(task_id_t id)
[007e6efa]139{
[7b616e2]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);
[79ae36dd]146 int rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
147 async_exchange_end(exch);
148
149 return rc;
[007e6efa]150}
151
[7b616e2]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_iface(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
[007e6efa]167/** @}
168 */
Note: See TracBrowser for help on using the repository browser.