source: mainline/uspace/srv/sysman/connection_broker.c@ 25697163

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

Replacing int with errno_t

The merged code from system-daemon still used the type int
for indicating an error instead of using errno_t. This
commit corrects this mistake

  • 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 errno_t 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 errno_t 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 retval = ENOTSUP;
99
100finish:
101 async_answer_0(icall, retval);
102 free(exposee);
103}
104
105static void sysman_exposee_removed(ipc_call_t *icall)
106{
107 sysman_log(LVL_DEBUG2, "%s", __func__);
108 async_answer_0(icall, ENOTSUP);
109 // TODO implement
110}
111
112void sysman_connection_broker(ipc_call_t *icall)
113{
114 sysman_log(LVL_DEBUG2, "%s", __func__);
115 /* First, accept connection */
116 async_answer_0(icall, EOK);
117
118 while (true) {
119 ipc_call_t call;
120
121 if (!async_get_call(&call) || !ipc_get_imethod(&call)) {
122 /* Client disconnected */
123 break;
124 }
125
126 switch (ipc_get_imethod(&call)) {
127 case SYSMAN_BROKER_REGISTER:
128 sysman_broker_register(&call);
129 break;
130 case SYSMAN_BROKER_IPC_FWD:
131 sysman_ipc_forwarded(&call);
132 break;
133 case SYSMAN_BROKER_MAIN_EXP_ADDED:
134 sysman_main_exposee_added(&call);
135 break;
136 case SYSMAN_BROKER_EXP_ADDED:
137 sysman_exposee_added(&call);
138 break;
139 case SYSMAN_BROKER_EXP_REMOVED:
140 sysman_exposee_removed(&call);
141 break;
142 default:
143 async_answer_0(&call, ENOENT);
144 }
145 }
146}
Note: See TracBrowser for help on using the repository browser.