source: mainline/uspace/lib/c/generic/taskman.c@ ae004bc

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

Correcting IPC calls introduced with taskman

The new PHONE_INITIAL has been corrected to make use of CAP_NIL.
Removing unneeded interfaces which were introduced during the
merging

  • Property mode set to 100644
File size: 4.2 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#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
45async_sess_t *session_taskman = NULL;
46
47/*
48 * Private functions
49 */
50
51void __task_init(async_sess_t *sess)
52{
53 assert(session_taskman == NULL);
54 session_taskman = sess;
55}
56
57async_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
67void taskman_exchange_end(async_exch_t *exch)
68{
69 async_exchange_end(exch);
70}
71#include <stdio.h>
72/** Wrap PHONE_INITIAL with session and introduce to taskman
73 */
74async_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 aid_t req = async_send_0(exch, TASKMAN_NEW_TASK, NULL);
88 async_exchange_end(exch);
89
90 if (req) {
91 async_forget(req);
92 }
93 }
94
95 return sess;
96}
97
98/** Ask taskman to pass/share its NS */
99async_sess_t *taskman_session_ns(void)
100{
101 async_exch_t *exch = taskman_exchange_begin();
102
103 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
104 TASKMAN_CONNECT_TO_NS, 0);
105 taskman_exchange_end(exch);
106
107 return sess;
108}
109
110/** Ask taskman to connect to (a new) loader instance */
111async_sess_t *taskman_session_loader(void)
112{
113 async_exch_t *exch = taskman_exchange_begin();
114 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
115 TASKMAN_CONNECT_TO_LOADER, 0);
116 taskman_exchange_end(exch);
117
118 return sess;
119}
120
121/*
122 * Public functions
123 */
124
125async_sess_t *taskman_get_session(void)
126{
127 return session_taskman;
128}
129
130/** Introduce as loader to taskman
131 *
132 * @return EOK on success, otherwise propagated error code
133 */
134errno_t taskman_intro_loader(void)
135{
136 async_exch_t *exch = taskman_exchange_begin();
137 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, TASKMAN_LOADER_CALLBACK, 0);
138 taskman_exchange_end(exch);
139
140 return rc;
141}
142
143/** Tell taskman we are his NS
144 *
145 * @return EOK on success, otherwise propagated error code
146 */
147errno_t taskman_intro_ns(void)
148{
149 async_exch_t *exch = taskman_exchange_begin();
150 aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
151
152 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, 0, 0);
153 taskman_exchange_end(exch);
154
155 if (rc != EOK) {
156 async_forget(req);
157 return rc;
158 }
159
160 errno_t retval;
161 async_wait_for(req, &retval);
162 return retval;
163}
164
165/** @}
166 */
Note: See TracBrowser for help on using the repository browser.