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