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

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

Introduce ds_display_t, ds_window_t

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