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

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

Fix 32-bit build

  • Property mode set to 100644
File size: 4.9 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 libc
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>
47static 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
61static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
62{
63 sysarg_t wnd_id;
64 errno_t rc;
65
66 printf("display_window_create_srv\n");
67
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
77static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
78{
79 sysarg_t wnd_id;
80 errno_t rc;
81
82 printf("display_window_destroy_srv\n");
83
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
95static 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);
111 if (rc != EOK) {
112 async_answer_0(icall, rc);
113 return;
114 }
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
138void display_conn(ipc_call_t *icall, display_srv_t *srv)
139{
140 /* Accept the connection */
141 async_accept_0(icall);
142 printf("display_conn\n");
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
156 printf("display_conn method=%u\n", (unsigned) method);
157 switch (method) {
158 case DISPLAY_CALLBACK_CREATE:
159 display_callback_create_srv(srv, &call);
160 break;
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;
167 case DISPLAY_GET_EVENT:
168 display_get_event_srv(srv, &call);
169 break;
170 default:
171 async_answer_0(&call, ENOTSUP);
172 }
173 }
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 */
186void display_srv_initialize(display_srv_t *srv)
187{
188 memset(srv, 0, sizeof(*srv));
189}
190
191/** Send 'pending' event to client.
192 *
193 * @param srv Display server structure
194 */
195void 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
206/** @}
207 */
Note: See TracBrowser for help on using the repository browser.