[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>
|
---|
[012dd8e] | 40 |
|
---|
| 41 | #include "private/taskman.h"
|
---|
| 42 |
|
---|
| 43 | static async_sess_t *session_ns = NULL;
|
---|
| 44 |
|
---|
| 45 | static async_exch_t *ns_exchange_begin(void)
|
---|
| 46 | {
|
---|
| 47 | /* Lazily connect to our NS */
|
---|
| 48 | if (session_ns == NULL) {
|
---|
| 49 | session_ns = taskman_session_ns();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | async_exch_t *exch = async_exchange_begin(session_ns);
|
---|
| 53 | return exch;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | static void ns_exchange_end(async_exch_t *exch)
|
---|
| 57 | {
|
---|
| 58 | async_exchange_end(exch);
|
---|
| 59 | }
|
---|
[007e6efa] | 60 |
|
---|
[9b1baac] | 61 | errno_t service_register(service_t service, iface_t iface,
|
---|
| 62 | async_port_handler_t handler, void *data)
|
---|
[007e6efa] | 63 | {
|
---|
[9b1baac] | 64 | port_id_t port;
|
---|
| 65 | errno_t rc = async_create_port(iface, handler, data, &port);
|
---|
| 66 | if (rc != EOK)
|
---|
| 67 | return rc;
|
---|
| 68 |
|
---|
[012dd8e] | 69 | async_exch_t *exch = ns_exchange_begin();
|
---|
[9b1baac] | 70 |
|
---|
[7b616e2] | 71 | ipc_call_t answer;
|
---|
[9b1baac] | 72 | aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
|
---|
| 73 | rc = async_connect_to_me(exch, iface, service, 0);
|
---|
| 74 |
|
---|
[012dd8e] | 75 | ns_exchange_end(exch);
|
---|
[9b1baac] | 76 |
|
---|
| 77 | if (rc != EOK) {
|
---|
| 78 | async_forget(req);
|
---|
| 79 | return rc;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | errno_t retval;
|
---|
| 83 | async_wait_for(req, &retval);
|
---|
| 84 | return rc;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | errno_t service_register_broker(service_t service, async_port_handler_t handler,
|
---|
| 88 | void *data)
|
---|
| 89 | {
|
---|
| 90 | async_set_fallback_port_handler(handler, data);
|
---|
[a35b458] | 91 |
|
---|
[241f1985] | 92 | async_exch_t *exch = ns_exchange_begin();
|
---|
[9b1baac] | 93 |
|
---|
| 94 | ipc_call_t answer;
|
---|
| 95 | aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
|
---|
| 96 | errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
|
---|
[a35b458] | 97 |
|
---|
[241f1985] | 98 | ns_exchange_end(exch);
|
---|
[a35b458] | 99 |
|
---|
[7b616e2] | 100 | if (rc != EOK) {
|
---|
| 101 | async_forget(req);
|
---|
| 102 | return rc;
|
---|
| 103 | }
|
---|
[a35b458] | 104 |
|
---|
[9b1baac] | 105 | errno_t retval;
|
---|
[7b616e2] | 106 | async_wait_for(req, &retval);
|
---|
[79ae36dd] | 107 | return rc;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[f9b2cb4c] | 110 | async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
|
---|
[0dd16778] | 111 | {
|
---|
[012dd8e] | 112 | async_exch_t *exch = ns_exchange_begin();
|
---|
[7b616e2] | 113 | if (exch == NULL)
|
---|
[0dd16778] | 114 | return NULL;
|
---|
[a35b458] | 115 |
|
---|
[012dd8e] | 116 | async_sess_t *sess =
|
---|
[914c693] | 117 | async_connect_me_to(exch, iface, service, arg3);
|
---|
[012dd8e] | 118 | ns_exchange_end(exch);
|
---|
[a35b458] | 119 |
|
---|
[012dd8e] | 120 | if (sess == NULL)
|
---|
[0dd16778] | 121 | return NULL;
|
---|
[a35b458] | 122 |
|
---|
[0dd16778] | 123 | /*
|
---|
| 124 | * FIXME Ugly hack to work around limitation of implementing
|
---|
| 125 | * parallel exchanges using multiple connections. Shift out
|
---|
| 126 | * first argument for non-initial connections.
|
---|
| 127 | */
|
---|
[012dd8e] | 128 | async_sess_args_set(sess, iface, arg3, 0);
|
---|
[a35b458] | 129 |
|
---|
[241f1985] | 130 | return sess;
|
---|
[0dd16778] | 131 | }
|
---|
| 132 |
|
---|
[f9b2cb4c] | 133 | async_sess_t *service_connect_blocking(service_t service, iface_t iface,
|
---|
| 134 | sysarg_t arg3)
|
---|
[566992e1] | 135 | {
|
---|
[012dd8e] | 136 | async_exch_t *exch = ns_exchange_begin();
|
---|
| 137 | async_sess_t *sess =
|
---|
[914c693] | 138 | async_connect_me_to_blocking(exch, iface, service, arg3);
|
---|
[012dd8e] | 139 | ns_exchange_end(exch);
|
---|
[a35b458] | 140 |
|
---|
[012dd8e] | 141 | if (sess == NULL)
|
---|
[566992e1] | 142 | return NULL;
|
---|
[a35b458] | 143 |
|
---|
[566992e1] | 144 | /*
|
---|
| 145 | * FIXME Ugly hack to work around limitation of implementing
|
---|
| 146 | * parallel exchanges using multiple connections. Shift out
|
---|
| 147 | * first argument for non-initial connections.
|
---|
| 148 | */
|
---|
[012dd8e] | 149 | async_sess_args_set(sess, iface, arg3, 0);
|
---|
[a35b458] | 150 |
|
---|
[012dd8e] | 151 | return sess;
|
---|
[566992e1] | 152 | }
|
---|
| 153 |
|
---|
[b7fd2a0] | 154 | errno_t ns_ping(void)
|
---|
[007e6efa] | 155 | {
|
---|
[241f1985] | 156 | async_exch_t *exch = ns_exchange_begin();
|
---|
[b7fd2a0] | 157 | errno_t rc = async_req_0_0(exch, NS_PING);
|
---|
[012dd8e] | 158 | ns_exchange_end(exch);
|
---|
[a35b458] | 159 |
|
---|
[79ae36dd] | 160 | return rc;
|
---|
[007e6efa] | 161 | }
|
---|
| 162 |
|
---|
| 163 | /** @}
|
---|
| 164 | */
|
---|