| 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 | #include <errno.h>
|
|---|
| 30 | #include <ipc/sysman.h>
|
|---|
| 31 | #include <stdlib.h>
|
|---|
| 32 |
|
|---|
| 33 | #include "configuration.h"
|
|---|
| 34 | #include "connection_broker.h"
|
|---|
| 35 | #include "log.h"
|
|---|
| 36 | #include "sysman.h"
|
|---|
| 37 |
|
|---|
| 38 | static void sysman_broker_register(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 39 | {
|
|---|
| 40 | sysman_log(LVL_DEBUG2, "%s", __func__);
|
|---|
| 41 | async_answer_0(iid, EOK);
|
|---|
| 42 | /* TODO implement
|
|---|
| 43 | * What exactly? Similar behavior that has locsrv with servers,
|
|---|
| 44 | * so that subsequent calls can be assigned to broker. Still that
|
|---|
| 45 | * makes sense only when brokers will somehow scope unit/exposee
|
|---|
| 46 | * names. Why I wanted this registration?
|
|---|
| 47 | */
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | static void sysman_ipc_forwarded(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 51 | {
|
|---|
| 52 | sysman_log(LVL_DEBUG2, "%s", __func__);
|
|---|
| 53 | async_answer_0(iid, ENOTSUP);
|
|---|
| 54 | // TODO implement
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | static void sysman_main_exposee_added(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 58 | {
|
|---|
| 59 | char *unit_name = NULL;
|
|---|
| 60 | sysarg_t retval;
|
|---|
| 61 |
|
|---|
| 62 | int rc = async_data_write_accept((void **) &unit_name, true,
|
|---|
| 63 | 0, 0, 0, NULL);
|
|---|
| 64 | if (rc != EOK) {
|
|---|
| 65 | retval = rc;
|
|---|
| 66 | goto finish;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | unit_t *unit = configuration_find_unit_by_name(unit_name);
|
|---|
| 70 | if (unit == NULL) {
|
|---|
| 71 | //sysman_log(LVL_NOTE, "Unit '%s' not found.", unit_name);
|
|---|
| 72 | retval = ENOENT;
|
|---|
| 73 | goto finish;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // TODO propagate caller task ID
|
|---|
| 77 | sysman_raise_event(&sysman_event_unit_exposee_created, unit);
|
|---|
| 78 |
|
|---|
| 79 | retval = EOK;
|
|---|
| 80 |
|
|---|
| 81 | finish:
|
|---|
| 82 | async_answer_0(iid, retval);
|
|---|
| 83 | free(unit_name);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static void sysman_exposee_added(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 87 | {
|
|---|
| 88 | char *exposee = NULL;
|
|---|
| 89 | sysarg_t retval;
|
|---|
| 90 |
|
|---|
| 91 | /* Just accept data and further not supported. */
|
|---|
| 92 | int rc = async_data_write_accept((void **) &exposee, true,
|
|---|
| 93 | 0, 0, 0, NULL);
|
|---|
| 94 | if (rc != EOK) {
|
|---|
| 95 | retval = rc;
|
|---|
| 96 | goto finish;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | //sysman_log(LVL_DEBUG2, "%s(%s)", __func__, exposee);
|
|---|
| 100 |
|
|---|
| 101 | retval = ENOTSUP;
|
|---|
| 102 |
|
|---|
| 103 | finish:
|
|---|
| 104 | async_answer_0(iid, retval);
|
|---|
| 105 | free(exposee);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | static void sysman_exposee_removed(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 109 | {
|
|---|
| 110 | sysman_log(LVL_DEBUG2, "%s", __func__);
|
|---|
| 111 | async_answer_0(iid, ENOTSUP);
|
|---|
| 112 | // TODO implement
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void sysman_connection_broker(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 116 | {
|
|---|
| 117 | sysman_log(LVL_DEBUG2, "%s", __func__);
|
|---|
| 118 | /* First, accept connection */
|
|---|
| 119 | async_answer_0(iid, EOK);
|
|---|
| 120 |
|
|---|
| 121 | while (true) {
|
|---|
| 122 | ipc_call_t call;
|
|---|
| 123 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 124 |
|
|---|
| 125 | if (!IPC_GET_IMETHOD(call)) {
|
|---|
| 126 | /* Client disconnected */
|
|---|
| 127 | break;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| 131 | case SYSMAN_BROKER_REGISTER:
|
|---|
| 132 | sysman_broker_register(callid, &call);
|
|---|
| 133 | break;
|
|---|
| 134 | case SYSMAN_BROKER_IPC_FWD:
|
|---|
| 135 | sysman_ipc_forwarded(callid, &call);
|
|---|
| 136 | break;
|
|---|
| 137 | case SYSMAN_BROKER_MAIN_EXP_ADDED:
|
|---|
| 138 | sysman_main_exposee_added(callid, &call);
|
|---|
| 139 | break;
|
|---|
| 140 | case SYSMAN_BROKER_EXP_ADDED:
|
|---|
| 141 | sysman_exposee_added(callid, &call);
|
|---|
| 142 | break;
|
|---|
| 143 | case SYSMAN_BROKER_EXP_REMOVED:
|
|---|
| 144 | sysman_exposee_removed(callid, &call);
|
|---|
| 145 | break;
|
|---|
| 146 | default:
|
|---|
| 147 | async_answer_0(callid, ENOENT);
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|