[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>
|
---|
[c8cf261] | 39 | #include <errno.h>
|
---|
[b3c185b6] | 40 | #include <io/log.h>
|
---|
[c8cf261] | 41 | #include <ipc/display.h>
|
---|
[959b7ec] | 42 | #include <mem.h>
|
---|
[c8cf261] | 43 | #include <stdlib.h>
|
---|
| 44 | #include <stddef.h>
|
---|
| 45 |
|
---|
[b3c185b6] | 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 |
|
---|
[c8cf261] | 61 | static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 62 | {
|
---|
| 63 | sysarg_t wnd_id;
|
---|
| 64 | errno_t rc;
|
---|
| 65 |
|
---|
[b3c185b6] | 66 | printf("display_window_create_srv\n");
|
---|
| 67 |
|
---|
[c8cf261] | 68 | if (srv->ops->window_create == NULL) {
|
---|
| 69 | async_answer_0(icall, ENOTSUP);
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | rc = srv->ops->window_create(srv->arg, &wnd_id);
|
---|
| 74 | async_answer_1(icall, rc, wnd_id);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 78 | {
|
---|
| 79 | sysarg_t wnd_id;
|
---|
| 80 | errno_t rc;
|
---|
| 81 |
|
---|
[b3c185b6] | 82 | printf("display_window_destroy_srv\n");
|
---|
| 83 |
|
---|
[c8cf261] | 84 | wnd_id = ipc_get_arg1(icall);
|
---|
| 85 |
|
---|
| 86 | if (srv->ops->window_create == NULL) {
|
---|
| 87 | async_answer_0(icall, ENOTSUP);
|
---|
| 88 | return;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | rc = srv->ops->window_destroy(srv->arg, wnd_id);
|
---|
| 92 | async_answer_0(icall, rc);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[b3c185b6] | 95 | static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall)
|
---|
| 96 | {
|
---|
| 97 | sysarg_t wnd_id;
|
---|
| 98 | display_wnd_ev_t event;
|
---|
| 99 | ipc_call_t call;
|
---|
| 100 | size_t size;
|
---|
| 101 | errno_t rc;
|
---|
| 102 |
|
---|
| 103 | printf("display_get_event_srv\n");
|
---|
| 104 |
|
---|
| 105 | if (srv->ops->get_event == NULL) {
|
---|
| 106 | async_answer_0(icall, ENOTSUP);
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | rc = srv->ops->get_event(srv->arg, &wnd_id, &event);
|
---|
[dcac756] | 111 | if (rc != EOK) {
|
---|
[b3c185b6] | 112 | async_answer_0(icall, rc);
|
---|
[dcac756] | 113 | return;
|
---|
| 114 | }
|
---|
[b3c185b6] | 115 |
|
---|
| 116 | /* Transfer event data */
|
---|
| 117 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 118 | async_answer_0(icall, EREFUSED);
|
---|
| 119 | return;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if (size != sizeof(event)) {
|
---|
| 123 | async_answer_0(icall, EREFUSED);
|
---|
| 124 | async_answer_0(&call, EREFUSED);
|
---|
| 125 | return;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | rc = async_data_read_finalize(&call, &event, sizeof(event));
|
---|
| 129 | if (rc != EOK) {
|
---|
| 130 | async_answer_0(icall, rc);
|
---|
| 131 | async_answer_0(&call, rc);
|
---|
| 132 | return;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | async_answer_1(icall, EOK, wnd_id);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[c8cf261] | 138 | void display_conn(ipc_call_t *icall, display_srv_t *srv)
|
---|
| 139 | {
|
---|
| 140 | /* Accept the connection */
|
---|
| 141 | async_accept_0(icall);
|
---|
[b3c185b6] | 142 | printf("display_conn\n");
|
---|
[c8cf261] | 143 |
|
---|
| 144 | while (true) {
|
---|
| 145 | ipc_call_t call;
|
---|
| 146 |
|
---|
| 147 | async_get_call(&call);
|
---|
| 148 | sysarg_t method = ipc_get_imethod(&call);
|
---|
| 149 |
|
---|
| 150 | if (!method) {
|
---|
| 151 | /* The other side has hung up */
|
---|
| 152 | async_answer_0(&call, EOK);
|
---|
| 153 | break;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[bf22cb78] | 156 | printf("display_conn method=%u\n", (unsigned) method);
|
---|
[c8cf261] | 157 | switch (method) {
|
---|
[b3c185b6] | 158 | case DISPLAY_CALLBACK_CREATE:
|
---|
| 159 | display_callback_create_srv(srv, &call);
|
---|
| 160 | break;
|
---|
[c8cf261] | 161 | case DISPLAY_WINDOW_CREATE:
|
---|
| 162 | display_window_create_srv(srv, &call);
|
---|
| 163 | break;
|
---|
| 164 | case DISPLAY_WINDOW_DESTROY:
|
---|
| 165 | display_window_destroy_srv(srv, &call);
|
---|
| 166 | break;
|
---|
[b3c185b6] | 167 | case DISPLAY_GET_EVENT:
|
---|
| 168 | display_get_event_srv(srv, &call);
|
---|
| 169 | break;
|
---|
[c8cf261] | 170 | default:
|
---|
| 171 | async_answer_0(&call, ENOTSUP);
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
[959b7ec] | 174 |
|
---|
| 175 | /* Hang up callback session */
|
---|
| 176 | if (srv->client_sess != NULL) {
|
---|
| 177 | async_hangup(srv->client_sess);
|
---|
| 178 | srv->client_sess = NULL;
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | /** Initialize display server structure
|
---|
| 183 | *
|
---|
| 184 | * @param srv Display server structure to initialize
|
---|
| 185 | */
|
---|
| 186 | void display_srv_initialize(display_srv_t *srv)
|
---|
| 187 | {
|
---|
| 188 | memset(srv, 0, sizeof(*srv));
|
---|
[c8cf261] | 189 | }
|
---|
| 190 |
|
---|
[b3c185b6] | 191 | /** Send 'pending' event to client.
|
---|
| 192 | *
|
---|
| 193 | * @param srv Display server structure
|
---|
| 194 | */
|
---|
| 195 | void display_srv_ev_pending(display_srv_t *srv)
|
---|
| 196 | {
|
---|
| 197 | async_exch_t *exch;
|
---|
| 198 |
|
---|
| 199 | printf("display_srv_ev_pending()\n");
|
---|
| 200 |
|
---|
| 201 | exch = async_exchange_begin(srv->client_sess);
|
---|
| 202 | async_msg_0(exch, DISPLAY_EV_PENDING);
|
---|
| 203 | async_exchange_end(exch);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[c8cf261] | 206 | /** @}
|
---|
| 207 | */
|
---|