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

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

Move implementation of display ops to a separate module

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