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

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

Start adding tests for libdisplay and fix display_close

So far we test display_open() and display_close().
display_conn was not closing the callback session, which led
to display_close waiting indefinitely.

  • 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
114 /* Transfer event data */
115 if (!async_data_read_receive(&call, &size)) {
116 async_answer_0(icall, EREFUSED);
117 return;
118 }
119
120 if (size != sizeof(event)) {
121 async_answer_0(icall, EREFUSED);
122 async_answer_0(&call, EREFUSED);
123 return;
124 }
125
126 rc = async_data_read_finalize(&call, &event, sizeof(event));
127 if (rc != EOK) {
128 async_answer_0(icall, rc);
129 async_answer_0(&call, rc);
130 return;
131 }
132
133 async_answer_1(icall, EOK, wnd_id);
134}
135
136void display_conn(ipc_call_t *icall, display_srv_t *srv)
137{
138 /* Accept the connection */
139 async_accept_0(icall);
140 printf("display_conn\n");
141
142 while (true) {
143 ipc_call_t call;
144
145 async_get_call(&call);
146 sysarg_t method = ipc_get_imethod(&call);
147
148 if (!method) {
149 /* The other side has hung up */
150 async_answer_0(&call, EOK);
151 break;
152 }
153
154 printf("display_conn method=%lu\n", method);
155 switch (method) {
156 case DISPLAY_CALLBACK_CREATE:
157 display_callback_create_srv(srv, &call);
158 break;
159 case DISPLAY_WINDOW_CREATE:
160 display_window_create_srv(srv, &call);
161 break;
162 case DISPLAY_WINDOW_DESTROY:
163 display_window_destroy_srv(srv, &call);
164 break;
165 case DISPLAY_GET_EVENT:
166 display_get_event_srv(srv, &call);
167 break;
168 default:
169 async_answer_0(&call, ENOTSUP);
170 }
171 }
172
173 /* Hang up callback session */
174 if (srv->client_sess != NULL) {
175 async_hangup(srv->client_sess);
176 srv->client_sess = NULL;
177 }
178}
179
180/** Initialize display server structure
181 *
182 * @param srv Display server structure to initialize
183 */
184void display_srv_initialize(display_srv_t *srv)
185{
186 memset(srv, 0, sizeof(*srv));
187}
188
189/** Send 'pending' event to client.
190 *
191 * @param srv Display server structure
192 */
193void display_srv_ev_pending(display_srv_t *srv)
194{
195 async_exch_t *exch;
196
197 printf("display_srv_ev_pending()\n");
198
199 exch = async_exchange_begin(srv->client_sess);
200 async_msg_0(exch, DISPLAY_EV_PENDING);
201 async_exchange_end(exch);
202}
203
204/** @}
205 */
Note: See TracBrowser for help on using the repository browser.