1 | /*
|
---|
2 | * Copyright (c) 2015 Michal Koutny
|
---|
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 |
|
---|
35 | #include <async.h>
|
---|
36 | #include <errno.h>
|
---|
37 | #include <ipc/common.h>
|
---|
38 | #include <ipc/taskman.h>
|
---|
39 | #include <task.h>
|
---|
40 | #include <taskman.h>
|
---|
41 |
|
---|
42 | #include "private/async.h"
|
---|
43 | #include "private/taskman.h"
|
---|
44 |
|
---|
45 | async_sess_t *session_taskman = NULL;
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * Private functions
|
---|
49 | */
|
---|
50 |
|
---|
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);
|
---|
62 | assert(exch);
|
---|
63 |
|
---|
64 | return exch;
|
---|
65 | }
|
---|
66 |
|
---|
67 | void taskman_exchange_end(async_exch_t *exch)
|
---|
68 | {
|
---|
69 | async_exchange_end(exch);
|
---|
70 | }
|
---|
71 |
|
---|
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);
|
---|
87 | sess = async_connect_me_to(exch, INTERFACE_ANY,
|
---|
88 | TASKMAN_NEW_TASK, 0);
|
---|
89 | async_exchange_end(exch);
|
---|
90 | }
|
---|
91 |
|
---|
92 | return sess;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /** Ask taskman to pass/share its NS */
|
---|
96 | async_sess_t *taskman_session_ns(void)
|
---|
97 | {
|
---|
98 | async_exch_t *exch = taskman_exchange_begin();
|
---|
99 |
|
---|
100 | async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
|
---|
101 | TASKMAN_CONNECT_TO_NS, 0);
|
---|
102 | taskman_exchange_end(exch);
|
---|
103 |
|
---|
104 | return sess;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** Ask taskman to connect to (a new) loader instance */
|
---|
108 | async_sess_t *taskman_session_loader(void)
|
---|
109 | {
|
---|
110 | async_exch_t *exch = taskman_exchange_begin();
|
---|
111 | async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
|
---|
112 | TASKMAN_CONNECT_TO_LOADER, 0);
|
---|
113 | taskman_exchange_end(exch);
|
---|
114 |
|
---|
115 | return sess;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * Public functions
|
---|
120 | */
|
---|
121 |
|
---|
122 | async_sess_t *taskman_get_session(void)
|
---|
123 | {
|
---|
124 | return session_taskman;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /** Introduce as loader to taskman
|
---|
128 | *
|
---|
129 | * @return EOK on success, otherwise propagated error code
|
---|
130 | */
|
---|
131 | errno_t taskman_intro_loader(void)
|
---|
132 | {
|
---|
133 | async_exch_t *exch = taskman_exchange_begin();
|
---|
134 | errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, TASKMAN_LOADER_CALLBACK, 0);
|
---|
135 | taskman_exchange_end(exch);
|
---|
136 |
|
---|
137 | return rc;
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Tell taskman we are his NS
|
---|
141 | *
|
---|
142 | * @return EOK on success, otherwise propagated error code
|
---|
143 | */
|
---|
144 | errno_t taskman_intro_ns(void)
|
---|
145 | {
|
---|
146 | async_exch_t *exch = taskman_exchange_begin();
|
---|
147 | aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
|
---|
148 |
|
---|
149 | errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, 0, 0);
|
---|
150 | taskman_exchange_end(exch);
|
---|
151 |
|
---|
152 | if (rc != EOK) {
|
---|
153 | async_forget(req);
|
---|
154 | return rc;
|
---|
155 | }
|
---|
156 |
|
---|
157 | errno_t retval;
|
---|
158 | async_wait_for(req, &retval);
|
---|
159 | return retval;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /** @}
|
---|
163 | */
|
---|