[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 |
|
---|
[b7fd2a0] | 48 | errno_t service_register(service_t service)
|
---|
[007e6efa] | 49 | {
|
---|
[b7fd2a0] | 50 | errno_t retval;
|
---|
[7b616e2] | 51 | ipc_call_t answer;
|
---|
[a35b458] | 52 |
|
---|
[7b616e2] | 53 | async_sess_t *sess = ns_session_get();
|
---|
| 54 | if (sess == NULL)
|
---|
| 55 | return EIO;
|
---|
[a35b458] | 56 |
|
---|
[7b616e2] | 57 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 58 | aid_t req = async_send_1(exch, NS_REGISTER, service, &answer);
|
---|
[b7fd2a0] | 59 | errno_t rc = async_connect_to_me(exch, 0, service, 0);
|
---|
[a35b458] | 60 |
|
---|
[79ae36dd] | 61 | async_exchange_end(exch);
|
---|
[a35b458] | 62 |
|
---|
[7b616e2] | 63 | if (rc != EOK) {
|
---|
| 64 | async_forget(req);
|
---|
| 65 | return rc;
|
---|
| 66 | }
|
---|
[a35b458] | 67 |
|
---|
[7b616e2] | 68 | async_wait_for(req, &retval);
|
---|
[79ae36dd] | 69 | return rc;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[f9b2cb4c] | 72 | async_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;
|
---|
[a35b458] | 77 |
|
---|
[7b616e2] | 78 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 79 | if (exch == NULL)
|
---|
[0dd16778] | 80 | return NULL;
|
---|
[a35b458] | 81 |
|
---|
[7b616e2] | 82 | async_sess_t *csess =
|
---|
[0dd16778] | 83 | async_connect_me_to_iface(exch, iface, service, arg3);
|
---|
| 84 | async_exchange_end(exch);
|
---|
[a35b458] | 85 |
|
---|
[7b616e2] | 86 | if (csess == NULL)
|
---|
[0dd16778] | 87 | return NULL;
|
---|
[a35b458] | 88 |
|
---|
[0dd16778] | 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);
|
---|
[a35b458] | 95 |
|
---|
[7b616e2] | 96 | return csess;
|
---|
[0dd16778] | 97 | }
|
---|
| 98 |
|
---|
[f9b2cb4c] | 99 | async_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;
|
---|
[a35b458] | 105 |
|
---|
[7b616e2] | 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);
|
---|
[a35b458] | 110 |
|
---|
[7b616e2] | 111 | if (csess == NULL)
|
---|
[566992e1] | 112 | return NULL;
|
---|
[a35b458] | 113 |
|
---|
[566992e1] | 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);
|
---|
[a35b458] | 120 |
|
---|
[7b616e2] | 121 | return csess;
|
---|
[566992e1] | 122 | }
|
---|
| 123 |
|
---|
[b1bd89ea] | 124 |
|
---|
[b7fd2a0] | 125 | errno_t ns_ping(void)
|
---|
[007e6efa] | 126 | {
|
---|
[7b616e2] | 127 | async_sess_t *sess = ns_session_get();
|
---|
| 128 | if (sess == NULL)
|
---|
| 129 | return EIO;
|
---|
[a35b458] | 130 |
|
---|
[7b616e2] | 131 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 132 | errno_t rc = async_req_0_0(exch, NS_PING);
|
---|
[79ae36dd] | 133 | async_exchange_end(exch);
|
---|
[a35b458] | 134 |
|
---|
[79ae36dd] | 135 | return rc;
|
---|
[007e6efa] | 136 | }
|
---|
| 137 |
|
---|
[b7fd2a0] | 138 | errno_t 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;
|
---|
[a35b458] | 144 |
|
---|
[7b616e2] | 145 | exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 146 | errno_t rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
|
---|
[79ae36dd] | 147 | async_exchange_end(exch);
|
---|
[a35b458] | 148 |
|
---|
[79ae36dd] | 149 | return rc;
|
---|
[007e6efa] | 150 | }
|
---|
| 151 |
|
---|
[7b616e2] | 152 | async_sess_t *ns_session_get(void)
|
---|
| 153 | {
|
---|
| 154 | async_exch_t *exch;
|
---|
[a35b458] | 155 |
|
---|
[7b616e2] | 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 | }
|
---|
[a35b458] | 163 |
|
---|
[7b616e2] | 164 | return sess_ns;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[007e6efa] | 167 | /** @}
|
---|
| 168 | */
|
---|