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

Last change on this file since fe86d9d was 0a8f070, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Create taskman server (extracts task-related operations from naming service)

  • Exploits initial phones connected to spawn parent instead of NS.
  • session_ns changed to session_primary (setup during taskman-loader handshake).
  • Task creation moved from NS to taskman (no clonable services anymore).
  • Other task-related operations implementation is to come (task_retval is temporarily dummy).
  • Async framework: implicit connections — create fibrils for calls that arrived through initial phone.

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/Makefile
uspace/app/trace/ipcp.c
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/ns.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/ipc/services.h
uspace/lib/c/include/ipc/taskman.h
uspace/lib/c/include/loader/pcb.h
uspace/lib/c/include/ns.h
uspace/srv/loader/main.c
uspace/srv/ns/clonable.c
uspace/srv/ns/ns.c

  • Property mode set to 100644
File size: 4.7 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_primary, so we create an extra session for
44 * actual communicaton
45 */
46static async_sess_t *sess_primary = NULL;
47
48errno_t service_register(service_t service, iface_t iface,
49 async_port_handler_t handler, void *data)
50{
51 async_sess_t *sess = get_session_primary();
52 if (sess == NULL)
53 return EIO;
54
55 port_id_t port;
56 errno_t rc = async_create_port(iface, handler, data, &port);
57 if (rc != EOK)
58 return rc;
59
60 async_exch_t *exch = async_exchange_begin(sess);
61
62 ipc_call_t answer;
63 aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
64 rc = async_connect_to_me(exch, iface, service, 0);
65
66 async_exchange_end(exch);
67
68 if (rc != EOK) {
69 async_forget(req);
70 return rc;
71 }
72
73 errno_t retval;
74 async_wait_for(req, &retval);
75 return rc;
76}
77
78errno_t service_register_broker(service_t service, async_port_handler_t handler,
79 void *data)
80{
81 async_set_fallback_port_handler(handler, data);
82
83 async_sess_t *sess = get_session_primary();
84 if (sess == NULL)
85 return EIO;
86
87 async_exch_t *exch = async_exchange_begin(sess);
88
89 ipc_call_t answer;
90 aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
91 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
92
93 async_exchange_end(exch);
94
95 if (rc != EOK) {
96 async_forget(req);
97 return rc;
98 }
99
100 errno_t retval;
101 async_wait_for(req, &retval);
102 return rc;
103}
104
105async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
106{
107 async_sess_t *sess = get_session_primary();
108 if (sess == NULL)
109 return NULL;
110
111 async_exch_t *exch = async_exchange_begin(sess);
112 if (exch == NULL)
113 return NULL;
114
115 async_sess_t *csess =
116 async_connect_me_to(exch, iface, service, arg3);
117 async_exchange_end(exch);
118
119 if (csess == NULL)
120 return NULL;
121
122 /*
123 * FIXME Ugly hack to work around limitation of implementing
124 * parallel exchanges using multiple connections. Shift out
125 * first argument for non-initial connections.
126 */
127 async_sess_args_set(csess, iface, arg3, 0);
128
129 return csess;
130}
131
132async_sess_t *service_connect_blocking(service_t service, iface_t iface,
133 sysarg_t arg3)
134{
135 async_sess_t *sess = get_session_primary();
136 if (sess == NULL)
137 return NULL;
138
139 async_exch_t *exch = async_exchange_begin(sess);
140 async_sess_t *csess =
141 async_connect_me_to_blocking(exch, iface, service, arg3);
142 async_exchange_end(exch);
143
144 if (csess == NULL)
145 return NULL;
146
147 /*
148 * FIXME Ugly hack to work around limitation of implementing
149 * parallel exchanges using multiple connections. Shift out
150 * first argument for non-initial connections.
151 */
152 async_sess_args_set(csess, iface, arg3, 0);
153
154 return csess;
155}
156
157errno_t ns_ping(void)
158{
159 async_sess_t *sess = get_session_primary();
160 if (sess == NULL)
161 return EIO;
162
163 async_exch_t *exch = async_exchange_begin(sess);
164 errno_t rc = async_req_0_0(exch, NS_PING);
165 async_exchange_end(exch);
166
167 return rc;
168}
169
170
171async_sess_t *get_session_primary(void)
172{
173 async_exch_t *exch;
174
175 if (sess_primary == NULL) {
176 exch = async_exchange_begin(&session_primary);
177 sess_primary = async_connect_me_to(exch, 0, 0, 0);
178 async_exchange_end(exch);
179 if (sess_primary == NULL)
180 return NULL;
181 }
182
183 return sess_primary;
184}
185
186/** @}
187 */
Note: See TracBrowser for help on using the repository browser.