source: mainline/uspace/srv/hid/display/main.c@ 9c40b834

Last change on this file since 9c40b834 was 9546146, checked in by Jiri Svoboda <jiri@…>, 16 months ago

Persistently store display/seat configuration.

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