[40313e4] | 1 | /*
|
---|
[0a8f070] | 2 | * Copyright (c) 2015 Michal Koutny
|
---|
[40313e4] | 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 |
|
---|
[0a8f070] | 29 | /** @addtogroup libc
|
---|
[40313e4] | 30 | * @{
|
---|
| 31 | */
|
---|
[0a8f070] | 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[012dd8e] | 35 |
|
---|
| 36 | #include <async.h>
|
---|
[0a8f070] | 37 | #include <errno.h>
|
---|
[012dd8e] | 38 | #include <ipc/common.h>
|
---|
[0a8f070] | 39 | #include <ipc/taskman.h>
|
---|
[012dd8e] | 40 | #include <task.h>
|
---|
[0a8f070] | 41 | #include <taskman.h>
|
---|
| 42 |
|
---|
[012dd8e] | 43 | #include "private/async.h"
|
---|
| 44 | #include "private/taskman.h"
|
---|
[0a8f070] | 45 |
|
---|
[012dd8e] | 46 | async_sess_t *session_taskman = NULL;
|
---|
[0a8f070] | 47 |
|
---|
[4667b5c] | 48 | /*
|
---|
| 49 | * Private functions
|
---|
| 50 | */
|
---|
| 51 |
|
---|
[012dd8e] | 52 | void __task_init(async_sess_t *sess)
|
---|
| 53 | {
|
---|
| 54 | assert(session_taskman == NULL);
|
---|
| 55 | session_taskman = sess;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | async_exch_t *taskman_exchange_begin(void)
|
---|
| 59 | {
|
---|
| 60 | assert(session_taskman);
|
---|
| 61 |
|
---|
| 62 | async_exch_t *exch = async_exchange_begin(session_taskman);
|
---|
| 63 | return exch;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | void taskman_exchange_end(async_exch_t *exch)
|
---|
[0a8f070] | 67 | {
|
---|
| 68 | async_exchange_end(exch);
|
---|
[012dd8e] | 69 | }
|
---|
[0a8f070] | 70 |
|
---|
[012dd8e] | 71 | /** Wrap PHONE_INITIAL with session and introduce to taskman
|
---|
| 72 | */
|
---|
| 73 | async_sess_t *taskman_connect(void)
|
---|
| 74 | {
|
---|
| 75 | /*
|
---|
| 76 | * EXCHANGE_ATOMIC would require single calls only,
|
---|
| 77 | * EXCHANGE_PARALLEL not sure about implementation via multiple phones,
|
---|
| 78 | * >EXCHANGE_SERIALIZE perhaphs no harm, except the client serialization
|
---|
| 79 | */
|
---|
| 80 | const exch_mgmt_t mgmt = EXCHANGE_SERIALIZE;
|
---|
| 81 | async_sess_t *sess = create_session(PHONE_INITIAL, mgmt, 0, 0, 0);
|
---|
| 82 |
|
---|
| 83 | if (sess != NULL) {
|
---|
| 84 | /* Introduce ourselves and ignore answer */
|
---|
| 85 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 86 | aid_t req = async_send_0(exch, TASKMAN_NEW_TASK, NULL);
|
---|
| 87 | async_exchange_end(exch);
|
---|
| 88 |
|
---|
| 89 | if (req) {
|
---|
| 90 | async_forget(req);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | return sess;
|
---|
[0a8f070] | 95 | }
|
---|
[40313e4] | 96 |
|
---|
[012dd8e] | 97 | /** Ask taskman to pass/share its NS */
|
---|
| 98 | async_sess_t *taskman_session_ns(void)
|
---|
[0a8f070] | 99 | {
|
---|
[012dd8e] | 100 | assert(session_taskman);
|
---|
| 101 |
|
---|
| 102 | async_exch_t *exch = async_exchange_begin(session_taskman);
|
---|
| 103 | assert(exch);
|
---|
| 104 |
|
---|
| 105 | async_sess_t *sess = async_connect_me_to(EXCHANGE_ATOMIC,
|
---|
| 106 | exch, TASKMAN_CONNECT_TO_NS, 0, 0);
|
---|
[0a8f070] | 107 | async_exchange_end(exch);
|
---|
[40313e4] | 108 |
|
---|
[012dd8e] | 109 | return sess;
|
---|
[0a8f070] | 110 | }
|
---|
| 111 |
|
---|
[012dd8e] | 112 | /** Ask taskman to connect to (a new) loader instance */
|
---|
| 113 | async_sess_t *taskman_session_loader(void)
|
---|
| 114 | {
|
---|
| 115 | assert(session_taskman);
|
---|
| 116 |
|
---|
| 117 | async_exch_t *exch = async_exchange_begin(session_taskman);
|
---|
| 118 | async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE,
|
---|
| 119 | exch, TASKMAN_CONNECT_TO_LOADER, 0, 0);
|
---|
| 120 | async_exchange_end(exch);
|
---|
| 121 |
|
---|
| 122 | return sess;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[4667b5c] | 125 | /*
|
---|
| 126 | * Public functions
|
---|
| 127 | */
|
---|
| 128 |
|
---|
| 129 | async_sess_t *taskman_get_session(void)
|
---|
| 130 | {
|
---|
| 131 | return session_taskman;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[012dd8e] | 134 | /** Introduce as loader to taskman
|
---|
[0a8f070] | 135 | *
|
---|
[012dd8e] | 136 | * @return EOK on success, otherwise propagated error code
|
---|
| 137 | */
|
---|
| 138 | int taskman_intro_loader(void)
|
---|
| 139 | {
|
---|
| 140 | assert(session_taskman);
|
---|
| 141 |
|
---|
| 142 | async_exch_t *exch = async_exchange_begin(session_taskman);
|
---|
| 143 | int rc = async_connect_to_me(
|
---|
| 144 | exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL);
|
---|
| 145 | async_exchange_end(exch);
|
---|
| 146 |
|
---|
| 147 | return rc;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | /** Tell taskman we are his NS
|
---|
[0a8f070] | 151 | *
|
---|
[012dd8e] | 152 | * @return EOK on success, otherwise propagated error code
|
---|
[0a8f070] | 153 | */
|
---|
[012dd8e] | 154 | int taskman_intro_ns(void)
|
---|
[0a8f070] | 155 | {
|
---|
[012dd8e] | 156 | assert(session_taskman);
|
---|
| 157 |
|
---|
| 158 | async_exch_t *exch = async_exchange_begin(session_taskman);
|
---|
| 159 | aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
|
---|
| 160 |
|
---|
| 161 | int rc = async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
|
---|
| 162 | taskman_exchange_end(exch);
|
---|
| 163 |
|
---|
[0a8f070] | 164 | if (rc != EOK) {
|
---|
[012dd8e] | 165 | return rc;
|
---|
[0a8f070] | 166 | }
|
---|
[40313e4] | 167 |
|
---|
[012dd8e] | 168 | sysarg_t retval;
|
---|
| 169 | async_wait_for(req, &retval);
|
---|
| 170 | return retval;
|
---|
| 171 | }
|
---|
[40313e4] | 172 |
|
---|
[012dd8e] | 173 |
|
---|
| 174 |
|
---|
[0a8f070] | 175 | /** @}
|
---|
[40313e4] | 176 | */
|
---|