blob: cc132c060bd1a49cc6ebb3fe8c9aeb6af3f946e7 [file] [log] [blame]
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07001/*
David Sodman8ef20062015-01-06 09:23:40 -08002 * Copyright 2014 The Chromium OS Authors. All rights reserved.
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07003 * 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 "splash.h"
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070018#include "term.h"
19#include "video.h"
David Sodmanbbcb0522014-09-19 10:34:07 -070020#include "util.h"
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070021
David Sodmanbbcb0522014-09-19 10:34:07 -070022#define FLAG_CLEAR 'c'
23#define FLAG_DAEMON 'd'
24#define FLAG_DEV_MODE 'e'
25#define FLAG_FRAME_INTERVAL 'f'
26#define FLAG_GAMMA 'g'
David Sodman8ef20062015-01-06 09:23:40 -080027#define FLAG_LOOP_START 'l'
28#define FLAG_LOOP_INTERVAL 'L'
29#define FLAG_LOOP_OFFSET 'o'
30#define FLAG_OFFSET 'O'
David Sodmanbbcb0522014-09-19 10:34:07 -070031#define FLAG_PRINT_RESOLUTION 'p'
32
33static struct option command_options[] = {
34 { "clear", required_argument, NULL, FLAG_CLEAR },
35 { "daemon", no_argument, NULL, FLAG_DAEMON },
36 { "dev-mode", no_argument, NULL, FLAG_DEV_MODE },
37 { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL },
38 { "gamma", required_argument, NULL, FLAG_GAMMA },
David Sodman8ef20062015-01-06 09:23:40 -080039 { "loop-start", required_argument, NULL, FLAG_LOOP_START },
40 { "loop-interval", required_argument, NULL, FLAG_LOOP_INTERVAL },
41 { "loop-offset", required_argument, NULL, FLAG_LOOP_OFFSET },
42 { "offset", required_argument, NULL, FLAG_OFFSET },
David Sodmanbbcb0522014-09-19 10:34:07 -070043 { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION },
44 { NULL, 0, NULL, 0 }
45};
46
David Sodman8ef20062015-01-06 09:23:40 -080047typedef struct {
48 bool print_resolution;
49 bool standalone;
50 bool devmode;
51} commandflags_t;
Dominik Behr580462b2014-11-20 13:50:05 -080052
David Sodman8ef20062015-01-06 09:23:40 -080053static
54void parse_offset(char* param, int32_t* x, int32_t* y)
55{
56 char* token;
57 char* saveptr;
58
59 token = strtok_r(param, ",", &saveptr);
60 if (token)
61 *x = strtol(token, NULL, 0);
62
63 token = strtok_r(NULL, ",", &saveptr);
64 if (token)
65 *y = strtol(token, NULL, 0);
66}
David Sodmanbbcb0522014-09-19 10:34:07 -070067
68int main(int argc, char* argv[])
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070069{
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070070 int ret;
David Sodmanbbcb0522014-09-19 10:34:07 -070071 int c;
72 int i;
David Sodman8ef20062015-01-06 09:23:40 -080073 int32_t x, y;
David Sodmanbbcb0522014-09-19 10:34:07 -070074 splash_t *splash;
75 video_t *video;
David Sodmanbbcb0522014-09-19 10:34:07 -070076 dbus_t *dbus;
David Sodman8ef20062015-01-06 09:23:40 -080077 commandflags_t command_flags;
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070078
Dominik Behr580462b2014-11-20 13:50:05 -080079 memset(&command_flags, 0, sizeof(command_flags));
80 command_flags.standalone = true;
David Sodmanbbcb0522014-09-19 10:34:07 -070081
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070082 ret = input_init();
83 if (ret) {
David Sodmanbbcb0522014-09-19 10:34:07 -070084 LOG(ERROR, "Input init failed");
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070085 return EXIT_FAILURE;
86 }
87
Daniel Nicoara76622c32015-03-18 17:47:54 -040088 sync_lock(true);
David Sodmanbf3f2842014-11-12 08:26:58 -080089 splash = splash_init();
David Sodmanbbcb0522014-09-19 10:34:07 -070090 if (splash == NULL) {
91 LOG(ERROR, "splash init failed");
92 return EXIT_FAILURE;
93 }
94
95 for (;;) {
96 c = getopt_long(argc, argv, "", command_options, NULL);
97
98 if (c == -1)
99 break;
100
101 switch (c) {
102 case FLAG_CLEAR:
103 splash_set_clear(splash, strtoul(optarg, NULL, 0));
104 break;
105
106 case FLAG_DAEMON:
107 daemonize();
Dominik Behr580462b2014-11-20 13:50:05 -0800108 command_flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -0700109 break;
110
David Sodman8ef20062015-01-06 09:23:40 -0800111 case FLAG_FRAME_INTERVAL:
112 splash_set_default_duration(splash, strtoul(optarg, NULL, 0));
113 break;
114
David Sodmanbbcb0522014-09-19 10:34:07 -0700115 case FLAG_DEV_MODE:
David Sodman8ef20062015-01-06 09:23:40 -0800116 command_flags.devmode = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700117 splash_set_devmode(splash);
118 break;
119
David Sodman8ef20062015-01-06 09:23:40 -0800120 case FLAG_LOOP_START:
121 splash_set_loop_start(splash, strtoul(optarg, NULL, 0));
122 break;
123
124 case FLAG_LOOP_INTERVAL:
125 splash_set_loop_duration(splash, strtoul(optarg, NULL, 0));
126 break;
127
128 case FLAG_LOOP_OFFSET:
129 parse_offset(optarg, &x, &y);
130 splash_set_loop_offset(splash, x, y);
131 break;
132
133 case FLAG_OFFSET:
134 parse_offset(optarg, &x, &y);
135 splash_set_offset(splash, x, y);
136 break;
137
David Sodmanbbcb0522014-09-19 10:34:07 -0700138 case FLAG_PRINT_RESOLUTION:
Dominik Behr580462b2014-11-20 13:50:05 -0800139 command_flags.print_resolution = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700140 break;
David Sodmanbbcb0522014-09-19 10:34:07 -0700141 }
142 }
143
David Sodman8ef20062015-01-06 09:23:40 -0800144 for (i = optind; i < argc; i++)
145 splash_add_image(splash, argv[i]);
146
David Sodmanbbcb0522014-09-19 10:34:07 -0700147 /*
148 * The DBUS service launches later than the boot-splash service, and
149 * as a result, when splash_run starts dbus is not yet up, but, by
150 * the time splash_run completes, it is running. At the same time,
151 * splash_run needs dbus to determine when chrome is visible. So,
152 * it creates the dbus object and then passes it back to the caller
153 * who can then pass it to the other objects that need it
154 */
155 dbus = NULL;
Dominik Behr580462b2014-11-20 13:50:05 -0800156 if (command_flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800157 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700158 printf("%d %d", video_getwidth(video), video_getheight(video));
159 return EXIT_SUCCESS;
160 }
David Sodman8ef20062015-01-06 09:23:40 -0800161 else if (splash_num_images(splash) > 0) {
David Sodmanbbcb0522014-09-19 10:34:07 -0700162 ret = splash_run(splash, &dbus);
163 if (ret) {
164 LOG(ERROR, "splash_run failed: %d", ret);
165 return EXIT_FAILURE;
166 }
167 }
168
169 /*
170 * If splash_run didn't create the dbus object (for example, if
David Sodman8ef20062015-01-06 09:23:40 -0800171 * there are no splash screen images), then go ahead and create
172 * it now
David Sodmanbbcb0522014-09-19 10:34:07 -0700173 */
174 if (dbus == NULL) {
175 dbus = dbus_init();
176 }
David Sodmanbbcb0522014-09-19 10:34:07 -0700177 input_set_dbus(dbus);
David Sodman8ef20062015-01-06 09:23:40 -0800178
Dominik Behr580462b2014-11-20 13:50:05 -0800179 ret = input_run(command_flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700180
181 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700182
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700183 return ret;
184}