source: mainline/uspace/srv/hid/display/main.c@ 1543d4c

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1543d4c was 4c6fd56, checked in by Jiri Svoboda <jiri@…>, 23 months ago

loc_server_register() should be callable more than once (API only)

Now loc_server_register() returns a pointer to a loc_srv_t object,
that is then passed to loc_service_register() and
loc_service_add_to_cat().

Added loc_server_unregister() that unregisters the server
and frees the loc_srv_t object.

Updated all callers. The implementation, however, is a stub.
It is not actually possible to call loc_server_register() more
than once, yet.

  • Property mode set to 100644
File size: 8.9 KB
Line 
1/*
2 * Copyright (c) 2023 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 * - Redistribution1s 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 display
30 * @{
31 */
32/**
33 * @file Display server main
34 */
35
36#include <async.h>
37#include <disp_srv.h>
38#include <dispcfg_srv.h>
39#include <errno.h>
40#include <gfx/context.h>
41#include <str_error.h>
42#include <io/log.h>
43#include <io/kbd_event.h>
44#include <io/pos_event.h>
45#include <ipc/services.h>
46#include <ipcgfx/server.h>
47#include <loc.h>
48#include <stdio.h>
49#include <task.h>
50#include <wndmgt_srv.h>
51#include "cfgclient.h"
52#include "cfgops.h"
53#include "client.h"
54#include "display.h"
55#include "dsops.h"
56#include "input.h"
57#include "main.h"
58#include "output.h"
59#include "seat.h"
60#include "window.h"
61#include "wmclient.h"
62#include "wmops.h"
63
64static void display_client_conn(ipc_call_t *, void *);
65static void display_client_ev_pending(void *);
66static void display_wmclient_ev_pending(void *);
67static void display_cfgclient_ev_pending(void *);
68static void display_gc_conn(ipc_call_t *, void *);
69static void display_wndmgt_conn(ipc_call_t *, void *);
70static void display_dispcfg_conn(ipc_call_t *, void *);
71
72#ifdef CONFIG_DISP_DOUBLE_BUF
73/*
74 * Double buffering is one way to provide flicker-free display.
75 */
76static ds_display_flags_t disp_flags = df_disp_double_buf;
77#else
78/*
79 * With double buffering disabled, wet screen flicker since front-to-back
80 * rendering is not implemented.
81 */
82static ds_display_flags_t disp_flags = df_none;
83#endif
84
85static ds_client_cb_t display_client_cb = {
86 .ev_pending = display_client_ev_pending
87};
88
89static ds_wmclient_cb_t display_wmclient_cb = {
90 .ev_pending = display_wmclient_ev_pending
91};
92
93static ds_cfgclient_cb_t display_cfgclient_cb = {
94 .ev_pending = display_cfgclient_ev_pending
95};
96
97static void display_client_ev_pending(void *arg)
98{
99 display_srv_t *srv = (display_srv_t *) arg;
100
101 display_srv_ev_pending(srv);
102}
103
104static void display_wmclient_ev_pending(void *arg)
105{
106 wndmgt_srv_t *srv = (wndmgt_srv_t *) arg;
107
108 wndmgt_srv_ev_pending(srv);
109}
110
111static void display_cfgclient_ev_pending(void *arg)
112{
113 dispcfg_srv_t *srv = (dispcfg_srv_t *) arg;
114
115 dispcfg_srv_ev_pending(srv);
116}
117
118/** Initialize display server */
119static errno_t display_srv_init(ds_output_t **routput)
120{
121 ds_display_t *disp = NULL;
122 ds_seat_t *seat = NULL;
123 ds_output_t *output = NULL;
124 gfx_context_t *gc = NULL;
125 port_id_t disp_port;
126 port_id_t gc_port;
127 port_id_t wm_port;
128 port_id_t dc_port;
129 loc_srv_t *srv = NULL;
130 service_id_t sid = 0;
131 errno_t rc;
132
133 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
134
135 rc = ds_display_create(NULL, disp_flags, &disp);
136 if (rc != EOK)
137 goto error;
138
139 rc = ds_seat_create(disp, "Alice", &seat);
140 if (rc != EOK)
141 goto error;
142
143 rc = ds_output_create(&output);
144 if (rc != EOK)
145 goto error;
146
147 output->def_display = disp;
148 rc = ds_output_start_discovery(output);
149 if (rc != EOK)
150 goto error;
151
152 rc = ds_input_open(disp);
153 if (rc != EOK)
154 goto error;
155
156 rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
157 &disp_port);
158 if (rc != EOK)
159 goto error;
160
161 rc = async_create_port(INTERFACE_GC, display_gc_conn, disp, &gc_port);
162 if (rc != EOK)
163 goto error;
164
165 rc = async_create_port(INTERFACE_WNDMGT, display_wndmgt_conn, disp,
166 &wm_port);
167 if (rc != EOK)
168 goto error;
169
170 rc = async_create_port(INTERFACE_DISPCFG, display_dispcfg_conn, disp,
171 &dc_port);
172 if (rc != EOK)
173 goto error;
174
175 rc = loc_server_register(NAME, &srv);
176 if (rc != EOK) {
177 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
178 rc = EEXIST;
179 goto error;
180 }
181
182 rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, &sid);
183 if (rc != EOK) {
184 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
185 rc = EEXIST;
186 goto error;
187 }
188
189 *routput = output;
190 return EOK;
191error:
192 if (sid != 0)
193 loc_service_unregister(srv, sid);
194 if (srv != NULL)
195 loc_server_unregister(srv);
196 // XXX destroy disp_port
197 // XXX destroy gc_port
198 // XXX destroy wm_port
199 // XXX destroy dc_port
200#if 0
201 if (disp->input != NULL)
202 ds_input_close(disp);
203#endif
204 if (output != NULL)
205 ds_output_destroy(output);
206 if (gc != NULL)
207 gfx_context_delete(gc);
208 if (seat != NULL)
209 ds_seat_destroy(seat);
210 if (disp != NULL)
211 ds_display_destroy(disp);
212 return rc;
213}
214
215/** Handle client connection to display server */
216static void display_client_conn(ipc_call_t *icall, void *arg)
217{
218 display_srv_t srv;
219 sysarg_t svc_id;
220 ds_client_t *client = NULL;
221 ds_display_t *disp = (ds_display_t *) arg;
222 errno_t rc;
223
224 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
225 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
226 ipc_get_arg4(icall));
227
228 svc_id = ipc_get_arg2(icall);
229
230 if (svc_id != 0) {
231 /* Create client object */
232 ds_display_lock(disp);
233 rc = ds_client_create(disp, &display_client_cb, &srv, &client);
234 ds_display_unlock(disp);
235 if (rc != EOK) {
236 async_answer_0(icall, ENOMEM);
237 return;
238 }
239
240 /* Set up protocol structure */
241 display_srv_initialize(&srv);
242 srv.ops = &display_srv_ops;
243 srv.arg = client;
244
245 /* Handle connection */
246 display_conn(icall, &srv);
247
248 ds_display_lock(disp);
249 ds_client_destroy(client);
250 ds_display_unlock(disp);
251 }
252}
253
254/** Handle GC connection to display server */
255static void display_gc_conn(ipc_call_t *icall, void *arg)
256{
257 sysarg_t wnd_id;
258 ds_window_t *wnd;
259 ds_display_t *disp = (ds_display_t *) arg;
260 gfx_context_t *gc;
261
262 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
263 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
264 ipc_get_arg4(icall));
265
266 wnd_id = ipc_get_arg3(icall);
267
268 /* Window GC connection */
269
270 wnd = ds_display_find_window(disp, wnd_id);
271 if (wnd == NULL) {
272 async_answer_0(icall, ENOENT);
273 return;
274 }
275
276 /*
277 * XXX We need a way to make sure that the connection does
278 * not stay active after the window had been destroyed
279 */
280 gc = ds_window_get_ctx(wnd);
281 gc_conn(icall, gc);
282}
283
284/** Handle window management connection to display server */
285static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
286{
287 ds_display_t *disp = (ds_display_t *) arg;
288 errno_t rc;
289 wndmgt_srv_t srv;
290 ds_wmclient_t *wmclient = NULL;
291
292 /* Create WM client object */
293 ds_display_lock(disp);
294 rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
295 ds_display_unlock(disp);
296 if (rc != EOK) {
297 async_answer_0(icall, ENOMEM);
298 return;
299 }
300
301 /* Set up protocol structure */
302 wndmgt_srv_initialize(&srv);
303 srv.ops = &wndmgt_srv_ops;
304 srv.arg = wmclient;
305
306 /* Handle connection */
307 wndmgt_conn(icall, &srv);
308
309 ds_display_lock(disp);
310 ds_wmclient_destroy(wmclient);
311 ds_display_unlock(disp);
312}
313
314/** Handle configuration connection to display server */
315static void display_dispcfg_conn(ipc_call_t *icall, void *arg)
316{
317 ds_display_t *disp = (ds_display_t *) arg;
318 errno_t rc;
319 dispcfg_srv_t srv;
320 ds_cfgclient_t *cfgclient = NULL;
321
322 /* Create CFG client object */
323 ds_display_lock(disp);
324 rc = ds_cfgclient_create(disp, &display_cfgclient_cb, &srv, &cfgclient);
325 ds_display_unlock(disp);
326 if (rc != EOK) {
327 async_answer_0(icall, ENOMEM);
328 return;
329 }
330
331 /* Set up protocol structure */
332 dispcfg_srv_initialize(&srv);
333 srv.ops = &dispcfg_srv_ops;
334 srv.arg = cfgclient;
335
336 /* Handle connection */
337 dispcfg_conn(icall, &srv);
338
339 ds_display_lock(disp);
340 ds_cfgclient_destroy(cfgclient);
341 ds_display_unlock(disp);
342}
343
344int main(int argc, char *argv[])
345{
346 errno_t rc;
347 ds_output_t *output;
348
349 printf("%s: Display server\n", NAME);
350
351 if (log_init(NAME) != EOK) {
352 printf(NAME ": Failed to initialize logging.\n");
353 return 1;
354 }
355
356 rc = display_srv_init(&output);
357 if (rc != EOK)
358 return 1;
359
360 printf(NAME ": Accepting connections.\n");
361 task_retval(0);
362 async_manager();
363
364 return 0;
365}
366
367/** @}
368 */
Note: See TracBrowser for help on using the repository browser.