2 * Copyright © 2019 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include <headless_server.h>
34 handle_sigint(int signal_number, void *data)
36 struct wl_display *display = (struct wl_display *)data;
37 wl_display_terminate(display);
43 init_signal(pepper_compositor_t *compositor)
45 struct wl_display *display;
46 struct wl_event_loop *loop;
47 struct wl_event_source *sigint;
49 display = pepper_compositor_get_display(compositor);
50 loop = wl_display_get_event_loop(display);
51 sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
58 int main(int argc, char *argv[])
60 const char *socket_name = NULL;
61 pepper_compositor_t *compositor = NULL;
64 /* set STDOUT/STDERR bufferless */
65 setvbuf(stdout, NULL, _IONBF, 0);
66 setvbuf(stderr, NULL, _IONBF, 0);
68 if (getenv("PEPPER_DLOG_ENABLE")) {
69 PEPPER_TRACE("pepper log will be written to dlog !\n");
70 pepper_log_dlog_enable(1);
73 socket_name = getenv("WAYLAND_DISPLAY");
76 socket_name = "wayland-0";
78 if (!getenv("XDG_RUNTIME_DIR"))
79 setenv("XDG_RUNTIME_DIR", "/run", 1);
81 /* create pepper compositir */
82 compositor = pepper_compositor_create(socket_name);
83 PEPPER_CHECK(compositor, return EXIT_FAILURE, "Failed to create compositor !");
85 /* Init event trace */
86 ret = headless_debug_init(compositor);
87 PEPPER_CHECK(ret, goto end, "headless_debug_init() failed\n");
89 /* Init input for headless */
90 ret = headless_input_init(compositor);
91 PEPPER_CHECK(ret, goto end, "headless_input_init() failed\n");
94 ret = headless_output_init(compositor);
95 PEPPER_CHECK(ret, goto end, "headless_output_init() failed.\n");
98 ret = headless_shell_init(compositor);
99 PEPPER_CHECK(ret, goto end, "headless_shell_init() failed.\n");
101 /* Init Signal for SIGINT */
102 init_signal(compositor);
105 wl_display_run(pepper_compositor_get_display(compositor));
109 headless_shell_deinit(compositor);
110 headless_input_deinit(compositor);
111 headless_output_deinit(compositor);
112 headless_debug_deinit(compositor);
113 pepper_compositor_destroy(compositor);