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 | |
Daniel Nicoara | 76622c3 | 2015-03-18 17:47:54 -0400 | [diff] [blame] | 68 | sync_lock(true); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 69 | splash = splash_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 70 | if (splash == NULL) { |
| 71 | LOG(ERROR, "splash init failed"); |
| 72 | return EXIT_FAILURE; |
| 73 | } |
| 74 | |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 75 | for (i = 0; i < MAX_TERMINALS; i++) |
| 76 | command_flags.exec[i] = default_cmd_line; |
| 77 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 78 | for (;;) { |
| 79 | c = getopt_long(argc, argv, "", command_options, NULL); |
| 80 | |
| 81 | if (c == -1) |
| 82 | break; |
| 83 | |
| 84 | switch (c) { |
| 85 | case FLAG_CLEAR: |
| 86 | splash_set_clear(splash, strtoul(optarg, NULL, 0)); |
| 87 | break; |
| 88 | |
| 89 | case FLAG_DAEMON: |
| 90 | daemonize(); |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 91 | command_flags.standalone = false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 92 | break; |
| 93 | |
| 94 | case FLAG_DEV_MODE: |
| 95 | splash_set_devmode(splash); |
| 96 | break; |
| 97 | |
| 98 | case FLAG_PRINT_RESOLUTION: |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 99 | command_flags.print_resolution = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 100 | break; |
| 101 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 102 | case FLAG_FRAME_INTERVAL: |
| 103 | splash_set_frame_rate(splash, strtoul(optarg, NULL, 0)); |
| 104 | for (i = optind; i < argc; i++) { |
| 105 | splash_add_image(splash, argv[i]); |
| 106 | } |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 107 | command_flags.frame_interval = true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * The DBUS service launches later than the boot-splash service, and |
| 114 | * as a result, when splash_run starts dbus is not yet up, but, by |
| 115 | * the time splash_run completes, it is running. At the same time, |
| 116 | * splash_run needs dbus to determine when chrome is visible. So, |
| 117 | * it creates the dbus object and then passes it back to the caller |
| 118 | * who can then pass it to the other objects that need it |
| 119 | */ |
| 120 | dbus = NULL; |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 121 | if (command_flags.print_resolution) { |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 122 | video = video_init(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 123 | printf("%d %d", video_getwidth(video), video_getheight(video)); |
| 124 | return EXIT_SUCCESS; |
| 125 | } |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 126 | else if (command_flags.frame_interval) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 127 | ret = splash_run(splash, &dbus); |
| 128 | if (ret) { |
| 129 | LOG(ERROR, "splash_run failed: %d", ret); |
| 130 | return EXIT_FAILURE; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * If splash_run didn't create the dbus object (for example, if |
| 136 | * we didn't supply the frame-interval parameter, then go ahead |
| 137 | * and create it now |
| 138 | */ |
| 139 | if (dbus == NULL) { |
| 140 | dbus = dbus_init(); |
| 141 | } |
| 142 | |
| 143 | input_set_dbus(dbus); |
Dominik Behr | 580462b | 2014-11-20 13:50:05 -0800 | [diff] [blame] | 144 | ret = input_run(command_flags.standalone); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 145 | |
| 146 | input_close(); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 147 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 148 | return ret; |
| 149 | } |