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

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

Finish libdisplay tests

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