source: mainline/uspace/lib/c/generic/ns.c@ 0a8f070

Last change on this file since 0a8f070 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
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/*
[0a8f070]43 * XXX ns does not know about session_primary, so we create an extra session for
[7b616e2]44 * actual communicaton
45 */
[0a8f070]46static async_sess_t *sess_primary = NULL;
[7b616e2]47
[9b1baac]48errno_t service_register(service_t service, iface_t iface,
49 async_port_handler_t handler, void *data)
[007e6efa]50{
[0a8f070]51 async_sess_t *sess = get_session_primary();
[9b1baac]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
[7b616e2]62 ipc_call_t answer;
[9b1baac]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);
[a35b458]82
[0a8f070]83 async_sess_t *sess = get_session_primary();
[7b616e2]84 if (sess == NULL)
85 return EIO;
[a35b458]86
[7b616e2]87 async_exch_t *exch = async_exchange_begin(sess);
[9b1baac]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);
[a35b458]92
[79ae36dd]93 async_exchange_end(exch);
[a35b458]94
[7b616e2]95 if (rc != EOK) {
96 async_forget(req);
97 return rc;
98 }
[a35b458]99
[9b1baac]100 errno_t retval;
[7b616e2]101 async_wait_for(req, &retval);
[79ae36dd]102 return rc;
103}
104
[f9b2cb4c]105async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
[0dd16778]106{
[0a8f070]107 async_sess_t *sess = get_session_primary();
[7b616e2]108 if (sess == NULL)
109 return NULL;
[a35b458]110
[7b616e2]111 async_exch_t *exch = async_exchange_begin(sess);
112 if (exch == NULL)
[0dd16778]113 return NULL;
[a35b458]114
[7b616e2]115 async_sess_t *csess =
[914c693]116 async_connect_me_to(exch, iface, service, arg3);
[0dd16778]117 async_exchange_end(exch);
[a35b458]118
[7b616e2]119 if (csess == NULL)
[0dd16778]120 return NULL;
[a35b458]121
[0dd16778]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 */
[7b616e2]127 async_sess_args_set(csess, iface, arg3, 0);
[a35b458]128
[7b616e2]129 return csess;
[0dd16778]130}
131
[f9b2cb4c]132async_sess_t *service_connect_blocking(service_t service, iface_t iface,
133 sysarg_t arg3)
[566992e1]134{
[0a8f070]135 async_sess_t *sess = get_session_primary();
[7b616e2]136 if (sess == NULL)
137 return NULL;
[a35b458]138
[7b616e2]139 async_exch_t *exch = async_exchange_begin(sess);
140 async_sess_t *csess =
[914c693]141 async_connect_me_to_blocking(exch, iface, service, arg3);
[566992e1]142 async_exchange_end(exch);
[a35b458]143
[7b616e2]144 if (csess == NULL)
[566992e1]145 return NULL;
[a35b458]146
[566992e1]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 */
[7b616e2]152 async_sess_args_set(csess, iface, arg3, 0);
[a35b458]153
[7b616e2]154 return csess;
[566992e1]155}
156
[b7fd2a0]157errno_t ns_ping(void)
[007e6efa]158{
[0a8f070]159 async_sess_t *sess = get_session_primary();
[7b616e2]160 if (sess == NULL)
161 return EIO;
[a35b458]162
[7b616e2]163 async_exch_t *exch = async_exchange_begin(sess);
[b7fd2a0]164 errno_t rc = async_req_0_0(exch, NS_PING);
[79ae36dd]165 async_exchange_end(exch);
[a35b458]166
[79ae36dd]167 return rc;
[007e6efa]168}
169
170
[0a8f070]171async_sess_t *get_session_primary(void)
[7b616e2]172{
173 async_exch_t *exch;
[a35b458]174
[0a8f070]175 if (sess_primary == NULL) {
176 exch = async_exchange_begin(&session_primary);
177 sess_primary = async_connect_me_to(exch, 0, 0, 0);
[7b616e2]178 async_exchange_end(exch);
[0a8f070]179 if (sess_primary == NULL)
[7b616e2]180 return NULL;
181 }
[a35b458]182
[0a8f070]183 return sess_primary;
[7b616e2]184}
185
[007e6efa]186/** @}
187 */
Note: See TracBrowser for help on using the repository browser.