blob: 105718bea29cc383489a59f62abe6ac81022414d [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
Daniel Nicoara76622c32015-03-18 17:47:54 -040068 sync_lock(true);
David Sodmanbf3f2842014-11-12 08:26:58 -080069 splash = splash_init();
David Sodmanbbcb0522014-09-19 10:34:07 -070070 if (splash == NULL) {
71 LOG(ERROR, "splash init failed");
72 return EXIT_FAILURE;
73 }
74
Dominik Behr580462b2014-11-20 13:50:05 -080075 for (i = 0; i < MAX_TERMINALS; i++)
76 command_flags.exec[i] = default_cmd_line;
77
David Sodmanbbcb0522014-09-19 10:34:07 -070078 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 Behr580462b2014-11-20 13:50:05 -080091 command_flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -070092 break;
93
94 case FLAG_DEV_MODE:
95 splash_set_devmode(splash);
96 break;
97
98 case FLAG_PRINT_RESOLUTION:
Dominik Behr580462b2014-11-20 13:50:05 -080099 command_flags.print_resolution = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700100 break;
101
David Sodmanbbcb0522014-09-19 10:34:07 -0700102 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 Behr580462b2014-11-20 13:50:05 -0800107 command_flags.frame_interval = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700108 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 Behr580462b2014-11-20 13:50:05 -0800121 if (command_flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800122 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700123 printf("%d %d", video_getwidth(video), video_getheight(video));
124 return EXIT_SUCCESS;
125 }
Dominik Behr580462b2014-11-20 13:50:05 -0800126 else if (command_flags.frame_interval) {
David Sodmanbbcb0522014-09-19 10:34:07 -0700127 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 Behr580462b2014-11-20 13:50:05 -0800144 ret = input_run(command_flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700145
146 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700147
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700148 return ret;
149}