| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 Jiri Svoboda
|
|---|
| 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 libdispcfg
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief Display configuration protocol server stub
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <dispcfg.h>
|
|---|
| 38 | #include <dispcfg_srv.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <ipc/dispcfg.h>
|
|---|
| 41 | #include <mem.h>
|
|---|
| 42 | #include <stdlib.h>
|
|---|
| 43 | #include <stddef.h>
|
|---|
| 44 | #include <str.h>
|
|---|
| 45 | #include "../private/dispcfg.h"
|
|---|
| 46 |
|
|---|
| 47 | static void dispcfg_callback_create_srv(dispcfg_srv_t *srv, ipc_call_t *call)
|
|---|
| 48 | {
|
|---|
| 49 | async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
|
|---|
| 50 | if (sess == NULL) {
|
|---|
| 51 | async_answer_0(call, ENOMEM);
|
|---|
| 52 | return;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | srv->client_sess = sess;
|
|---|
| 56 | async_answer_0(call, EOK);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | static void dispcfg_get_seat_list_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 60 | {
|
|---|
| 61 | ipc_call_t call;
|
|---|
| 62 | dispcfg_seat_list_t *list = NULL;
|
|---|
| 63 | size_t size;
|
|---|
| 64 | errno_t rc;
|
|---|
| 65 |
|
|---|
| 66 | if (srv->ops->get_seat_list == NULL) {
|
|---|
| 67 | async_answer_0(icall, ENOTSUP);
|
|---|
| 68 | return;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | rc = srv->ops->get_seat_list(srv->arg, &list);
|
|---|
| 72 | if (rc != EOK) {
|
|---|
| 73 | async_answer_0(icall, rc);
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /* Send list size */
|
|---|
| 78 |
|
|---|
| 79 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 80 | dispcfg_free_seat_list(list);
|
|---|
| 81 | async_answer_0(&call, EREFUSED);
|
|---|
| 82 | async_answer_0(icall, EREFUSED);
|
|---|
| 83 | return;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | if (size != sizeof(list->nseats)) {
|
|---|
| 87 | dispcfg_free_seat_list(list);
|
|---|
| 88 | async_answer_0(&call, EINVAL);
|
|---|
| 89 | async_answer_0(icall, EINVAL);
|
|---|
| 90 | return;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | rc = async_data_read_finalize(&call, &list->nseats, size);
|
|---|
| 94 | if (rc != EOK) {
|
|---|
| 95 | dispcfg_free_seat_list(list);
|
|---|
| 96 | async_answer_0(&call, rc);
|
|---|
| 97 | async_answer_0(icall, rc);
|
|---|
| 98 | return;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /* Send seat list */
|
|---|
| 102 |
|
|---|
| 103 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 104 | dispcfg_free_seat_list(list);
|
|---|
| 105 | async_answer_0(&call, EREFUSED);
|
|---|
| 106 | async_answer_0(icall, EREFUSED);
|
|---|
| 107 | return;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | if (size != list->nseats * sizeof(sysarg_t)) {
|
|---|
| 111 | dispcfg_free_seat_list(list);
|
|---|
| 112 | async_answer_0(&call, EINVAL);
|
|---|
| 113 | async_answer_0(icall, EINVAL);
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | rc = async_data_read_finalize(&call, list->seats, size);
|
|---|
| 118 | if (rc != EOK) {
|
|---|
| 119 | dispcfg_free_seat_list(list);
|
|---|
| 120 | async_answer_0(&call, rc);
|
|---|
| 121 | async_answer_0(icall, rc);
|
|---|
| 122 | return;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | async_answer_0(icall, EOK);
|
|---|
| 126 | dispcfg_free_seat_list(list);
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | static void dispcfg_get_seat_info_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 130 | {
|
|---|
| 131 | sysarg_t seat_id;
|
|---|
| 132 | ipc_call_t call;
|
|---|
| 133 | dispcfg_seat_info_t *info = NULL;
|
|---|
| 134 | size_t namesize;
|
|---|
| 135 | size_t size;
|
|---|
| 136 | errno_t rc;
|
|---|
| 137 |
|
|---|
| 138 | seat_id = ipc_get_arg1(icall);
|
|---|
| 139 |
|
|---|
| 140 | if (srv->ops->get_seat_info == NULL) {
|
|---|
| 141 | async_answer_0(icall, ENOTSUP);
|
|---|
| 142 | return;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | rc = srv->ops->get_seat_info(srv->arg, seat_id, &info);
|
|---|
| 146 | if (rc != EOK) {
|
|---|
| 147 | async_answer_0(icall, rc);
|
|---|
| 148 | return;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /* Send name size */
|
|---|
| 152 |
|
|---|
| 153 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 154 | dispcfg_free_seat_info(info);
|
|---|
| 155 | async_answer_0(&call, EREFUSED);
|
|---|
| 156 | async_answer_0(icall, EREFUSED);
|
|---|
| 157 | return;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | if (size != sizeof(size_t)) {
|
|---|
| 161 | dispcfg_free_seat_info(info);
|
|---|
| 162 | async_answer_0(&call, EINVAL);
|
|---|
| 163 | async_answer_0(icall, EINVAL);
|
|---|
| 164 | return;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | namesize = str_size(info->name);
|
|---|
| 168 |
|
|---|
| 169 | rc = async_data_read_finalize(&call, &namesize, size);
|
|---|
| 170 | if (rc != EOK) {
|
|---|
| 171 | dispcfg_free_seat_info(info);
|
|---|
| 172 | async_answer_0(&call, rc);
|
|---|
| 173 | async_answer_0(icall, rc);
|
|---|
| 174 | return;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | /* Send name */
|
|---|
| 178 |
|
|---|
| 179 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 180 | dispcfg_free_seat_info(info);
|
|---|
| 181 | async_answer_0(&call, EREFUSED);
|
|---|
| 182 | async_answer_0(icall, EREFUSED);
|
|---|
| 183 | return;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | if (size != namesize) {
|
|---|
| 187 | dispcfg_free_seat_info(info);
|
|---|
| 188 | async_answer_0(&call, EINVAL);
|
|---|
| 189 | async_answer_0(icall, EINVAL);
|
|---|
| 190 | return;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | rc = async_data_read_finalize(&call, info->name, size);
|
|---|
| 194 | if (rc != EOK) {
|
|---|
| 195 | dispcfg_free_seat_info(info);
|
|---|
| 196 | async_answer_0(&call, rc);
|
|---|
| 197 | async_answer_0(icall, rc);
|
|---|
| 198 | return;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | async_answer_0(icall, EOK);
|
|---|
| 202 | dispcfg_free_seat_info(info);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | static void dispcfg_seat_create_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 206 | {
|
|---|
| 207 | sysarg_t seat_id;
|
|---|
| 208 | ipc_call_t call;
|
|---|
| 209 | char *name;
|
|---|
| 210 | size_t size;
|
|---|
| 211 | errno_t rc;
|
|---|
| 212 |
|
|---|
| 213 | if (!async_data_write_receive(&call, &size)) {
|
|---|
| 214 | async_answer_0(&call, EREFUSED);
|
|---|
| 215 | async_answer_0(icall, EREFUSED);
|
|---|
| 216 | return;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | name = calloc(size + 1, 1);
|
|---|
| 220 | if (name == NULL) {
|
|---|
| 221 | async_answer_0(&call, ENOMEM);
|
|---|
| 222 | async_answer_0(icall, ENOMEM);
|
|---|
| 223 | return;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | rc = async_data_write_finalize(&call, name, size);
|
|---|
| 227 | if (rc != EOK) {
|
|---|
| 228 | free(name);
|
|---|
| 229 | async_answer_0(&call, rc);
|
|---|
| 230 | async_answer_0(icall, rc);
|
|---|
| 231 | return;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | if (srv->ops->seat_create == NULL) {
|
|---|
| 235 | free(name);
|
|---|
| 236 | async_answer_0(icall, ENOTSUP);
|
|---|
| 237 | return;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | rc = srv->ops->seat_create(srv->arg, name, &seat_id);
|
|---|
| 241 | async_answer_1(icall, rc, seat_id);
|
|---|
| 242 | free(name);
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | static void dispcfg_seat_delete_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 246 | {
|
|---|
| 247 | sysarg_t seat_id;
|
|---|
| 248 | errno_t rc;
|
|---|
| 249 |
|
|---|
| 250 | seat_id = ipc_get_arg1(icall);
|
|---|
| 251 |
|
|---|
| 252 | if (srv->ops->seat_delete == NULL) {
|
|---|
| 253 | async_answer_0(icall, ENOTSUP);
|
|---|
| 254 | return;
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | rc = srv->ops->seat_delete(srv->arg, seat_id);
|
|---|
| 258 | async_answer_0(icall, rc);
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | static void dispcfg_dev_assign_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 262 | {
|
|---|
| 263 | sysarg_t svc_id;
|
|---|
| 264 | sysarg_t seat_id;
|
|---|
| 265 | errno_t rc;
|
|---|
| 266 |
|
|---|
| 267 | svc_id = ipc_get_arg1(icall);
|
|---|
| 268 | seat_id = ipc_get_arg2(icall);
|
|---|
| 269 |
|
|---|
| 270 | if (srv->ops->dev_assign == NULL) {
|
|---|
| 271 | async_answer_0(icall, ENOTSUP);
|
|---|
| 272 | return;
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | rc = srv->ops->dev_assign(srv->arg, svc_id, seat_id);
|
|---|
| 276 | async_answer_0(icall, rc);
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | static void dispcfg_dev_unassign_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 280 | {
|
|---|
| 281 | sysarg_t svc_id;
|
|---|
| 282 | errno_t rc;
|
|---|
| 283 |
|
|---|
| 284 | svc_id = ipc_get_arg1(icall);
|
|---|
| 285 |
|
|---|
| 286 | if (srv->ops->dev_unassign == NULL) {
|
|---|
| 287 | async_answer_0(icall, ENOTSUP);
|
|---|
| 288 | return;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | rc = srv->ops->dev_unassign(srv->arg, svc_id);
|
|---|
| 292 | async_answer_0(icall, rc);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | static void dispcfg_get_event_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
|
|---|
| 296 | {
|
|---|
| 297 | dispcfg_ev_t event;
|
|---|
| 298 | ipc_call_t call;
|
|---|
| 299 | size_t size;
|
|---|
| 300 | errno_t rc;
|
|---|
| 301 |
|
|---|
| 302 | if (srv->ops->get_event == NULL) {
|
|---|
| 303 | async_answer_0(icall, ENOTSUP);
|
|---|
| 304 | return;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | rc = srv->ops->get_event(srv->arg, &event);
|
|---|
| 308 | if (rc != EOK) {
|
|---|
| 309 | async_answer_0(icall, rc);
|
|---|
| 310 | return;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | /* Transfer event data */
|
|---|
| 314 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 315 | async_answer_0(&call, EREFUSED);
|
|---|
| 316 | async_answer_0(icall, EREFUSED);
|
|---|
| 317 | return;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | if (size != sizeof(event)) {
|
|---|
| 321 | async_answer_0(&call, EREFUSED);
|
|---|
| 322 | async_answer_0(icall, EREFUSED);
|
|---|
| 323 | return;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | rc = async_data_read_finalize(&call, &event, sizeof(event));
|
|---|
| 327 | if (rc != EOK) {
|
|---|
| 328 | async_answer_0(&call, rc);
|
|---|
| 329 | async_answer_0(icall, rc);
|
|---|
| 330 | return;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | async_answer_0(icall, EOK);
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | void dispcfg_conn(ipc_call_t *icall, dispcfg_srv_t *srv)
|
|---|
| 337 | {
|
|---|
| 338 | /* Accept the connection */
|
|---|
| 339 | async_accept_0(icall);
|
|---|
| 340 |
|
|---|
| 341 | while (true) {
|
|---|
| 342 | ipc_call_t call;
|
|---|
| 343 |
|
|---|
| 344 | async_get_call(&call);
|
|---|
| 345 | sysarg_t method = ipc_get_imethod(&call);
|
|---|
| 346 |
|
|---|
| 347 | if (!method) {
|
|---|
| 348 | /* The other side has hung up */
|
|---|
| 349 | async_answer_0(&call, EOK);
|
|---|
| 350 | break;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | switch (method) {
|
|---|
| 354 | case DISPCFG_CALLBACK_CREATE:
|
|---|
| 355 | dispcfg_callback_create_srv(srv, &call);
|
|---|
| 356 | break;
|
|---|
| 357 | case DISPCFG_GET_SEAT_LIST:
|
|---|
| 358 | dispcfg_get_seat_list_srv(srv, &call);
|
|---|
| 359 | break;
|
|---|
| 360 | case DISPCFG_GET_SEAT_INFO:
|
|---|
| 361 | dispcfg_get_seat_info_srv(srv, &call);
|
|---|
| 362 | break;
|
|---|
| 363 | case DISPCFG_SEAT_CREATE:
|
|---|
| 364 | dispcfg_seat_create_srv(srv, &call);
|
|---|
| 365 | break;
|
|---|
| 366 | case DISPCFG_SEAT_DELETE:
|
|---|
| 367 | dispcfg_seat_delete_srv(srv, &call);
|
|---|
| 368 | break;
|
|---|
| 369 | case DISPCFG_DEV_ASSIGN:
|
|---|
| 370 | dispcfg_dev_assign_srv(srv, &call);
|
|---|
| 371 | break;
|
|---|
| 372 | case DISPCFG_DEV_UNASSIGN:
|
|---|
| 373 | dispcfg_dev_unassign_srv(srv, &call);
|
|---|
| 374 | break;
|
|---|
| 375 | case DISPCFG_GET_EVENT:
|
|---|
| 376 | dispcfg_get_event_srv(srv, &call);
|
|---|
| 377 | break;
|
|---|
| 378 | default:
|
|---|
| 379 | async_answer_0(&call, ENOTSUP);
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | /* Hang up callback session */
|
|---|
| 384 | if (srv->client_sess != NULL) {
|
|---|
| 385 | async_hangup(srv->client_sess);
|
|---|
| 386 | srv->client_sess = NULL;
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | /** Initialize display configuration server structure
|
|---|
| 391 | *
|
|---|
| 392 | * @param srv Display configuration server structure to initialize
|
|---|
| 393 | */
|
|---|
| 394 | void dispcfg_srv_initialize(dispcfg_srv_t *srv)
|
|---|
| 395 | {
|
|---|
| 396 | memset(srv, 0, sizeof(*srv));
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /** Send 'pending' event to client.
|
|---|
| 400 | *
|
|---|
| 401 | * @param srv Display configuration server structure
|
|---|
| 402 | */
|
|---|
| 403 | void dispcfg_srv_ev_pending(dispcfg_srv_t *srv)
|
|---|
| 404 | {
|
|---|
| 405 | async_exch_t *exch;
|
|---|
| 406 |
|
|---|
| 407 | exch = async_exchange_begin(srv->client_sess);
|
|---|
| 408 | async_msg_0(exch, DISPCFG_EV_PENDING);
|
|---|
| 409 | async_exchange_end(exch);
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | /** @}
|
|---|
| 413 | */
|
|---|