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

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

Display server scaffolding

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