blob: bd0e1fe3316a27cb48b4ace893aa1306d16c1d83 [file] [log] [blame]
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07001/*
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 Behr580462b2014-11-20 13:50:05 -08007#include <getopt.h>
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07008#include <libtsm.h>
Dominik Behr580462b2014-11-20 13:50:05 -08009#include <memory.h>
10#include <stdbool.h>
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070011#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14
Dominik Behr580462b2014-11-20 13:50:05 -080015#include "dbus.h"
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070016#include "input.h"
Dominik Behr580462b2014-11-20 13:50:05 -080017#include "main.h"
18#include "splash.h"
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070019#include "term.h"
20#include "video.h"
David Sodmanbbcb0522014-09-19 10:34:07 -070021#include "util.h"
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070022
David Sodmanbbcb0522014-09-19 10:34:07 -070023#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
30static 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 Behr580462b2014-11-20 13:50:05 -080040commandflags_t command_flags;
41
42static char *default_cmd_line[] = {
43 "/sbin/agetty",
44 "-",
45 "9600",
46 "xterm",
47 NULL
48};
David Sodmanbbcb0522014-09-19 10:34:07 -070049
50int main(int argc, char* argv[])
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070051{
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070052 int ret;
David Sodmanbbcb0522014-09-19 10:34:07 -070053 int c;
54 int i;
David Sodmanbbcb0522014-09-19 10:34:07 -070055 splash_t *splash;
56 video_t *video;
David Sodmanbbcb0522014-09-19 10:34:07 -070057 dbus_t *dbus;
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070058
Dominik Behr580462b2014-11-20 13:50:05 -080059 memset(&command_flags, 0, sizeof(command_flags));
60 command_flags.standalone = true;
David Sodmanbbcb0522014-09-19 10:34:07 -070061
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070062 ret = input_init();
63 if (ret) {
David Sodmanbbcb0522014-09-19 10:34:07 -070064 LOG(ERROR, "Input init failed");
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070065 return EXIT_FAILURE;
66 }
67
David Sodmanbf3f2842014-11-12 08:26:58 -080068 splash = splash_init();
David Sodmanbbcb0522014-09-19 10:34:07 -070069 if (splash == NULL) {
70 LOG(ERROR, "splash init failed");
71 return EXIT_FAILURE;
72 }
73
David Sodmane46ea8a2015-03-13 15:47:12 -070074 sync_lock(true);
75
Dominik Behr580462b2014-11-20 13:50:05 -080076 for (i = 0; i < MAX_TERMINALS; i++)
77 command_flags.exec[i] = default_cmd_line;
78
David Sodmanbbcb0522014-09-19 10:34:07 -070079 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 Behr580462b2014-11-20 13:50:05 -080092 command_flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -070093 break;
94
95 case FLAG_DEV_MODE:
96 splash_set_devmode(splash);
97 break;
98
99 case FLAG_PRINT_RESOLUTION:
Dominik Behr580462b2014-11-20 13:50:05 -0800100 command_flags.print_resolution = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700101 break;
102
David Sodmanbbcb0522014-09-19 10:34:07 -0700103 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 Behr580462b2014-11-20 13:50:05 -0800108 command_flags.frame_interval = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700109 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 Behr580462b2014-11-20 13:50:05 -0800122 if (command_flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800123 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700124 printf("%d %d", video_getwidth(video), video_getheight(video));
125 return EXIT_SUCCESS;
126 }
Dominik Behr580462b2014-11-20 13:50:05 -0800127 else if (command_flags.frame_interval) {
David Sodmanbbcb0522014-09-19 10:34:07 -0700128 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 Behr580462b2014-11-20 13:50:05 -0800145 ret = input_run(command_flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700146
147 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700148
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700149 return ret;
150}