[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 | */
|
---|
| 46 | static async_sess_t *sess_ns = NULL;
|
---|
| 47 |
|
---|
[9b1baac] | 48 | errno_t service_register(service_t service, iface_t iface,
|
---|
| 49 | async_port_handler_t handler, void *data)
|
---|
[007e6efa] | 50 | {
|
---|
[9b1baac] | 51 | async_sess_t *sess = ns_session_get();
|
---|
| 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 |
|
---|
| 78 | errno_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 |
|
---|
[7b616e2] | 83 | async_sess_t *sess = ns_session_get();
|
---|
| 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] | 105 | async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
|
---|
[0dd16778] | 106 | {
|
---|
[7b616e2] | 107 | async_sess_t *sess = ns_session_get();
|
---|
| 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] | 132 | async_sess_t *service_connect_blocking(service_t service, iface_t iface,
|
---|
| 133 | sysarg_t arg3)
|
---|
[566992e1] | 134 | {
|
---|
[7b616e2] | 135 | async_sess_t *sess = ns_session_get();
|
---|
| 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 |
|
---|
[b1bd89ea] | 157 |
|
---|
[b7fd2a0] | 158 | errno_t ns_ping(void)
|
---|
[007e6efa] | 159 | {
|
---|
[7b616e2] | 160 | async_sess_t *sess = ns_session_get();
|
---|
| 161 | if (sess == NULL)
|
---|
| 162 | return EIO;
|
---|
[a35b458] | 163 |
|
---|
[7b616e2] | 164 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 165 | errno_t rc = async_req_0_0(exch, NS_PING);
|
---|
[79ae36dd] | 166 | async_exchange_end(exch);
|
---|
[a35b458] | 167 |
|
---|
[79ae36dd] | 168 | return rc;
|
---|
[007e6efa] | 169 | }
|
---|
| 170 |
|
---|
[b7fd2a0] | 171 | errno_t ns_intro(task_id_t id)
|
---|
[007e6efa] | 172 | {
|
---|
[7b616e2] | 173 | async_exch_t *exch;
|
---|
| 174 | async_sess_t *sess = ns_session_get();
|
---|
| 175 | if (sess == NULL)
|
---|
| 176 | return EIO;
|
---|
[a35b458] | 177 |
|
---|
[7b616e2] | 178 | exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 179 | errno_t rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
|
---|
[79ae36dd] | 180 | async_exchange_end(exch);
|
---|
[a35b458] | 181 |
|
---|
[79ae36dd] | 182 | return rc;
|
---|
[007e6efa] | 183 | }
|
---|
| 184 |
|
---|
[7b616e2] | 185 | async_sess_t *ns_session_get(void)
|
---|
| 186 | {
|
---|
| 187 | async_exch_t *exch;
|
---|
[a35b458] | 188 |
|
---|
[7b616e2] | 189 | if (sess_ns == NULL) {
|
---|
[9f272d9] | 190 | exch = async_exchange_begin(&session_ns);
|
---|
[914c693] | 191 | sess_ns = async_connect_me_to(exch, 0, 0, 0);
|
---|
[7b616e2] | 192 | async_exchange_end(exch);
|
---|
| 193 | if (sess_ns == NULL)
|
---|
| 194 | return NULL;
|
---|
| 195 | }
|
---|
[a35b458] | 196 |
|
---|
[7b616e2] | 197 | return sess_ns;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[007e6efa] | 200 | /** @}
|
---|
| 201 | */
|
---|