Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #include <libtsm.h> |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <unistd.h> |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 11 | #include <memory.h> |
| 12 | #include <getopt.h> |
| 13 | #include <stdbool.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 14 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 15 | #include "input.h" |
| 16 | #include "term.h" |
| 17 | #include "video.h" |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 18 | #include "dbus.h" |
| 19 | #include "util.h" |
| 20 | #include "splash.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' |
| 27 | #define FLAG_PRINT_RESOLUTION 'p' |
| 28 | |
| 29 | static struct option command_options[] = { |
| 30 | { "clear", required_argument, NULL, FLAG_CLEAR }, |
| 31 | { "daemon", no_argument, NULL, FLAG_DAEMON }, |
| 32 | { "dev-mode", no_argument, NULL, FLAG_DEV_MODE }, |
| 33 | { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL }, |
| 34 | { "gamma", required_argument, NULL, FLAG_GAMMA }, |
| 35 | { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION }, |
| 36 | { NULL, 0, NULL, 0 } |
| 37 | }; |
| 38 | |
Ilja Friedel | 268188e | 2014-12-03 18:34:04 +0000 | [diff] [blame] | 39 | typedef struct { |
| 40 | bool print_resolution; |
| 41 | bool frame_interval; |
| 42 | bool standalone; |
| 43 | } commandflags_t; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 44 | |
| 45 | int main(int argc, char* argv[]) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 46 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 47 | int ret; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 48 | int c; |
| 49 | int i; |
Ilja Friedel | 268188e | 2014-12-03 18:34:04 +0000 | [diff] [blame] | 50 | commandflags_t flags; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 51 | splash_t *splash; |
| 52 | video_t *video; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 53 | dbus_t *dbus; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 54 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 55 | memset(&flags, 0, sizeof(flags)); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 56 | flags.standalone = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 57 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 58 | ret = input_init(); |
| 59 | if (ret) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 60 | LOG(ERROR, "Input init failed"); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 61 | return EXIT_FAILURE; |
| 62 | } |
| 63 | |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 64 | splash = splash_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 65 | if (splash == NULL) { |
| 66 | LOG(ERROR, "splash init failed"); |
| 67 | return EXIT_FAILURE; |
| 68 | } |
| 69 | |
| 70 | for (;;) { |
| 71 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 72 | |
| 73 | if (c == -1) |
| 74 | break; |
| 75 | |
| 76 | switch (c) { |
| 77 | case FLAG_CLEAR: |
| 78 | splash_set_clear(splash, strtoul(optarg, NULL, 0)); |
| 79 | break; |
| 80 | |
| 81 | case FLAG_DAEMON: |
| 82 | daemonize(); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 83 | flags.standalone = false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 84 | break; |
| 85 | |
| 86 | case FLAG_DEV_MODE: |
| 87 | splash_set_devmode(splash); |
| 88 | break; |
| 89 | |
| 90 | case FLAG_PRINT_RESOLUTION: |
| 91 | flags.print_resolution = true; |
| 92 | break; |
| 93 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 94 | case FLAG_FRAME_INTERVAL: |
| 95 | splash_set_frame_rate(splash, strtoul(optarg, NULL, 0)); |
| 96 | for (i = optind; i < argc; i++) { |
| 97 | splash_add_image(splash, argv[i]); |
| 98 | } |
| 99 | flags.frame_interval = true; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * The DBUS service launches later than the boot-splash service, and |
| 106 | * as a result, when splash_run starts dbus is not yet up, but, by |
| 107 | * the time splash_run completes, it is running. At the same time, |
| 108 | * splash_run needs dbus to determine when chrome is visible. So, |
| 109 | * it creates the dbus object and then passes it back to the caller |
| 110 | * who can then pass it to the other objects that need it |
| 111 | */ |
| 112 | dbus = NULL; |
| 113 | if (flags.print_resolution) { |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 114 | video = video_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 115 | printf("%d %d", video_getwidth(video), video_getheight(video)); |
| 116 | return EXIT_SUCCESS; |
| 117 | } |
| 118 | else if (flags.frame_interval) { |
| 119 | ret = splash_run(splash, &dbus); |
| 120 | if (ret) { |
| 121 | LOG(ERROR, "splash_run failed: %d", ret); |
| 122 | return EXIT_FAILURE; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * If splash_run didn't create the dbus object (for example, if |
| 128 | * we didn't supply the frame-interval parameter, then go ahead |
| 129 | * and create it now |
| 130 | */ |
| 131 | if (dbus == NULL) { |
| 132 | dbus = dbus_init(); |
| 133 | } |
| 134 | |
| 135 | input_set_dbus(dbus); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 136 | ret = input_run(flags.standalone); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 137 | |
| 138 | input_close(); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 139 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 140 | return ret; |
| 141 | } |