source: mainline/uspace/lib/display/src/disp_srv.c@ a2e104e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a2e104e was a2e104e, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Move windows by dragging decoration

Or dragging anywhere with button 2. Need to add Ctrl/Alt/Shift state
to pos_event_t and change the latter to Alt-drag/Shift-drag.

  • Property mode set to 100644
File size: 6.8 KB
Line 
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#include "../private/params.h"
46
47static void display_callback_create_srv(display_srv_t *srv, ipc_call_t *call)
48{
49 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
50 if (sess == NULL) {
51 async_answer_0(call, ENOMEM);
52 return;
53 }
54
55 srv->client_sess = sess;
56 async_answer_0(call, EOK);
57}
58
59static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
60{
61 sysarg_t wnd_id;
62 ipc_call_t call;
63 display_wnd_params_t params;
64 size_t size;
65 errno_t rc;
66
67 if (!async_data_write_receive(&call, &size)) {
68 async_answer_0(&call, EREFUSED);
69 async_answer_0(icall, EREFUSED);
70 return;
71 }
72
73 if (size != sizeof(display_wnd_params_t)) {
74 async_answer_0(&call, EINVAL);
75 async_answer_0(icall, EINVAL);
76 return;
77 }
78
79 rc = async_data_write_finalize(&call, &params, size);
80 if (rc != EOK) {
81 async_answer_0(&call, rc);
82 async_answer_0(icall, rc);
83 return;
84 }
85
86 if (srv->ops->window_create == NULL) {
87 async_answer_0(icall, ENOTSUP);
88 return;
89 }
90
91 rc = srv->ops->window_create(srv->arg, &params, &wnd_id);
92 async_answer_1(icall, rc, wnd_id);
93}
94
95static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
96{
97 sysarg_t wnd_id;
98 errno_t rc;
99
100 wnd_id = ipc_get_arg1(icall);
101
102 if (srv->ops->window_destroy == NULL) {
103 async_answer_0(icall, ENOTSUP);
104 return;
105 }
106
107 rc = srv->ops->window_destroy(srv->arg, wnd_id);
108 async_answer_0(icall, rc);
109}
110
111static void display_window_move_req_srv(display_srv_t *srv, ipc_call_t *icall)
112{
113 sysarg_t wnd_id;
114 ipc_call_t call;
115 gfx_coord2_t pos;
116 size_t size;
117 errno_t rc;
118
119 wnd_id = ipc_get_arg1(icall);
120
121 if (!async_data_write_receive(&call, &size)) {
122 async_answer_0(&call, EREFUSED);
123 async_answer_0(icall, EREFUSED);
124 return;
125 }
126
127 if (size != sizeof(gfx_coord2_t)) {
128 async_answer_0(&call, EINVAL);
129 async_answer_0(icall, EINVAL);
130 return;
131 }
132
133 rc = async_data_write_finalize(&call, &pos, size);
134 if (rc != EOK) {
135 async_answer_0(&call, rc);
136 async_answer_0(icall, rc);
137 return;
138 }
139
140 if (srv->ops->window_move_req == NULL) {
141 async_answer_0(icall, ENOTSUP);
142 return;
143 }
144
145 rc = srv->ops->window_move_req(srv->arg, wnd_id, &pos);
146 async_answer_0(icall, rc);
147}
148
149static void display_window_resize_srv(display_srv_t *srv, ipc_call_t *icall)
150{
151 sysarg_t wnd_id;
152 ipc_call_t call;
153 display_wnd_resize_t wresize;
154 size_t size;
155 errno_t rc;
156
157 wnd_id = ipc_get_arg1(icall);
158
159 if (!async_data_write_receive(&call, &size)) {
160 async_answer_0(&call, EREFUSED);
161 async_answer_0(icall, EREFUSED);
162 return;
163 }
164
165 if (size != sizeof(display_wnd_resize_t)) {
166 async_answer_0(&call, EINVAL);
167 async_answer_0(icall, EINVAL);
168 return;
169 }
170
171 rc = async_data_write_finalize(&call, &wresize, size);
172 if (rc != EOK) {
173 async_answer_0(&call, rc);
174 async_answer_0(icall, rc);
175 return;
176 }
177
178 if (srv->ops->window_resize == NULL) {
179 async_answer_0(icall, ENOTSUP);
180 return;
181 }
182
183 rc = srv->ops->window_resize(srv->arg, wnd_id, &wresize.offs,
184 &wresize.nrect);
185 async_answer_0(icall, rc);
186}
187
188static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall)
189{
190 sysarg_t wnd_id;
191 display_wnd_ev_t event;
192 ipc_call_t call;
193 size_t size;
194 errno_t rc;
195
196 if (srv->ops->get_event == NULL) {
197 async_answer_0(icall, ENOTSUP);
198 return;
199 }
200
201 rc = srv->ops->get_event(srv->arg, &wnd_id, &event);
202 if (rc != EOK) {
203 async_answer_0(icall, rc);
204 return;
205 }
206
207 /* Transfer event data */
208 if (!async_data_read_receive(&call, &size)) {
209 async_answer_0(icall, EREFUSED);
210 return;
211 }
212
213 if (size != sizeof(event)) {
214 async_answer_0(icall, EREFUSED);
215 async_answer_0(&call, EREFUSED);
216 return;
217 }
218
219 rc = async_data_read_finalize(&call, &event, sizeof(event));
220 if (rc != EOK) {
221 async_answer_0(icall, rc);
222 async_answer_0(&call, rc);
223 return;
224 }
225
226 async_answer_1(icall, EOK, wnd_id);
227}
228
229void display_conn(ipc_call_t *icall, display_srv_t *srv)
230{
231 /* Accept the connection */
232 async_accept_0(icall);
233
234 while (true) {
235 ipc_call_t call;
236
237 async_get_call(&call);
238 sysarg_t method = ipc_get_imethod(&call);
239
240 if (!method) {
241 /* The other side has hung up */
242 async_answer_0(&call, EOK);
243 break;
244 }
245
246 switch (method) {
247 case DISPLAY_CALLBACK_CREATE:
248 display_callback_create_srv(srv, &call);
249 break;
250 case DISPLAY_WINDOW_CREATE:
251 display_window_create_srv(srv, &call);
252 break;
253 case DISPLAY_WINDOW_DESTROY:
254 display_window_destroy_srv(srv, &call);
255 break;
256 case DISPLAY_WINDOW_MOVE_REQ:
257 display_window_move_req_srv(srv, &call);
258 break;
259 case DISPLAY_WINDOW_RESIZE:
260 display_window_resize_srv(srv, &call);
261 break;
262 case DISPLAY_GET_EVENT:
263 display_get_event_srv(srv, &call);
264 break;
265 default:
266 async_answer_0(&call, ENOTSUP);
267 }
268 }
269
270 /* Hang up callback session */
271 if (srv->client_sess != NULL) {
272 async_hangup(srv->client_sess);
273 srv->client_sess = NULL;
274 }
275}
276
277/** Initialize display server structure
278 *
279 * @param srv Display server structure to initialize
280 */
281void display_srv_initialize(display_srv_t *srv)
282{
283 memset(srv, 0, sizeof(*srv));
284}
285
286/** Send 'pending' event to client.
287 *
288 * @param srv Display server structure
289 */
290void display_srv_ev_pending(display_srv_t *srv)
291{
292 async_exch_t *exch;
293
294 exch = async_exchange_begin(srv->client_sess);
295 async_msg_0(exch, DISPLAY_EV_PENDING);
296 async_exchange_end(exch);
297}
298
299/** @}
300 */
Note: See TracBrowser for help on using the repository browser.