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

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

Window event delivery mechanism

  • Property mode set to 100644
File size: 4.5 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 <stdlib.h>
43#include <stddef.h>
44
45#include <stdio.h>
46static void display_callback_create_srv(display_srv_t *srv, ipc_call_t *call)
47{
48 printf("display_callback_create_srv\n");
49
50 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
51 if (sess == NULL) {
52 async_answer_0(call, ENOMEM);
53 return;
54 }
55
56 srv->client_sess = sess;
57 async_answer_0(call, EOK);
58}
59
60static void display_window_create_srv(display_srv_t *srv, ipc_call_t *icall)
61{
62 sysarg_t wnd_id;
63 errno_t rc;
64
65 printf("display_window_create_srv\n");
66
67 if (srv->ops->window_create == NULL) {
68 async_answer_0(icall, ENOTSUP);
69 return;
70 }
71
72 rc = srv->ops->window_create(srv->arg, &wnd_id);
73 async_answer_1(icall, rc, wnd_id);
74}
75
76static void display_window_destroy_srv(display_srv_t *srv, ipc_call_t *icall)
77{
78 sysarg_t wnd_id;
79 errno_t rc;
80
81 printf("display_window_destroy_srv\n");
82
83 wnd_id = ipc_get_arg1(icall);
84
85 if (srv->ops->window_create == NULL) {
86 async_answer_0(icall, ENOTSUP);
87 return;
88 }
89
90 rc = srv->ops->window_destroy(srv->arg, wnd_id);
91 async_answer_0(icall, rc);
92}
93
94static void display_get_event_srv(display_srv_t *srv, ipc_call_t *icall)
95{
96 sysarg_t wnd_id;
97 display_wnd_ev_t event;
98 ipc_call_t call;
99 size_t size;
100 errno_t rc;
101
102 printf("display_get_event_srv\n");
103
104 if (srv->ops->get_event == NULL) {
105 async_answer_0(icall, ENOTSUP);
106 return;
107 }
108
109 rc = srv->ops->get_event(srv->arg, &wnd_id, &event);
110 if (rc != EOK)
111 async_answer_0(icall, rc);
112
113 /* Transfer event data */
114 if (!async_data_read_receive(&call, &size)) {
115 async_answer_0(icall, EREFUSED);
116 return;
117 }
118
119 if (size != sizeof(event)) {
120 async_answer_0(icall, EREFUSED);
121 async_answer_0(&call, EREFUSED);
122 return;
123 }
124
125 rc = async_data_read_finalize(&call, &event, sizeof(event));
126 if (rc != EOK) {
127 async_answer_0(icall, rc);
128 async_answer_0(&call, rc);
129 return;
130 }
131
132 async_answer_1(icall, EOK, wnd_id);
133}
134
135void display_conn(ipc_call_t *icall, display_srv_t *srv)
136{
137 /* Accept the connection */
138 async_accept_0(icall);
139 printf("display_conn\n");
140
141 while (true) {
142 ipc_call_t call;
143
144 async_get_call(&call);
145 sysarg_t method = ipc_get_imethod(&call);
146
147 if (!method) {
148 /* The other side has hung up */
149 async_answer_0(&call, EOK);
150 break;
151 }
152
153 printf("display_conn method=%lu\n", method);
154 switch (method) {
155 case DISPLAY_CALLBACK_CREATE:
156 display_callback_create_srv(srv, &call);
157 break;
158 case DISPLAY_WINDOW_CREATE:
159 display_window_create_srv(srv, &call);
160 break;
161 case DISPLAY_WINDOW_DESTROY:
162 display_window_destroy_srv(srv, &call);
163 break;
164 case DISPLAY_GET_EVENT:
165 display_get_event_srv(srv, &call);
166 break;
167 default:
168 async_answer_0(&call, ENOTSUP);
169 }
170 }
171}
172
173/** Send 'pending' event to client.
174 *
175 * @param srv Display server structure
176 */
177void display_srv_ev_pending(display_srv_t *srv)
178{
179 async_exch_t *exch;
180
181 printf("display_srv_ev_pending()\n");
182
183 exch = async_exchange_begin(srv->client_sess);
184 async_msg_0(exch, DISPLAY_EV_PENDING);
185 async_exchange_end(exch);
186}
187
188/** @}
189 */
Note: See TracBrowser for help on using the repository browser.