blob: dfe4277103af3b27f4c3adc704406308f41b8bad [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
Dominik Behr580462b2014-11-20 13:50:05 -080074 for (i = 0; i < MAX_TERMINALS; i++)
75 command_flags.exec[i] = default_cmd_line;
76
David Sodmanbbcb0522014-09-19 10:34:07 -070077 for (;;) {
78 c = getopt_long(argc, argv, "", command_options, NULL);
79
80 if (c == -1)
81 break;
82
83 switch (c) {
84 case FLAG_CLEAR:
85 splash_set_clear(splash, strtoul(optarg, NULL, 0));
86 break;
87
88 case FLAG_DAEMON:
89 daemonize();
Dominik Behr580462b2014-11-20 13:50:05 -080090 command_flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -070091 break;
92
93 case FLAG_DEV_MODE:
94 splash_set_devmode(splash);
95 break;
96
97 case FLAG_PRINT_RESOLUTION:
Dominik Behr580462b2014-11-20 13:50:05 -080098 command_flags.print_resolution = true;
David Sodmanbbcb0522014-09-19 10:34:07 -070099 break;
100
David Sodmanbbcb0522014-09-19 10:34:07 -0700101 case FLAG_FRAME_INTERVAL:
102 splash_set_frame_rate(splash, strtoul(optarg, NULL, 0));
103 for (i = optind; i < argc; i++) {
104 splash_add_image(splash, argv[i]);
105 }
Dominik Behr580462b2014-11-20 13:50:05 -0800106 command_flags.frame_interval = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700107 break;
108 }
109 }
110
111 /*
112 * The DBUS service launches later than the boot-splash service, and
113 * as a result, when splash_run starts dbus is not yet up, but, by
114 * the time splash_run completes, it is running. At the same time,
115 * splash_run needs dbus to determine when chrome is visible. So,
116 * it creates the dbus object and then passes it back to the caller
117 * who can then pass it to the other objects that need it
118 */
119 dbus = NULL;
Dominik Behr580462b2014-11-20 13:50:05 -0800120 if (command_flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800121 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700122 printf("%d %d", video_getwidth(video), video_getheight(video));
123 return EXIT_SUCCESS;
124 }
Dominik Behr580462b2014-11-20 13:50:05 -0800125 else if (command_flags.frame_interval) {
David Sodmanbbcb0522014-09-19 10:34:07 -0700126 ret = splash_run(splash, &dbus);
127 if (ret) {
128 LOG(ERROR, "splash_run failed: %d", ret);
129 return EXIT_FAILURE;
130 }
131 }
132
133 /*
134 * If splash_run didn't create the dbus object (for example, if
135 * we didn't supply the frame-interval parameter, then go ahead
136 * and create it now
137 */
138 if (dbus == NULL) {
139 dbus = dbus_init();
140 }
141
142 input_set_dbus(dbus);
Dominik Behr580462b2014-11-20 13:50:05 -0800143 ret = input_run(command_flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700144
145 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700146
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700147 return ret;
148}