source: mainline/uspace/lib/c/generic/taskman.c@ 2f04bdd

Last change on this file since 2f04bdd 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
RevLine 
[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]45async_sess_t *session_taskman = NULL;
[0a8f070]46
[4667b5c]47/*
48 * Private functions
49 */
50
[012dd8e]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);
[5be6361]62 assert(exch);
63
[012dd8e]64 return exch;
65}
66
67void taskman_exchange_end(async_exch_t *exch)
[0a8f070]68{
69 async_exchange_end(exch);
[012dd8e]70}
[7ffdcbd]71#include <stdio.h>
[012dd8e]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);
[102f641]89
[012dd8e]90 if (req) {
91 async_forget(req);
92 }
93 }
94
95 return sess;
[0a8f070]96}
[40313e4]97
[012dd8e]98/** Ask taskman to pass/share its NS */
99async_sess_t *taskman_session_ns(void)
[0a8f070]100{
[5be6361]101 async_exch_t *exch = taskman_exchange_begin();
[012dd8e]102
[7ffdcbd]103 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
[102f641]104 TASKMAN_CONNECT_TO_NS, 0);
[5be6361]105 taskman_exchange_end(exch);
[40313e4]106
[012dd8e]107 return sess;
[0a8f070]108}
109
[012dd8e]110/** Ask taskman to connect to (a new) loader instance */
111async_sess_t *taskman_session_loader(void)
112{
[5be6361]113 async_exch_t *exch = taskman_exchange_begin();
[7ffdcbd]114 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_ANY,
[241f1985]115 TASKMAN_CONNECT_TO_LOADER, 0);
[5be6361]116 taskman_exchange_end(exch);
[012dd8e]117
118 return sess;
119}
120
[4667b5c]121/*
122 * Public functions
123 */
124
125async_sess_t *taskman_get_session(void)
126{
127 return session_taskman;
128}
129
[012dd8e]130/** Introduce as loader to taskman
[0a8f070]131 *
[012dd8e]132 * @return EOK on success, otherwise propagated error code
133 */
[241f1985]134errno_t taskman_intro_loader(void)
[012dd8e]135{
[5be6361]136 async_exch_t *exch = taskman_exchange_begin();
[7ffdcbd]137 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, TASKMAN_LOADER_CALLBACK, 0);
[5be6361]138 taskman_exchange_end(exch);
[012dd8e]139
140 return rc;
141}
142
143/** Tell taskman we are his NS
[0a8f070]144 *
[012dd8e]145 * @return EOK on success, otherwise propagated error code
[0a8f070]146 */
[241f1985]147errno_t taskman_intro_ns(void)
[0a8f070]148{
[5be6361]149 async_exch_t *exch = taskman_exchange_begin();
[012dd8e]150 aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
151
[7ffdcbd]152 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, 0, 0);
[012dd8e]153 taskman_exchange_end(exch);
154
[0a8f070]155 if (rc != EOK) {
[7ffdcbd]156 async_forget(req);
[012dd8e]157 return rc;
[0a8f070]158 }
[40313e4]159
[241f1985]160 errno_t retval;
[012dd8e]161 async_wait_for(req, &retval);
162 return retval;
163}
[40313e4]164
[0a8f070]165/** @}
[40313e4]166 */
Note: See TracBrowser for help on using the repository browser.