| 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 |
|
|---|
| 29 | /** @addtogroup libdisplay
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief Display protocol server stub
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <disp_srv.h>
|
|---|
| 38 | #include <display/event.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <io/log.h>
|
|---|
| 41 | #include <ipc/display.h>
|
|---|
| 42 | #include <mem.h>
|
|---|
| 43 | #include <stdlib.h>
|
|---|
| 44 | #include <stddef.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <stdio.h>
|
|---|
| 47 | static void display_callback_create_srv(display_srv_t *srv, ipc_call_t *call)
|
|---|
| 48 | {
|
|---|
| 49 | printf("display_callback_create_srv\n");
|
|---|
| 50 |
|
|---|
| 51 | async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
|
|---|
| 52 | if (sess == NULL) {
|
|---|
| 53 | async_answer_0(call, ENOMEM);
|
|---|
| 54 | return;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | srv->client_sess = sess;
|
|---|
| 58 | async_answer_0(call, EOK);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
|
|---|
| 62 | {
|
|---|
| 63 | sysarg_t wnd_id;
|
|---|
| 64 | ipc_call_t call;
|
|---|
| 65 | display_wnd_params_t params;
|
|---|
| 66 | size_t size;
|
|---|
| 67 | errno_t rc;
|
|---|
| 68 |
|
|---|
| 69 | printf("display_window_create_srv\n");
|
|---|
| 70 |
|
|---|
| 71 | if (!async_data_write_receive(&call, &size)) {
|
|---|
| 72 | async_answer_0(&call, EREFUSED);
|
|---|
| 73 | async_answer_0(icall, EREFUSED);
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | if (size != sizeof(display_wnd_params_t)) {
|
|---|
| 78 | async_answer_0(&call, EINVAL);
|
|---|
| 79 | async_answer_0(icall, EINVAL);
|
|---|
| 80 | return;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | rc = async_data_write_finalize(&call, ¶ms, size);
|
|---|
| 84 | if (rc != EOK) {
|
|---|
| 85 | async_answer_0(&call, rc);
|
|---|
| 86 | async_answer_0(icall, rc);
|
|---|
| 87 | return;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | if (srv->ops->window_create == NULL) {
|
|---|
| 91 | async_answer_0(icall, ENOTSUP);
|
|---|
| 92 | return;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | rc = srv->ops->window_create(srv->arg, ¶ms, &wnd_id);
|
|---|
| 96 | async_answer_1(icall, rc, wnd_id);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
|
|---|
| 100 | {
|
|---|
| 101 | sysarg_t wnd_id;
|
|---|
| 102 | errno_t rc;
|
|---|
| 103 |
|
|---|
| 104 | printf("display_window_destroy_srv\n");
|
|---|
| 105 |
|
|---|
| 106 | wnd_id = ipc_get_arg1(icall);
|
|---|
| 107 |
|
|---|
| 108 | if (srv->ops->window_create == NULL) {
|
|---|
| 109 | async_answer_0(icall, ENOTSUP);
|
|---|
| 110 | return;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | rc = srv->ops->window_destroy(srv->arg, wnd_id);
|
|---|
| 114 | async_answer_0(icall, rc);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall)
|
|---|
| 118 | {
|
|---|
| 119 | sysarg_t wnd_id;
|
|---|
| 120 | display_wnd_ev_t event;
|
|---|
| 121 | ipc_call_t call;
|
|---|
| 122 | size_t size;
|
|---|
| 123 | errno_t rc;
|
|---|
| 124 |
|
|---|
| 125 | printf("display_get_event_srv\n");
|
|---|
| 126 |
|
|---|
| 127 | if (srv->ops->get_event == NULL) {
|
|---|
| 128 | async_answer_0(icall, ENOTSUP);
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | rc = srv->ops->get_event(srv->arg, &wnd_id, &event);
|
|---|
| 133 | if (rc != EOK) {
|
|---|
| 134 | async_answer_0(icall, rc);
|
|---|
| 135 | return;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /* Transfer event data */
|
|---|
| 139 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 140 | async_answer_0(icall, EREFUSED);
|
|---|
| 141 | return;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | if (size != sizeof(event)) {
|
|---|
| 145 | async_answer_0(icall, EREFUSED);
|
|---|
| 146 | async_answer_0(&call, EREFUSED);
|
|---|
| 147 | return;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | rc = async_data_read_finalize(&call, &event, sizeof(event));
|
|---|
| 151 | if (rc != EOK) {
|
|---|
| 152 | async_answer_0(icall, rc);
|
|---|
| 153 | async_answer_0(&call, rc);
|
|---|
| 154 | return;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | async_answer_1(icall, EOK, wnd_id);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void display_conn(ipc_call_t *icall, display_srv_t *srv)
|
|---|
| 161 | {
|
|---|
| 162 | /* Accept the connection */
|
|---|
| 163 | async_accept_0(icall);
|
|---|
| 164 | printf("display_conn\n");
|
|---|
| 165 |
|
|---|
| 166 | while (true) {
|
|---|
| 167 | ipc_call_t call;
|
|---|
| 168 |
|
|---|
| 169 | async_get_call(&call);
|
|---|
| 170 | sysarg_t method = ipc_get_imethod(&call);
|
|---|
| 171 |
|
|---|
| 172 | if (!method) {
|
|---|
| 173 | /* The other side has hung up */
|
|---|
| 174 | async_answer_0(&call, EOK);
|
|---|
| 175 | break;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | printf("display_conn method=%u\n", (unsigned) method);
|
|---|
| 179 | switch (method) {
|
|---|
| 180 | case DISPLAY_CALLBACK_CREATE:
|
|---|
| 181 | display_callback_create_srv(srv, &call);
|
|---|
| 182 | break;
|
|---|
| 183 | case DISPLAY_WINDOW_CREATE:
|
|---|
| 184 | display_window_create_srv(srv, &call);
|
|---|
| 185 | break;
|
|---|
| 186 | case DISPLAY_WINDOW_DESTROY:
|
|---|
| 187 | display_window_destroy_srv(srv, &call);
|
|---|
| 188 | break;
|
|---|
| 189 | case DISPLAY_GET_EVENT:
|
|---|
| 190 | display_get_event_srv(srv, &call);
|
|---|
| 191 | break;
|
|---|
| 192 | default:
|
|---|
| 193 | async_answer_0(&call, ENOTSUP);
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | /* Hang up callback session */
|
|---|
| 198 | if (srv->client_sess != NULL) {
|
|---|
| 199 | async_hangup(srv->client_sess);
|
|---|
| 200 | srv->client_sess = NULL;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | /** Initialize display server structure
|
|---|
| 205 | *
|
|---|
| 206 | * @param srv Display server structure to initialize
|
|---|
| 207 | */
|
|---|
| 208 | void display_srv_initialize(display_srv_t *srv)
|
|---|
| 209 | {
|
|---|
| 210 | memset(srv, 0, sizeof(*srv));
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | /** Send 'pending' event to client.
|
|---|
| 214 | *
|
|---|
| 215 | * @param srv Display server structure
|
|---|
| 216 | */
|
|---|
| 217 | void display_srv_ev_pending(display_srv_t *srv)
|
|---|
| 218 | {
|
|---|
| 219 | async_exch_t *exch;
|
|---|
| 220 |
|
|---|
| 221 | printf("display_srv_ev_pending()\n");
|
|---|
| 222 |
|
|---|
| 223 | exch = async_exchange_begin(srv->client_sess);
|
|---|
| 224 | async_msg_0(exch, DISPLAY_EV_PENDING);
|
|---|
| 225 | async_exchange_end(exch);
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | /** @}
|
|---|
| 229 | */
|
|---|