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