blob: f0ca46a3d8a1d1744a990a9079cca23f0993da83 [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
David Sodmanbf3f2842014-11-12 08:26:58 -080088 splash = splash_init();
David Sodmanbbcb0522014-09-19 10:34:07 -070089 if (splash == NULL) {
90 LOG(ERROR, "splash init failed");
91 return EXIT_FAILURE;
92 }
93
94 for (;;) {
95 c = getopt_long(argc, argv, "", command_options, NULL);
96
97 if (c == -1)
98 break;
99
100 switch (c) {
101 case FLAG_CLEAR:
102 splash_set_clear(splash, strtoul(optarg, NULL, 0));
103 break;
104
105 case FLAG_DAEMON:
106 daemonize();
Dominik Behr580462b2014-11-20 13:50:05 -0800107 command_flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -0700108 break;
109
David Sodman8ef20062015-01-06 09:23:40 -0800110 case FLAG_FRAME_INTERVAL:
111 splash_set_default_duration(splash, strtoul(optarg, NULL, 0));
112 break;
113
David Sodmanbbcb0522014-09-19 10:34:07 -0700114 case FLAG_DEV_MODE:
David Sodman8ef20062015-01-06 09:23:40 -0800115 command_flags.devmode = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700116 splash_set_devmode(splash);
117 break;
118
David Sodman8ef20062015-01-06 09:23:40 -0800119 case FLAG_LOOP_START:
120 splash_set_loop_start(splash, strtoul(optarg, NULL, 0));
121 break;
122
123 case FLAG_LOOP_INTERVAL:
124 splash_set_loop_duration(splash, strtoul(optarg, NULL, 0));
125 break;
126
127 case FLAG_LOOP_OFFSET:
128 parse_offset(optarg, &x, &y);
129 splash_set_loop_offset(splash, x, y);
130 break;
131
132 case FLAG_OFFSET:
133 parse_offset(optarg, &x, &y);
134 splash_set_offset(splash, x, y);
135 break;
136
David Sodmanbbcb0522014-09-19 10:34:07 -0700137 case FLAG_PRINT_RESOLUTION:
Dominik Behr580462b2014-11-20 13:50:05 -0800138 command_flags.print_resolution = true;
David Sodmanbbcb0522014-09-19 10:34:07 -0700139 break;
David Sodmanbbcb0522014-09-19 10:34:07 -0700140 }
141 }
142
David Sodman8ef20062015-01-06 09:23:40 -0800143 for (i = optind; i < argc; i++)
144 splash_add_image(splash, argv[i]);
145
David Sodmanbbcb0522014-09-19 10:34:07 -0700146 /*
147 * The DBUS service launches later than the boot-splash service, and
148 * as a result, when splash_run starts dbus is not yet up, but, by
149 * the time splash_run completes, it is running. At the same time,
150 * splash_run needs dbus to determine when chrome is visible. So,
151 * it creates the dbus object and then passes it back to the caller
152 * who can then pass it to the other objects that need it
153 */
154 dbus = NULL;
Dominik Behr580462b2014-11-20 13:50:05 -0800155 if (command_flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800156 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700157 printf("%d %d", video_getwidth(video), video_getheight(video));
158 return EXIT_SUCCESS;
159 }
David Sodman8ef20062015-01-06 09:23:40 -0800160 else if (splash_num_images(splash) > 0) {
David Sodmanbbcb0522014-09-19 10:34:07 -0700161 ret = splash_run(splash, &dbus);
162 if (ret) {
163 LOG(ERROR, "splash_run failed: %d", ret);
164 return EXIT_FAILURE;
165 }
166 }
167
168 /*
169 * If splash_run didn't create the dbus object (for example, if
David Sodman8ef20062015-01-06 09:23:40 -0800170 * there are no splash screen images), then go ahead and create
171 * it now
David Sodmanbbcb0522014-09-19 10:34:07 -0700172 */
173 if (dbus == NULL) {
174 dbus = dbus_init();
175 }
David Sodmanbbcb0522014-09-19 10:34:07 -0700176 input_set_dbus(dbus);
David Sodman8ef20062015-01-06 09:23:40 -0800177
Dominik Behr580462b2014-11-20 13:50:05 -0800178 ret = input_run(command_flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700179
180 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700181
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700182 return ret;
183}