source: mainline/uspace/lib/c/generic/taskman.c@ 241f1985

Last change on this file since 241f1985 was 241f1985, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

  • Property mode set to 100644
File size: 4.3 KB
Line 
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
36#include <async.h>
37#include <errno.h>
38#include <ipc/common.h>
39#include <ipc/taskman.h>
40#include <task.h>
41#include <taskman.h>
42
43#include "private/async.h"
44#include "private/taskman.h"
45
46async_sess_t *session_taskman = NULL;
47
48/*
49 * Private functions
50 */
51
52void __task_init(async_sess_t *sess)
53{
54 assert(session_taskman == NULL);
55 session_taskman = sess;
56}
57
58async_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
66void taskman_exchange_end(async_exch_t *exch)
67{
68 async_exchange_end(exch);
69}
70
71/** Wrap PHONE_INITIAL with session and introduce to taskman
72 */
73async_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;
95}
96
97/** Ask taskman to pass/share its NS */
98async_sess_t *taskman_session_ns(void)
99{
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(exch, INTERFACE_NS,
106 TASKMAN_CONNECT_TO_NS, 0);
107 async_exchange_end(exch);
108
109 return sess;
110}
111
112/** Ask taskman to connect to (a new) loader instance */
113async_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(exch, INTERFACE_LOADER,
119 TASKMAN_CONNECT_TO_LOADER, 0);
120 async_exchange_end(exch);
121
122 return sess;
123}
124
125/*
126 * Public functions
127 */
128
129async_sess_t *taskman_get_session(void)
130{
131 return session_taskman;
132}
133
134/** Introduce as loader to taskman
135 *
136 * @return EOK on success, otherwise propagated error code
137 */
138errno_t taskman_intro_loader(void)
139{
140 assert(session_taskman);
141
142 async_exch_t *exch = async_exchange_begin(session_taskman);
143 errno_t rc = async_connect_to_me(exch, INTERFACE_LOADER, TASKMAN_LOADER_CALLBACK, 0);
144 async_exchange_end(exch);
145
146 return rc;
147}
148
149/** Tell taskman we are his NS
150 *
151 * @return EOK on success, otherwise propagated error code
152 */
153errno_t taskman_intro_ns(void)
154{
155 assert(session_taskman);
156
157 async_exch_t *exch = async_exchange_begin(session_taskman);
158 aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
159
160 errno_t rc = async_connect_to_me(exch, INTERFACE_NS, 0, 0);
161 taskman_exchange_end(exch);
162
163 if (rc != EOK) {
164 return rc;
165 }
166
167 errno_t retval;
168 async_wait_for(req, &retval);
169 return retval;
170}
171
172
173
174/** @}
175 */
Note: See TracBrowser for help on using the repository browser.