Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 2 | * Copyright 2014 The Chromium OS Authors. All rights reserved. |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 7 | #include <getopt.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 8 | #include <libtsm.h> |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 9 | #include <memory.h> |
| 10 | #include <stdbool.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <unistd.h> |
| 14 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 15 | #include "dbus.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 16 | #include "input.h" |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 17 | #include "splash.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 18 | #include "term.h" |
| 19 | #include "video.h" |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 20 | #include "util.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 21 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 22 | #define FLAG_CLEAR 'c' |
| 23 | #define FLAG_DAEMON 'd' |
| 24 | #define FLAG_DEV_MODE 'e' |
| 25 | #define FLAG_FRAME_INTERVAL 'f' |
| 26 | #define FLAG_GAMMA 'g' |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 27 | #define FLAG_LOOP_START 'l' |
| 28 | #define FLAG_LOOP_INTERVAL 'L' |
| 29 | #define FLAG_LOOP_OFFSET 'o' |
| 30 | #define FLAG_OFFSET 'O' |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 31 | #define FLAG_PRINT_RESOLUTION 'p' |
| 32 | |
| 33 | static struct option command_options[] = { |
| 34 | { "clear", required_argument, NULL, FLAG_CLEAR }, |
| 35 | { "daemon", no_argument, NULL, FLAG_DAEMON }, |
| 36 | { "dev-mode", no_argument, NULL, FLAG_DEV_MODE }, |
| 37 | { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL }, |
| 38 | { "gamma", required_argument, NULL, FLAG_GAMMA }, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 39 | { "loop-start", required_argument, NULL, FLAG_LOOP_START }, |
| 40 | { "loop-interval", required_argument, NULL, FLAG_LOOP_INTERVAL }, |
| 41 | { "loop-offset", required_argument, NULL, FLAG_LOOP_OFFSET }, |
| 42 | { "offset", required_argument, NULL, FLAG_OFFSET }, |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 43 | { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION }, |
| 44 | { NULL, 0, NULL, 0 } |
| 45 | }; |
| 46 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 47 | typedef struct { |
| 48 | bool print_resolution; |
| 49 | bool standalone; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 50 | } commandflags_t; |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 51 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 52 | static |
| 53 | void parse_offset(char* param, int32_t* x, int32_t* y) |
| 54 | { |
| 55 | char* token; |
| 56 | char* saveptr; |
| 57 | |
| 58 | token = strtok_r(param, ",", &saveptr); |
| 59 | if (token) |
| 60 | *x = strtol(token, NULL, 0); |
| 61 | |
| 62 | token = strtok_r(NULL, ",", &saveptr); |
| 63 | if (token) |
| 64 | *y = strtol(token, NULL, 0); |
| 65 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 66 | |
| 67 | int main(int argc, char* argv[]) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 68 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 69 | int ret; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 70 | int c; |
| 71 | int i; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 72 | int32_t x, y; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 73 | splash_t *splash; |
| 74 | video_t *video; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 75 | dbus_t *dbus; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 76 | commandflags_t command_flags; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 77 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 78 | memset(&command_flags, 0, sizeof(command_flags)); |
| 79 | command_flags.standalone = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 80 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 81 | ret = input_init(); |
| 82 | if (ret) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 83 | LOG(ERROR, "Input init failed"); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 84 | return EXIT_FAILURE; |
| 85 | } |
| 86 | |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 87 | splash = splash_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 88 | if (splash == NULL) { |
| 89 | LOG(ERROR, "splash init failed"); |
| 90 | return EXIT_FAILURE; |
| 91 | } |
| 92 | |
| 93 | for (;;) { |
| 94 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 95 | |
| 96 | if (c == -1) |
| 97 | break; |
| 98 | |
| 99 | switch (c) { |
| 100 | case FLAG_CLEAR: |
| 101 | splash_set_clear(splash, strtoul(optarg, NULL, 0)); |
| 102 | break; |
| 103 | |
| 104 | case FLAG_DAEMON: |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 105 | command_flags.standalone = false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 106 | break; |
| 107 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 108 | case FLAG_FRAME_INTERVAL: |
| 109 | splash_set_default_duration(splash, strtoul(optarg, NULL, 0)); |
| 110 | break; |
| 111 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 112 | case FLAG_DEV_MODE: |
| 113 | splash_set_devmode(splash); |
| 114 | break; |
| 115 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 116 | case FLAG_LOOP_START: |
| 117 | splash_set_loop_start(splash, strtoul(optarg, NULL, 0)); |
| 118 | break; |
| 119 | |
| 120 | case FLAG_LOOP_INTERVAL: |
| 121 | splash_set_loop_duration(splash, strtoul(optarg, NULL, 0)); |
| 122 | break; |
| 123 | |
| 124 | case FLAG_LOOP_OFFSET: |
| 125 | parse_offset(optarg, &x, &y); |
| 126 | splash_set_loop_offset(splash, x, y); |
| 127 | break; |
| 128 | |
| 129 | case FLAG_OFFSET: |
| 130 | parse_offset(optarg, &x, &y); |
| 131 | splash_set_offset(splash, x, y); |
| 132 | break; |
| 133 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 134 | case FLAG_PRINT_RESOLUTION: |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 135 | command_flags.print_resolution = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 136 | break; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 140 | for (i = optind; i < argc; i++) |
| 141 | splash_add_image(splash, argv[i]); |
| 142 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 143 | /* |
| 144 | * The DBUS service launches later than the boot-splash service, and |
| 145 | * as a result, when splash_run starts dbus is not yet up, but, by |
| 146 | * the time splash_run completes, it is running. At the same time, |
| 147 | * splash_run needs dbus to determine when chrome is visible. So, |
| 148 | * it creates the dbus object and then passes it back to the caller |
| 149 | * who can then pass it to the other objects that need it |
| 150 | */ |
| 151 | dbus = NULL; |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 152 | if (command_flags.print_resolution) { |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 153 | video = video_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 154 | printf("%d %d", video_getwidth(video), video_getheight(video)); |
| 155 | return EXIT_SUCCESS; |
| 156 | } |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 157 | else if (command_flags.standalone == false) { |
| 158 | splash_present_term_file(splash); |
| 159 | daemonize(); |
| 160 | } |
| 161 | if (splash_num_images(splash) > 0) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 162 | ret = splash_run(splash, &dbus); |
| 163 | if (ret) { |
| 164 | LOG(ERROR, "splash_run failed: %d", ret); |
| 165 | return EXIT_FAILURE; |
| 166 | } |
| 167 | } |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 168 | splash_destroy(splash); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * If splash_run didn't create the dbus object (for example, if |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 172 | * there are no splash screen images), then go ahead and create |
| 173 | * it now |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 174 | */ |
| 175 | if (dbus == NULL) { |
| 176 | dbus = dbus_init(); |
| 177 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 178 | input_set_dbus(dbus); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 179 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 180 | ret = input_run(command_flags.standalone); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 181 | |
| 182 | input_close(); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 183 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 184 | return ret; |
| 185 | } |