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" |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 19 | #include "util.h" |
Stéphane Marchesin | 62561a1 | 2015-12-11 17:32:37 -0800 | [diff] [blame] | 20 | #include "video.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' |
Dominik Behr | 32a7c89 | 2015-10-09 15:47:53 -0700 | [diff] [blame] | 27 | #define FLAG_IMAGE 'i' |
| 28 | #define FLAG_IMAGE_HIRES 'I' |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 29 | #define FLAG_LOOP_START 'l' |
| 30 | #define FLAG_LOOP_INTERVAL 'L' |
| 31 | #define FLAG_LOOP_OFFSET 'o' |
| 32 | #define FLAG_OFFSET 'O' |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 33 | #define FLAG_PRINT_RESOLUTION 'p' |
| 34 | |
| 35 | static struct option command_options[] = { |
| 36 | { "clear", required_argument, NULL, FLAG_CLEAR }, |
| 37 | { "daemon", no_argument, NULL, FLAG_DAEMON }, |
| 38 | { "dev-mode", no_argument, NULL, FLAG_DEV_MODE }, |
| 39 | { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL }, |
| 40 | { "gamma", required_argument, NULL, FLAG_GAMMA }, |
Dominik Behr | 32a7c89 | 2015-10-09 15:47:53 -0700 | [diff] [blame] | 41 | { "image", required_argument, NULL, FLAG_IMAGE }, |
| 42 | { "image-hires", required_argument, NULL, FLAG_IMAGE_HIRES }, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 43 | { "loop-start", required_argument, NULL, FLAG_LOOP_START }, |
| 44 | { "loop-interval", required_argument, NULL, FLAG_LOOP_INTERVAL }, |
| 45 | { "loop-offset", required_argument, NULL, FLAG_LOOP_OFFSET }, |
| 46 | { "offset", required_argument, NULL, FLAG_OFFSET }, |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 47 | { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION }, |
| 48 | { NULL, 0, NULL, 0 } |
| 49 | }; |
| 50 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 51 | typedef struct { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 52 | bool standalone; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 53 | } commandflags_t; |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 54 | |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 55 | static void parse_offset(char* param, int32_t* x, int32_t* y) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 56 | { |
| 57 | char* token; |
| 58 | char* saveptr; |
| 59 | |
| 60 | token = strtok_r(param, ",", &saveptr); |
| 61 | if (token) |
| 62 | *x = strtol(token, NULL, 0); |
| 63 | |
| 64 | token = strtok_r(NULL, ",", &saveptr); |
| 65 | if (token) |
| 66 | *y = strtol(token, NULL, 0); |
| 67 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 68 | |
| 69 | int main(int argc, char* argv[]) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 70 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 71 | int ret; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 72 | int c; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 73 | int32_t x, y; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 74 | splash_t* splash; |
| 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 | |
Douglas Anderson | 4da95cd | 2015-10-05 15:04:30 -0700 | [diff] [blame] | 78 | /* Handle resolution special before splash init */ |
| 79 | for (;;) { |
| 80 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 81 | if (c == -1) { |
| 82 | break; |
| 83 | } else if (c == FLAG_PRINT_RESOLUTION) { |
| 84 | video_t *video = video_init(); |
| 85 | if (!video) |
| 86 | return EXIT_FAILURE; |
| 87 | |
| 88 | printf("%d %d", video_getwidth(video), |
| 89 | video_getheight(video)); |
| 90 | video_close(video); |
| 91 | return EXIT_SUCCESS; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* Reset option parsing */ |
| 96 | optind = 1; |
| 97 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 98 | memset(&command_flags, 0, sizeof(command_flags)); |
| 99 | command_flags.standalone = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 100 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 101 | ret = input_init(); |
| 102 | if (ret) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 103 | LOG(ERROR, "Input init failed"); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 104 | return EXIT_FAILURE; |
| 105 | } |
| 106 | |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 107 | splash = splash_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 108 | if (splash == NULL) { |
| 109 | LOG(ERROR, "splash init failed"); |
| 110 | return EXIT_FAILURE; |
| 111 | } |
| 112 | |
| 113 | for (;;) { |
| 114 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 115 | |
| 116 | if (c == -1) |
| 117 | break; |
| 118 | |
| 119 | switch (c) { |
| 120 | case FLAG_CLEAR: |
| 121 | splash_set_clear(splash, strtoul(optarg, NULL, 0)); |
| 122 | break; |
| 123 | |
| 124 | case FLAG_DAEMON: |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 125 | command_flags.standalone = false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 126 | break; |
| 127 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 128 | case FLAG_FRAME_INTERVAL: |
| 129 | splash_set_default_duration(splash, strtoul(optarg, NULL, 0)); |
| 130 | break; |
| 131 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 132 | case FLAG_DEV_MODE: |
| 133 | splash_set_devmode(splash); |
| 134 | break; |
| 135 | |
Dominik Behr | 32a7c89 | 2015-10-09 15:47:53 -0700 | [diff] [blame] | 136 | case FLAG_IMAGE: |
| 137 | if (!splash_is_hires(splash)) |
| 138 | splash_add_image(splash, optarg); |
| 139 | break; |
| 140 | |
| 141 | case FLAG_IMAGE_HIRES: |
| 142 | if (splash_is_hires(splash)) |
| 143 | splash_add_image(splash, optarg); |
| 144 | break; |
| 145 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 146 | case FLAG_LOOP_START: |
| 147 | splash_set_loop_start(splash, strtoul(optarg, NULL, 0)); |
| 148 | break; |
| 149 | |
| 150 | case FLAG_LOOP_INTERVAL: |
| 151 | splash_set_loop_duration(splash, strtoul(optarg, NULL, 0)); |
| 152 | break; |
| 153 | |
| 154 | case FLAG_LOOP_OFFSET: |
| 155 | parse_offset(optarg, &x, &y); |
| 156 | splash_set_loop_offset(splash, x, y); |
| 157 | break; |
| 158 | |
| 159 | case FLAG_OFFSET: |
| 160 | parse_offset(optarg, &x, &y); |
| 161 | splash_set_offset(splash, x, y); |
| 162 | break; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Stéphane Marchesin | ac14d29 | 2015-12-14 15:27:18 -0800 | [diff] [blame] | 166 | for (int i = optind; i < argc; i++) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 167 | splash_add_image(splash, argv[i]); |
| 168 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 169 | /* |
| 170 | * The DBUS service launches later than the boot-splash service, and |
| 171 | * as a result, when splash_run starts dbus is not yet up, but, by |
| 172 | * the time splash_run completes, it is running. At the same time, |
| 173 | * splash_run needs dbus to determine when chrome is visible. So, |
| 174 | * it creates the dbus object and then passes it back to the caller |
| 175 | * who can then pass it to the other objects that need it |
| 176 | */ |
| 177 | dbus = NULL; |
Douglas Anderson | 4da95cd | 2015-10-05 15:04:30 -0700 | [diff] [blame] | 178 | if (command_flags.standalone == false) { |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 179 | splash_present_term_file(splash); |
| 180 | daemonize(); |
| 181 | } |
| 182 | if (splash_num_images(splash) > 0) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 183 | ret = splash_run(splash, &dbus); |
| 184 | if (ret) { |
Yuly Novikov | 945871e | 2015-05-23 00:00:41 -0400 | [diff] [blame] | 185 | LOG(ERROR, "splash_run failed: %d", ret); |
| 186 | return EXIT_FAILURE; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 189 | splash_destroy(splash); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * If splash_run didn't create the dbus object (for example, if |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 193 | * there are no splash screen images), then go ahead and create |
| 194 | * it now |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 195 | */ |
| 196 | if (dbus == NULL) { |
| 197 | dbus = dbus_init(); |
| 198 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 199 | input_set_dbus(dbus); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 200 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 201 | ret = input_run(command_flags.standalone); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 202 | |
| 203 | input_close(); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 204 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 205 | return ret; |
| 206 | } |