[c8cf261] | 1 | /*
|
---|
| 2 | * Copyright (c) 2019 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 |
|
---|
[973efd36] | 29 | /** @addtogroup libdisplay
|
---|
[c8cf261] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief Display protocol server stub
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <disp_srv.h>
|
---|
[b3c185b6] | 38 | #include <display/event.h>
|
---|
[1e4a937] | 39 | #include <display/wndresize.h>
|
---|
[c8cf261] | 40 | #include <errno.h>
|
---|
[b3c185b6] | 41 | #include <io/log.h>
|
---|
[c8cf261] | 42 | #include <ipc/display.h>
|
---|
[959b7ec] | 43 | #include <mem.h>
|
---|
[c8cf261] | 44 | #include <stdlib.h>
|
---|
| 45 | #include <stddef.h>
|
---|
[0e6e77f] | 46 | #include "../private/params.h"
|
---|
[c8cf261] | 47 |
|
---|
[b3c185b6] | 48 | static void display_callback_create_srv(display_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 |
|
---|
[c8cf261] | 60 | static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 61 | {
|
---|
| 62 | sysarg_t wnd_id;
|
---|
[4d9c807] | 63 | ipc_call_t call;
|
---|
| 64 | display_wnd_params_t params;
|
---|
| 65 | size_t size;
|
---|
[c8cf261] | 66 | errno_t rc;
|
---|
| 67 |
|
---|
[4d9c807] | 68 | if (!async_data_write_receive(&call, &size)) {
|
---|
| 69 | async_answer_0(&call, EREFUSED);
|
---|
| 70 | async_answer_0(icall, EREFUSED);
|
---|
| 71 | return;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | if (size != sizeof(display_wnd_params_t)) {
|
---|
| 75 | async_answer_0(&call, EINVAL);
|
---|
| 76 | async_answer_0(icall, EINVAL);
|
---|
| 77 | return;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | rc = async_data_write_finalize(&call, ¶ms, size);
|
---|
| 81 | if (rc != EOK) {
|
---|
| 82 | async_answer_0(&call, rc);
|
---|
| 83 | async_answer_0(icall, rc);
|
---|
| 84 | return;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[c8cf261] | 87 | if (srv->ops->window_create == NULL) {
|
---|
| 88 | async_answer_0(icall, ENOTSUP);
|
---|
| 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[4d9c807] | 92 | rc = srv->ops->window_create(srv->arg, ¶ms, &wnd_id);
|
---|
[c8cf261] | 93 | async_answer_1(icall, rc, wnd_id);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 97 | {
|
---|
| 98 | sysarg_t wnd_id;
|
---|
| 99 | errno_t rc;
|
---|
| 100 |
|
---|
| 101 | wnd_id = ipc_get_arg1(icall);
|
---|
| 102 |
|
---|
[a2e104e] | 103 | if (srv->ops->window_destroy == NULL) {
|
---|
[c8cf261] | 104 | async_answer_0(icall, ENOTSUP);
|
---|
| 105 | return;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | rc = srv->ops->window_destroy(srv->arg, wnd_id);
|
---|
| 109 | async_answer_0(icall, rc);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[a2e104e] | 112 | static void display_window_move_req_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 113 | {
|
---|
| 114 | sysarg_t wnd_id;
|
---|
| 115 | ipc_call_t call;
|
---|
| 116 | gfx_coord2_t pos;
|
---|
| 117 | size_t size;
|
---|
| 118 | errno_t rc;
|
---|
| 119 |
|
---|
| 120 | wnd_id = ipc_get_arg1(icall);
|
---|
| 121 |
|
---|
| 122 | if (!async_data_write_receive(&call, &size)) {
|
---|
| 123 | async_answer_0(&call, EREFUSED);
|
---|
| 124 | async_answer_0(icall, EREFUSED);
|
---|
| 125 | return;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | if (size != sizeof(gfx_coord2_t)) {
|
---|
| 129 | async_answer_0(&call, EINVAL);
|
---|
| 130 | async_answer_0(icall, EINVAL);
|
---|
| 131 | return;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | rc = async_data_write_finalize(&call, &pos, size);
|
---|
| 135 | if (rc != EOK) {
|
---|
| 136 | async_answer_0(&call, rc);
|
---|
| 137 | async_answer_0(icall, rc);
|
---|
| 138 | return;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | if (srv->ops->window_move_req == NULL) {
|
---|
| 142 | async_answer_0(icall, ENOTSUP);
|
---|
| 143 | return;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | rc = srv->ops->window_move_req(srv->arg, wnd_id, &pos);
|
---|
| 147 | async_answer_0(icall, rc);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[1e4a937] | 150 | static void display_window_resize_req_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 151 | {
|
---|
| 152 | sysarg_t wnd_id;
|
---|
| 153 | ipc_call_t call;
|
---|
| 154 | display_wnd_rsztype_t rsztype;
|
---|
| 155 | gfx_coord2_t pos;
|
---|
| 156 | size_t size;
|
---|
| 157 | errno_t rc;
|
---|
| 158 |
|
---|
| 159 | wnd_id = ipc_get_arg1(icall);
|
---|
| 160 | rsztype = (display_wnd_rsztype_t) ipc_get_arg2(icall);
|
---|
| 161 |
|
---|
| 162 | if (!async_data_write_receive(&call, &size)) {
|
---|
| 163 | async_answer_0(&call, EREFUSED);
|
---|
| 164 | async_answer_0(icall, EREFUSED);
|
---|
| 165 | return;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | if (size != sizeof(gfx_coord2_t)) {
|
---|
| 169 | async_answer_0(&call, EINVAL);
|
---|
| 170 | async_answer_0(icall, EINVAL);
|
---|
| 171 | return;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | rc = async_data_write_finalize(&call, &pos, size);
|
---|
| 175 | if (rc != EOK) {
|
---|
| 176 | async_answer_0(&call, rc);
|
---|
| 177 | async_answer_0(icall, rc);
|
---|
| 178 | return;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | if (srv->ops->window_resize_req == NULL) {
|
---|
| 182 | async_answer_0(icall, ENOTSUP);
|
---|
| 183 | return;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | rc = srv->ops->window_resize_req(srv->arg, wnd_id, rsztype, &pos);
|
---|
| 187 | async_answer_0(icall, rc);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[0e6e77f] | 190 | static void display_window_resize_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 191 | {
|
---|
| 192 | sysarg_t wnd_id;
|
---|
| 193 | ipc_call_t call;
|
---|
[7bb45e3] | 194 | display_wnd_resize_t wresize;
|
---|
[0e6e77f] | 195 | size_t size;
|
---|
| 196 | errno_t rc;
|
---|
| 197 |
|
---|
| 198 | wnd_id = ipc_get_arg1(icall);
|
---|
| 199 |
|
---|
| 200 | if (!async_data_write_receive(&call, &size)) {
|
---|
| 201 | async_answer_0(&call, EREFUSED);
|
---|
| 202 | async_answer_0(icall, EREFUSED);
|
---|
| 203 | return;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[7bb45e3] | 206 | if (size != sizeof(display_wnd_resize_t)) {
|
---|
[0e6e77f] | 207 | async_answer_0(&call, EINVAL);
|
---|
| 208 | async_answer_0(icall, EINVAL);
|
---|
| 209 | return;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[7bb45e3] | 212 | rc = async_data_write_finalize(&call, &wresize, size);
|
---|
[0e6e77f] | 213 | if (rc != EOK) {
|
---|
| 214 | async_answer_0(&call, rc);
|
---|
| 215 | async_answer_0(icall, rc);
|
---|
| 216 | return;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | if (srv->ops->window_resize == NULL) {
|
---|
| 220 | async_answer_0(icall, ENOTSUP);
|
---|
| 221 | return;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[7bb45e3] | 224 | rc = srv->ops->window_resize(srv->arg, wnd_id, &wresize.offs,
|
---|
| 225 | &wresize.nrect);
|
---|
[0e6e77f] | 226 | async_answer_0(icall, rc);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[b3c185b6] | 229 | static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 230 | {
|
---|
| 231 | sysarg_t wnd_id;
|
---|
| 232 | display_wnd_ev_t event;
|
---|
| 233 | ipc_call_t call;
|
---|
| 234 | size_t size;
|
---|
| 235 | errno_t rc;
|
---|
| 236 |
|
---|
| 237 | if (srv->ops->get_event == NULL) {
|
---|
| 238 | async_answer_0(icall, ENOTSUP);
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | rc = srv->ops->get_event(srv->arg, &wnd_id, &event);
|
---|
[dcac756] | 243 | if (rc != EOK) {
|
---|
[b3c185b6] | 244 | async_answer_0(icall, rc);
|
---|
[dcac756] | 245 | return;
|
---|
| 246 | }
|
---|
[b3c185b6] | 247 |
|
---|
| 248 | /* Transfer event data */
|
---|
| 249 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 250 | async_answer_0(icall, EREFUSED);
|
---|
| 251 | return;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | if (size != sizeof(event)) {
|
---|
| 255 | async_answer_0(icall, EREFUSED);
|
---|
| 256 | async_answer_0(&call, EREFUSED);
|
---|
| 257 | return;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | rc = async_data_read_finalize(&call, &event, sizeof(event));
|
---|
| 261 | if (rc != EOK) {
|
---|
| 262 | async_answer_0(icall, rc);
|
---|
| 263 | async_answer_0(&call, rc);
|
---|
| 264 | return;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | async_answer_1(icall, EOK, wnd_id);
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[c8cf261] | 270 | void display_conn(ipc_call_t *icall, display_srv_t *srv)
|
---|
| 271 | {
|
---|
| 272 | /* Accept the connection */
|
---|
| 273 | async_accept_0(icall);
|
---|
| 274 |
|
---|
| 275 | while (true) {
|
---|
| 276 | ipc_call_t call;
|
---|
| 277 |
|
---|
| 278 | async_get_call(&call);
|
---|
| 279 | sysarg_t method = ipc_get_imethod(&call);
|
---|
| 280 |
|
---|
| 281 | if (!method) {
|
---|
| 282 | /* The other side has hung up */
|
---|
| 283 | async_answer_0(&call, EOK);
|
---|
| 284 | break;
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | switch (method) {
|
---|
[b3c185b6] | 288 | case DISPLAY_CALLBACK_CREATE:
|
---|
| 289 | display_callback_create_srv(srv, &call);
|
---|
| 290 | break;
|
---|
[c8cf261] | 291 | case DISPLAY_WINDOW_CREATE:
|
---|
| 292 | display_window_create_srv(srv, &call);
|
---|
| 293 | break;
|
---|
| 294 | case DISPLAY_WINDOW_DESTROY:
|
---|
| 295 | display_window_destroy_srv(srv, &call);
|
---|
| 296 | break;
|
---|
[a2e104e] | 297 | case DISPLAY_WINDOW_MOVE_REQ:
|
---|
| 298 | display_window_move_req_srv(srv, &call);
|
---|
| 299 | break;
|
---|
[1e4a937] | 300 | case DISPLAY_WINDOW_RESIZE_REQ:
|
---|
| 301 | display_window_resize_req_srv(srv, &call);
|
---|
| 302 | break;
|
---|
[0e6e77f] | 303 | case DISPLAY_WINDOW_RESIZE:
|
---|
| 304 | display_window_resize_srv(srv, &call);
|
---|
| 305 | break;
|
---|
[b3c185b6] | 306 | case DISPLAY_GET_EVENT:
|
---|
| 307 | display_get_event_srv(srv, &call);
|
---|
| 308 | break;
|
---|
[c8cf261] | 309 | default:
|
---|
| 310 | async_answer_0(&call, ENOTSUP);
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
[959b7ec] | 313 |
|
---|
| 314 | /* Hang up callback session */
|
---|
| 315 | if (srv->client_sess != NULL) {
|
---|
| 316 | async_hangup(srv->client_sess);
|
---|
| 317 | srv->client_sess = NULL;
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | /** Initialize display server structure
|
---|
| 322 | *
|
---|
| 323 | * @param srv Display server structure to initialize
|
---|
| 324 | */
|
---|
| 325 | void display_srv_initialize(display_srv_t *srv)
|
---|
| 326 | {
|
---|
| 327 | memset(srv, 0, sizeof(*srv));
|
---|
[c8cf261] | 328 | }
|
---|
| 329 |
|
---|
[b3c185b6] | 330 | /** Send 'pending' event to client.
|
---|
| 331 | *
|
---|
| 332 | * @param srv Display server structure
|
---|
| 333 | */
|
---|
| 334 | void display_srv_ev_pending(display_srv_t *srv)
|
---|
| 335 | {
|
---|
| 336 | async_exch_t *exch;
|
---|
| 337 |
|
---|
| 338 | exch = async_exchange_begin(srv->client_sess);
|
---|
| 339 | async_msg_0(exch, DISPLAY_EV_PENDING);
|
---|
| 340 | async_exchange_end(exch);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[c8cf261] | 343 | /** @}
|
---|
| 344 | */
|
---|