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 | |
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 "main.h" |
| 18 | #include "splash.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 19 | #include "term.h" |
| 20 | #include "video.h" |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 21 | #include "util.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 22 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 23 | #define FLAG_CLEAR 'c' |
| 24 | #define FLAG_DAEMON 'd' |
| 25 | #define FLAG_DEV_MODE 'e' |
| 26 | #define FLAG_FRAME_INTERVAL 'f' |
| 27 | #define FLAG_GAMMA 'g' |
| 28 | #define FLAG_PRINT_RESOLUTION 'p' |
| 29 | |
| 30 | static struct option command_options[] = { |
| 31 | { "clear", required_argument, NULL, FLAG_CLEAR }, |
| 32 | { "daemon", no_argument, NULL, FLAG_DAEMON }, |
| 33 | { "dev-mode", no_argument, NULL, FLAG_DEV_MODE }, |
| 34 | { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL }, |
| 35 | { "gamma", required_argument, NULL, FLAG_GAMMA }, |
| 36 | { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION }, |
| 37 | { NULL, 0, NULL, 0 } |
| 38 | }; |
| 39 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 40 | commandflags_t command_flags; |
| 41 | |
| 42 | static char *default_cmd_line[] = { |
| 43 | "/sbin/agetty", |
| 44 | "-", |
| 45 | "9600", |
| 46 | "xterm", |
| 47 | NULL |
| 48 | }; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 49 | |
| 50 | int main(int argc, char* argv[]) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 51 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 52 | int ret; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 53 | int c; |
| 54 | int i; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 55 | splash_t *splash; |
| 56 | video_t *video; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 57 | dbus_t *dbus; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 58 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 59 | memset(&command_flags, 0, sizeof(command_flags)); |
| 60 | command_flags.standalone = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 61 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 62 | ret = input_init(); |
| 63 | if (ret) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 64 | LOG(ERROR, "Input init failed"); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 65 | return EXIT_FAILURE; |
| 66 | } |
| 67 | |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 68 | splash = splash_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 69 | if (splash == NULL) { |
| 70 | LOG(ERROR, "splash init failed"); |
| 71 | return EXIT_FAILURE; |
| 72 | } |
| 73 | |
David Sodman | e46ea8a | 2015-03-13 15:47:12 -0700 | [diff] [blame] | 74 | sync_lock(true); |
| 75 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 76 | for (i = 0; i < MAX_TERMINALS; i++) |
| 77 | command_flags.exec[i] = default_cmd_line; |
| 78 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 79 | for (;;) { |
| 80 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 81 | |
| 82 | if (c == -1) |
| 83 | break; |
| 84 | |
| 85 | switch (c) { |
| 86 | case FLAG_CLEAR: |
| 87 | splash_set_clear(splash, strtoul(optarg, NULL, 0)); |
| 88 | break; |
| 89 | |
| 90 | case FLAG_DAEMON: |
| 91 | daemonize(); |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 92 | command_flags.standalone = false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 93 | break; |
| 94 | |
| 95 | case FLAG_DEV_MODE: |
| 96 | splash_set_devmode(splash); |
| 97 | break; |
| 98 | |
| 99 | case FLAG_PRINT_RESOLUTION: |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 100 | command_flags.print_resolution = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 101 | break; |
| 102 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 103 | case FLAG_FRAME_INTERVAL: |
| 104 | splash_set_frame_rate(splash, strtoul(optarg, NULL, 0)); |
| 105 | for (i = optind; i < argc; i++) { |
| 106 | splash_add_image(splash, argv[i]); |
| 107 | } |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 108 | command_flags.frame_interval = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * The DBUS service launches later than the boot-splash service, and |
| 115 | * as a result, when splash_run starts dbus is not yet up, but, by |
| 116 | * the time splash_run completes, it is running. At the same time, |
| 117 | * splash_run needs dbus to determine when chrome is visible. So, |
| 118 | * it creates the dbus object and then passes it back to the caller |
| 119 | * who can then pass it to the other objects that need it |
| 120 | */ |
| 121 | dbus = NULL; |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 122 | if (command_flags.print_resolution) { |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 123 | video = video_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 124 | printf("%d %d", video_getwidth(video), video_getheight(video)); |
| 125 | return EXIT_SUCCESS; |
| 126 | } |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 127 | else if (command_flags.frame_interval) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 128 | ret = splash_run(splash, &dbus); |
| 129 | if (ret) { |
| 130 | LOG(ERROR, "splash_run failed: %d", ret); |
| 131 | return EXIT_FAILURE; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * If splash_run didn't create the dbus object (for example, if |
| 137 | * we didn't supply the frame-interval parameter, then go ahead |
| 138 | * and create it now |
| 139 | */ |
| 140 | if (dbus == NULL) { |
| 141 | dbus = dbus_init(); |
| 142 | } |
| 143 | |
| 144 | input_set_dbus(dbus); |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 145 | ret = input_run(command_flags.standalone); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 146 | |
| 147 | input_close(); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 148 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 149 | return ret; |
| 150 | } |