source: mainline/uspace/srv/hid/display/main.c@ 0da03df

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

Lock display when destroying client

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[c8cf261]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 *
[159776f]9 * - Redistribution1s of source code must retain the above copyright
[c8cf261]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 <errno.h>
39#include <gfx/context.h>
40#include <str_error.h>
41#include <io/log.h>
[24cf391a]42#include <io/kbd_event.h>
43#include <io/pos_event.h>
[c8cf261]44#include <ipc/services.h>
45#include <ipcgfx/server.h>
46#include <loc.h>
47#include <stdio.h>
48#include <task.h>
[b3c185b6]49#include "client.h"
[c8cf261]50#include "display.h"
[38e5f36c]51#include "dsops.h"
[02f45748]52#include "input.h"
[b3c185b6]53#include "main.h"
[159776f]54#include "output.h"
[cf32dbd]55#include "seat.h"
[6af4b4f]56#include "window.h"
[c8cf261]57
58static void display_client_conn(ipc_call_t *, void *);
[be15256]59static void display_client_ev_pending(void *);
60
[8aef01c]61#ifdef CONFIG_DISP_DOUBLE_BUF
62/*
63 * Double buffering is one way to provide flicker-free display.
64 */
65static ds_display_flags_t disp_flags = df_disp_double_buf;
66#else
67/*
68 * With double buffering disabled, wet screen flicker since front-to-back
69 * rendering is not implemented.
70 */
71static ds_display_flags_t disp_flags = df_none;
72#endif
73
[be15256]74static ds_client_cb_t display_client_cb = {
75 .ev_pending = display_client_ev_pending
76};
[c8cf261]77
[be15256]78static void display_client_ev_pending(void *arg)
79{
80 display_srv_t *srv = (display_srv_t *) arg;
[6c2aba3]81
[be15256]82 display_srv_ev_pending(srv);
83}
84
[c8cf261]85/** Initialize display server */
[87a7cdb]86static errno_t display_srv_init(ds_output_t **routput)
[c8cf261]87{
[6af4b4f]88 ds_display_t *disp = NULL;
[cf32dbd]89 ds_seat_t *seat = NULL;
[87a7cdb]90 ds_output_t *output = NULL;
[159776f]91 gfx_context_t *gc = NULL;
[c8cf261]92 errno_t rc;
93
[b3c185b6]94 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
95
[8aef01c]96 rc = ds_display_create(NULL, disp_flags, &disp);
[159776f]97 if (rc != EOK)
98 goto error;
99
[cf32dbd]100 rc = ds_seat_create(disp, &seat);
101 if (rc != EOK)
102 goto error;
103
[02f45748]104 rc = ds_output_create(&output);
[87a7cdb]105 if (rc != EOK)
106 goto error;
107
108 output->def_display = disp;
109 rc = ds_output_start_discovery(output);
110 if (rc != EOK)
111 goto error;
112
[dbf5d7c]113 rc = ds_input_open(disp);
114 if (rc != EOK)
115 goto error;
116
[6af4b4f]117 async_set_fallback_port_handler(display_client_conn, disp);
[c8cf261]118
119 rc = loc_server_register(NAME);
120 if (rc != EOK) {
121 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
122 rc = EEXIST;
[8630748]123 goto error;
[c8cf261]124 }
125
126 service_id_t sid;
127 rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
128 if (rc != EOK) {
129 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
130 rc = EEXIST;
131 goto error;
132 }
133
[87a7cdb]134 *routput = output;
[c8cf261]135 return EOK;
136error:
[b3c185b6]137#if 0
138 if (disp->input != NULL)
139 ds_input_close(disp);
140#endif
[87a7cdb]141 if (output != NULL)
142 ds_output_destroy(output);
[159776f]143 if (gc != NULL)
144 gfx_context_delete(gc);
[cf32dbd]145 if (seat != NULL)
146 ds_seat_destroy(seat);
[6af4b4f]147 if (disp != NULL)
148 ds_display_destroy(disp);
[c8cf261]149 return rc;
150}
151
152/** Handle client connection to display server */
153static void display_client_conn(ipc_call_t *icall, void *arg)
154{
155 display_srv_t srv;
156 sysarg_t wnd_id;
157 sysarg_t svc_id;
[b3c185b6]158 ds_client_t *client = NULL;
[6af4b4f]159 ds_window_t *wnd;
160 ds_display_t *disp = (ds_display_t *) arg;
[c8cf261]161 gfx_context_t *gc;
[b3c185b6]162 errno_t rc;
[c8cf261]163
[195b7b3]164 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
[c8cf261]165 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
166 ipc_get_arg4(icall));
167
168 (void) icall;
169 (void) arg;
170
171 svc_id = ipc_get_arg2(icall);
172 wnd_id = ipc_get_arg3(icall);
173
174 if (svc_id != 0) {
[b3c185b6]175 /* Create client object */
[be15256]176 rc = ds_client_create(disp, &display_client_cb, &srv, &client);
[b3c185b6]177 if (rc != EOK) {
178 async_answer_0(icall, ENOMEM);
179 return;
180 }
181
182 /* Set up protocol structure */
[959b7ec]183 display_srv_initialize(&srv);
[c8cf261]184 srv.ops = &display_srv_ops;
[b3c185b6]185 srv.arg = client;
[c8cf261]186
[b3c185b6]187 /* Handle connection */
[c8cf261]188 display_conn(icall, &srv);
[b3c185b6]189
[1762ceb]190 ds_display_lock(disp);
[b3c185b6]191 ds_client_destroy(client);
[1762ceb]192 ds_display_unlock(disp);
[c8cf261]193 } else {
[b3c185b6]194 /* Window GC connection */
195
[6af4b4f]196 wnd = ds_display_find_window(disp, wnd_id);
197 if (wnd == NULL) {
198 async_answer_0(icall, ENOENT);
[c8cf261]199 return;
200 }
201
[b7eea3c9]202 /*
203 * XXX We need a way to make sure that the connection does
204 * not stay active after the window had been destroyed
205 */
[6af4b4f]206 gc = ds_window_get_ctx(wnd);
[c8cf261]207 gc_conn(icall, gc);
208 }
209}
210
211int main(int argc, char *argv[])
212{
213 errno_t rc;
[87a7cdb]214 ds_output_t *output;
[c8cf261]215
216 printf("%s: Display server\n", NAME);
217
218 if (log_init(NAME) != EOK) {
219 printf(NAME ": Failed to initialize logging.\n");
220 return 1;
221 }
222
[87a7cdb]223 rc = display_srv_init(&output);
[c8cf261]224 if (rc != EOK)
225 return 1;
226
227 printf(NAME ": Accepting connections.\n");
228 task_retval(0);
229 async_manager();
230
231 return 0;
232}
233
234/** @}
235 */
Note: See TracBrowser for help on using the repository browser.