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