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

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

Provisional display server output via canvas/guigfx

  • Property mode set to 100644
File size: 3.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 "display.h"
48#include "output.h"
49#include "window.h"
50
51#define NAME "display"
52
53static void display_client_conn(ipc_call_t *, void *);
54
55/** Initialize display server */
56static errno_t display_srv_init(void)
57{
58 ds_display_t *disp = NULL;
59 gfx_context_t *gc = NULL;
60 errno_t rc;
61
62 rc = output_init(&gc);
63 if (rc != EOK)
64 goto error;
65
66 rc = ds_display_create(gc, &disp);
67 if (rc != EOK)
68 goto error;
69
70 log_msg(LOG_DEFAULT, LVL_DEBUG, "display_srv_init()");
71
72 async_set_fallback_port_handler(display_client_conn, disp);
73
74 rc = loc_server_register(NAME);
75 if (rc != EOK) {
76 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
77 rc = EEXIST;
78 }
79
80 service_id_t sid;
81 rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
82 if (rc != EOK) {
83 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
84 rc = EEXIST;
85 goto error;
86 }
87
88 return EOK;
89error:
90 if (gc != NULL)
91 gfx_context_delete(gc);
92 if (disp != NULL)
93 ds_display_destroy(disp);
94 return rc;
95}
96
97/** Handle client connection to display server */
98static void display_client_conn(ipc_call_t *icall, void *arg)
99{
100 display_srv_t srv;
101 sysarg_t wnd_id;
102 sysarg_t svc_id;
103 ds_window_t *wnd;
104 ds_display_t *disp = (ds_display_t *) arg;
105 gfx_context_t *gc;
106
107 log_msg(LOG_DEFAULT, LVL_NOTE, "display_client_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
108 ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
109 ipc_get_arg4(icall));
110
111 (void) icall;
112 (void) arg;
113
114 svc_id = ipc_get_arg2(icall);
115 wnd_id = ipc_get_arg3(icall);
116
117 if (svc_id != 0) {
118 /* Display management */
119 srv.ops = &display_srv_ops;
120 srv.arg = disp;
121
122 display_conn(icall, &srv);
123 } else {
124 /* Window GC */
125 wnd = ds_display_find_window(disp, wnd_id);
126 if (wnd == NULL) {
127 async_answer_0(icall, ENOENT);
128 return;
129 }
130
131 gc = ds_window_get_ctx(wnd);
132 gc_conn(icall, gc);
133 }
134}
135
136int main(int argc, char *argv[])
137{
138 errno_t rc;
139
140 printf("%s: Display server\n", NAME);
141
142 if (log_init(NAME) != EOK) {
143 printf(NAME ": Failed to initialize logging.\n");
144 return 1;
145 }
146
147 rc = display_srv_init();
148 if (rc != EOK)
149 return 1;
150
151 printf(NAME ": Accepting connections.\n");
152 task_retval(0);
153 async_manager();
154
155 return 0;
156}
157
158/** @}
159 */
Note: See TracBrowser for help on using the repository browser.