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