| 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 <errno.h>
|
|---|
| 36 | #include <ipc/taskman.h>
|
|---|
| 37 | #include <taskman.h>
|
|---|
| 38 |
|
|---|
| 39 | #include <stdio.h>
|
|---|
| 40 |
|
|---|
| 41 | //TODO better filename?
|
|---|
| 42 | #include "private/ns.h"
|
|---|
| 43 |
|
|---|
| 44 | static int taskman_ask_callback(async_sess_t *session_tm)
|
|---|
| 45 | {
|
|---|
| 46 | async_exch_t *exch = async_exchange_begin(session_tm);
|
|---|
| 47 | int rc = async_connect_to_me(
|
|---|
| 48 | exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL);
|
|---|
| 49 | async_exchange_end(exch);
|
|---|
| 50 |
|
|---|
| 51 | return rc;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | static async_sess_t *taskman_connect_to_ns(async_sess_t *session_tm)
|
|---|
| 55 | {
|
|---|
| 56 | async_exch_t *exch = async_exchange_begin(session_tm);
|
|---|
| 57 | async_sess_t *session_ns = async_connect_me_to(EXCHANGE_ATOMIC,
|
|---|
| 58 | exch, TASKMAN_LOADER_TO_NS, 0, 0);
|
|---|
| 59 | async_exchange_end(exch);
|
|---|
| 60 |
|
|---|
| 61 | return session_ns;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /** Set up phones upon being spawned by taskman
|
|---|
| 65 | *
|
|---|
| 66 | * Assumes primary session exists that is connected to taskman.
|
|---|
| 67 | * After handshake, taskman is connected to us (see, it's opposite) and broker
|
|---|
| 68 | * session is set up according to taskman.
|
|---|
| 69 | *
|
|---|
| 70 | *
|
|---|
| 71 | * @return Session to broker (naming service) or NULL (sets errno).
|
|---|
| 72 | */
|
|---|
| 73 | async_sess_t *taskman_handshake(void)
|
|---|
| 74 | {
|
|---|
| 75 | int rc = taskman_ask_callback(session_primary);
|
|---|
| 76 | if (rc != EOK) {
|
|---|
| 77 | errno = rc;
|
|---|
| 78 | return NULL;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | async_sess_t *session_ns = taskman_connect_to_ns(session_primary);
|
|---|
| 82 | if (session_ns == NULL) {
|
|---|
| 83 | errno = ENOENT;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | return session_ns;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | /** @}
|
|---|
| 90 | */
|
|---|