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

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

Introduce window focus, housed in a seat object

  • Property mode set to 100644
File size: 5.1 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>
42#include <ipc/services.h>
43#include <ipcgfx/server.h>
44#include <loc.h>
45#include <stdio.h>
46#include <task.h>
[b3c185b6]47#include "client.h"
[c8cf261]48#include "display.h"
[38e5f36c]49#include "dsops.h"
[b3c185b6]50#include "main.h"
[159776f]51#include "output.h"
[cf32dbd]52#include "seat.h"
[6af4b4f]53#include "window.h"
[c8cf261]54
55static void display_client_conn(ipc_call_t *, void *);
[be15256]56static void display_client_ev_pending(void *);
57
58static ds_client_cb_t display_client_cb = {
59 .ev_pending = display_client_ev_pending
60};
[c8cf261]61
[b3c185b6]62static void display_kbd_event(void *arg, kbd_event_t *event)
63{
64 ds_display_t *disp = (ds_display_t *) arg;
65
66 printf("display_kbd_event\n");
67 ds_display_post_kbd_event(disp, event);
68}
69
[be15256]70static void display_client_ev_pending(void *arg)
71{
72 display_srv_t *srv = (display_srv_t *) arg;
73 printf("display_client_ev_pending\n");
74 display_srv_ev_pending(srv);
75}
76
[c8cf261]77/** Initialize display server */
78static errno_t display_srv_init(void)
79{
[6af4b4f]80 ds_display_t *disp = NULL;
[cf32dbd]81 ds_seat_t *seat = NULL;
[159776f]82 gfx_context_t *gc = NULL;
[c8cf261]83 errno_t rc;
84
[b3c185b6]85 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
86
87 rc = ds_display_create(NULL, &disp);
[159776f]88 if (rc != EOK)
89 goto error;
90
[cf32dbd]91 rc = ds_seat_create(disp, &seat);
92 if (rc != EOK)
93 goto error;
94
[b3c185b6]95 rc = output_init(display_kbd_event, (void *) disp, &gc);
[6af4b4f]96 if (rc != EOK)
97 goto error;
98
[b3c185b6]99 disp->gc = gc;
100#if 0
101 rc = ds_input_open(disp);
102 if (rc != EOK)
103 goto error;
104#endif
[6af4b4f]105 async_set_fallback_port_handler(display_client_conn, disp);
[c8cf261]106
107 rc = loc_server_register(NAME);
108 if (rc != EOK) {
109 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
110 rc = EEXIST;
111 }
112
113 service_id_t sid;
114 rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
115 if (rc != EOK) {
116 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
117 rc = EEXIST;
118 goto error;
119 }
120
121 return EOK;
122error:
[b3c185b6]123#if 0
124 if (disp->input != NULL)
125 ds_input_close(disp);
126#endif
[159776f]127 if (gc != NULL)
128 gfx_context_delete(gc);
[cf32dbd]129 if (seat != NULL)
130 ds_seat_destroy(seat);
[6af4b4f]131 if (disp != NULL)
132 ds_display_destroy(disp);
[c8cf261]133 return rc;
134}
135
136/** Handle client connection to display server */
137static void display_client_conn(ipc_call_t *icall, void *arg)
138{
139 display_srv_t srv;
140 sysarg_t wnd_id;
141 sysarg_t svc_id;
[b3c185b6]142 ds_client_t *client = NULL;
[6af4b4f]143 ds_window_t *wnd;
144 ds_display_t *disp = (ds_display_t *) arg;
[c8cf261]145 gfx_context_t *gc;
[b3c185b6]146 errno_t rc;
[c8cf261]147
148 log_msg(LOG_DEFAULT, LVL_NOTE, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
149 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
150 ipc_get_arg4(icall));
151
152 (void) icall;
153 (void) arg;
154
155 svc_id = ipc_get_arg2(icall);
156 wnd_id = ipc_get_arg3(icall);
157
158 if (svc_id != 0) {
[b3c185b6]159 /* Create client object */
[be15256]160 rc = ds_client_create(disp, &display_client_cb, &srv, &client);
[b3c185b6]161 if (rc != EOK) {
162 async_answer_0(icall, ENOMEM);
163 return;
164 }
165
166 /* Set up protocol structure */
[959b7ec]167 display_srv_initialize(&srv);
[c8cf261]168 srv.ops = &display_srv_ops;
[b3c185b6]169 srv.arg = client;
[c8cf261]170
[b3c185b6]171 /* Handle connection */
[c8cf261]172 display_conn(icall, &srv);
[b3c185b6]173
174 ds_client_destroy(client);
[c8cf261]175 } else {
[b3c185b6]176 /* Window GC connection */
177
[6af4b4f]178 wnd = ds_display_find_window(disp, wnd_id);
179 if (wnd == NULL) {
180 async_answer_0(icall, ENOENT);
[c8cf261]181 return;
182 }
183
[6af4b4f]184 gc = ds_window_get_ctx(wnd);
[c8cf261]185 gc_conn(icall, gc);
186 }
187}
188
189int main(int argc, char *argv[])
190{
191 errno_t rc;
192
193 printf("%s: Display server\n", NAME);
194
195 if (log_init(NAME) != EOK) {
196 printf(NAME ": Failed to initialize logging.\n");
197 return 1;
198 }
199
200 rc = display_srv_init();
201 if (rc != EOK)
202 return 1;
203
204 printf(NAME ": Accepting connections.\n");
205 task_retval(0);
206 async_manager();
207
208 return 0;
209}
210
211/** @}
212 */
Note: See TracBrowser for help on using the repository browser.