[0761448] | 1 | /*
|
---|
| 2 | * Copyright (c) 2022 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 libwndmgt
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief Window management protocol server stub
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <wndmgt_srv.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <io/log.h>
|
---|
| 40 | #include <ipc/wndmgt.h>
|
---|
| 41 | #include <mem.h>
|
---|
| 42 | #include <stdlib.h>
|
---|
| 43 | #include <stddef.h>
|
---|
| 44 | #include <str.h>
|
---|
| 45 | #include <wndmgt.h>
|
---|
| 46 | #include "../private/wndmgt.h"
|
---|
| 47 |
|
---|
| 48 | static void wndmgt_callback_create_srv(wndmgt_srv_t *srv, ipc_call_t *call)
|
---|
| 49 | {
|
---|
| 50 | async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
|
---|
| 51 | if (sess == NULL) {
|
---|
| 52 | async_answer_0(call, ENOMEM);
|
---|
| 53 | return;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | srv->client_sess = sess;
|
---|
| 57 | async_answer_0(call, EOK);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | static void wndmgt_get_window_list_srv(wndmgt_srv_t *srv, ipc_call_t *icall)
|
---|
| 61 | {
|
---|
| 62 | ipc_call_t call;
|
---|
| 63 | wndmgt_window_list_t *list = NULL;
|
---|
| 64 | size_t size;
|
---|
| 65 | errno_t rc;
|
---|
| 66 |
|
---|
| 67 | if (srv->ops->get_window_list == NULL) {
|
---|
| 68 | async_answer_0(icall, ENOTSUP);
|
---|
| 69 | return;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | rc = srv->ops->get_window_list(srv->arg, &list);
|
---|
| 73 | if (rc != EOK) {
|
---|
| 74 | async_answer_0(&call, rc);
|
---|
| 75 | async_answer_0(icall, rc);
|
---|
| 76 | return;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | /* Send list size */
|
---|
| 80 |
|
---|
| 81 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 82 | wndmgt_free_window_list(list);
|
---|
| 83 | async_answer_0(icall, EREFUSED);
|
---|
| 84 | return;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | if (size != sizeof(list->nwindows)) {
|
---|
| 88 | wndmgt_free_window_list(list);
|
---|
| 89 | async_answer_0(&call, EINVAL);
|
---|
| 90 | async_answer_0(icall, EINVAL);
|
---|
| 91 | return;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | rc = async_data_read_finalize(&call, &list->nwindows, size);
|
---|
| 95 | if (rc != EOK) {
|
---|
| 96 | wndmgt_free_window_list(list);
|
---|
| 97 | async_answer_0(&call, rc);
|
---|
| 98 | async_answer_0(icall, rc);
|
---|
| 99 | return;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /* Send window list */
|
---|
| 103 |
|
---|
| 104 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 105 | wndmgt_free_window_list(list);
|
---|
| 106 | async_answer_0(icall, EREFUSED);
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | if (size != list->nwindows * sizeof(sysarg_t)) {
|
---|
| 111 | wndmgt_free_window_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->windows, size);
|
---|
| 118 | if (rc != EOK) {
|
---|
| 119 | wndmgt_free_window_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 | wndmgt_free_window_list(list);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | static void wndmgt_get_window_info_srv(wndmgt_srv_t *srv, ipc_call_t *icall)
|
---|
| 130 | {
|
---|
| 131 | sysarg_t wnd_id;
|
---|
| 132 | ipc_call_t call;
|
---|
| 133 | wndmgt_window_info_t *info = NULL;
|
---|
| 134 | size_t capsize;
|
---|
| 135 | size_t size;
|
---|
| 136 | errno_t rc;
|
---|
| 137 |
|
---|
| 138 | wnd_id = ipc_get_arg1(icall);
|
---|
| 139 |
|
---|
| 140 | if (srv->ops->get_window_info == NULL) {
|
---|
| 141 | async_answer_0(icall, ENOTSUP);
|
---|
| 142 | return;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | rc = srv->ops->get_window_info(srv->arg, wnd_id, &info);
|
---|
| 146 | if (rc != EOK) {
|
---|
| 147 | async_answer_0(&call, rc);
|
---|
| 148 | async_answer_0(icall, rc);
|
---|
| 149 | return;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /* Send caption size */
|
---|
| 153 |
|
---|
| 154 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 155 | wndmgt_free_window_info(info);
|
---|
| 156 | async_answer_0(icall, EREFUSED);
|
---|
| 157 | return;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if (size != sizeof(size_t)) {
|
---|
| 161 | wndmgt_free_window_info(info);
|
---|
| 162 | async_answer_0(&call, EINVAL);
|
---|
| 163 | async_answer_0(icall, EINVAL);
|
---|
| 164 | return;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | capsize = str_size(info->caption);
|
---|
| 168 |
|
---|
| 169 | rc = async_data_read_finalize(&call, &capsize, size);
|
---|
| 170 | if (rc != EOK) {
|
---|
| 171 | wndmgt_free_window_info(info);
|
---|
| 172 | async_answer_0(&call, rc);
|
---|
| 173 | async_answer_0(icall, rc);
|
---|
| 174 | return;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | /* Send caption */
|
---|
| 178 |
|
---|
| 179 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 180 | wndmgt_free_window_info(info);
|
---|
| 181 | async_answer_0(icall, EREFUSED);
|
---|
| 182 | return;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | if (size != capsize) {
|
---|
| 186 | wndmgt_free_window_info(info);
|
---|
| 187 | async_answer_0(&call, EINVAL);
|
---|
| 188 | async_answer_0(icall, EINVAL);
|
---|
| 189 | return;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | rc = async_data_read_finalize(&call, info->caption, size);
|
---|
| 193 | if (rc != EOK) {
|
---|
| 194 | wndmgt_free_window_info(info);
|
---|
| 195 | async_answer_0(&call, rc);
|
---|
| 196 | async_answer_0(icall, rc);
|
---|
| 197 | return;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | async_answer_0(icall, EOK);
|
---|
| 201 | wndmgt_free_window_info(info);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | static void wndmgt_activate_window_srv(wndmgt_srv_t *srv, ipc_call_t *icall)
|
---|
| 205 | {
|
---|
[a6492460] | 206 | sysarg_t dev_id;
|
---|
[0761448] | 207 | sysarg_t wnd_id;
|
---|
| 208 | errno_t rc;
|
---|
| 209 |
|
---|
[a6492460] | 210 | dev_id = ipc_get_arg1(icall);
|
---|
[3a6d44b7] | 211 | wnd_id = ipc_get_arg2(icall);
|
---|
[0761448] | 212 |
|
---|
| 213 | if (srv->ops->activate_window == NULL) {
|
---|
| 214 | async_answer_0(icall, ENOTSUP);
|
---|
| 215 | return;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[a6492460] | 218 | rc = srv->ops->activate_window(srv->arg, dev_id, wnd_id);
|
---|
[0761448] | 219 | async_answer_0(icall, rc);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | static void wndmgt_close_window_srv(wndmgt_srv_t *srv, ipc_call_t *icall)
|
---|
| 223 | {
|
---|
| 224 | sysarg_t wnd_id;
|
---|
| 225 | errno_t rc;
|
---|
| 226 |
|
---|
| 227 | wnd_id = ipc_get_arg1(icall);
|
---|
| 228 |
|
---|
| 229 | if (srv->ops->activate_window == NULL) {
|
---|
| 230 | async_answer_0(icall, ENOTSUP);
|
---|
| 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | rc = srv->ops->close_window(srv->arg, wnd_id);
|
---|
| 235 | async_answer_0(icall, rc);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | static void wndmgt_get_event_srv(wndmgt_srv_t *srv, ipc_call_t *icall)
|
---|
| 239 | {
|
---|
| 240 | wndmgt_ev_t event;
|
---|
| 241 | ipc_call_t call;
|
---|
| 242 | size_t size;
|
---|
| 243 | errno_t rc;
|
---|
| 244 |
|
---|
| 245 | if (srv->ops->get_event == NULL) {
|
---|
| 246 | async_answer_0(icall, ENOTSUP);
|
---|
| 247 | return;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | rc = srv->ops->get_event(srv->arg, &event);
|
---|
| 251 | if (rc != EOK) {
|
---|
| 252 | async_answer_0(icall, rc);
|
---|
| 253 | return;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /* Transfer event data */
|
---|
| 257 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 258 | async_answer_0(icall, EREFUSED);
|
---|
| 259 | return;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | if (size != sizeof(event)) {
|
---|
| 263 | async_answer_0(icall, EREFUSED);
|
---|
| 264 | async_answer_0(&call, EREFUSED);
|
---|
| 265 | return;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | rc = async_data_read_finalize(&call, &event, sizeof(event));
|
---|
| 269 | if (rc != EOK) {
|
---|
| 270 | async_answer_0(icall, rc);
|
---|
| 271 | async_answer_0(&call, rc);
|
---|
| 272 | return;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | async_answer_0(icall, EOK);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | void wndmgt_conn(ipc_call_t *icall, wndmgt_srv_t *srv)
|
---|
| 279 | {
|
---|
| 280 | /* Accept the connection */
|
---|
| 281 | async_accept_0(icall);
|
---|
| 282 |
|
---|
| 283 | while (true) {
|
---|
| 284 | ipc_call_t call;
|
---|
| 285 |
|
---|
| 286 | async_get_call(&call);
|
---|
| 287 | sysarg_t method = ipc_get_imethod(&call);
|
---|
| 288 |
|
---|
| 289 | if (!method) {
|
---|
| 290 | /* The other side has hung up */
|
---|
| 291 | async_answer_0(&call, EOK);
|
---|
| 292 | break;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | switch (method) {
|
---|
| 296 | case WNDMGT_CALLBACK_CREATE:
|
---|
| 297 | wndmgt_callback_create_srv(srv, &call);
|
---|
| 298 | break;
|
---|
| 299 | case WNDMGT_GET_WINDOW_LIST:
|
---|
| 300 | wndmgt_get_window_list_srv(srv, &call);
|
---|
| 301 | break;
|
---|
| 302 | case WNDMGT_GET_WINDOW_INFO:
|
---|
| 303 | wndmgt_get_window_info_srv(srv, &call);
|
---|
| 304 | break;
|
---|
| 305 | case WNDMGT_ACTIVATE_WINDOW:
|
---|
| 306 | wndmgt_activate_window_srv(srv, &call);
|
---|
| 307 | break;
|
---|
| 308 | case WNDMGT_CLOSE_WINDOW:
|
---|
| 309 | wndmgt_close_window_srv(srv, &call);
|
---|
| 310 | break;
|
---|
| 311 | case WNDMGT_GET_EVENT:
|
---|
| 312 | wndmgt_get_event_srv(srv, &call);
|
---|
| 313 | break;
|
---|
| 314 | default:
|
---|
| 315 | async_answer_0(&call, ENOTSUP);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | /* Hang up callback session */
|
---|
| 320 | if (srv->client_sess != NULL) {
|
---|
| 321 | async_hangup(srv->client_sess);
|
---|
| 322 | srv->client_sess = NULL;
|
---|
| 323 | }
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | /** Initialize window management server structure
|
---|
| 327 | *
|
---|
| 328 | * @param srv Window management server structure to initialize
|
---|
| 329 | */
|
---|
| 330 | void wndmgt_srv_initialize(wndmgt_srv_t *srv)
|
---|
| 331 | {
|
---|
| 332 | memset(srv, 0, sizeof(*srv));
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | /** Send 'pending' event to client.
|
---|
| 336 | *
|
---|
| 337 | * @param srv Window management server structure
|
---|
| 338 | */
|
---|
| 339 | void wndmgt_srv_ev_pending(wndmgt_srv_t *srv)
|
---|
| 340 | {
|
---|
| 341 | async_exch_t *exch;
|
---|
| 342 |
|
---|
| 343 | exch = async_exchange_begin(srv->client_sess);
|
---|
| 344 | async_msg_0(exch, WNDMGT_EV_PENDING);
|
---|
| 345 | async_exchange_end(exch);
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | /** @}
|
---|
| 349 | */
|
---|