blob: e821c226630c92e35ef9d9ca87397a37572ca554 [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
7#include <libtsm.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h>
David Sodmanbbcb0522014-09-19 10:34:07 -070011#include <memory.h>
12#include <getopt.h>
13#include <stdbool.h>
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070014
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070015#include "input.h"
16#include "term.h"
17#include "video.h"
David Sodmanbbcb0522014-09-19 10:34:07 -070018#include "dbus.h"
19#include "util.h"
20#include "splash.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'
27#define FLAG_PRINT_RESOLUTION 'p'
28
29static struct option command_options[] = {
30 { "clear", required_argument, NULL, FLAG_CLEAR },
31 { "daemon", no_argument, NULL, FLAG_DAEMON },
32 { "dev-mode", no_argument, NULL, FLAG_DEV_MODE },
33 { "frame-interval", required_argument, NULL, FLAG_FRAME_INTERVAL },
34 { "gamma", required_argument, NULL, FLAG_GAMMA },
35 { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION },
36 { NULL, 0, NULL, 0 }
37};
38
39typedef struct {
40 bool print_resolution;
41 bool frame_interval;
David Sodmanbf3f2842014-11-12 08:26:58 -080042 bool standalone;
David Sodmanbbcb0522014-09-19 10:34:07 -070043} commandflags_t;
44
45int main(int argc, char* argv[])
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070046{
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070047 int ret;
David Sodmanbbcb0522014-09-19 10:34:07 -070048 int c;
49 int i;
50 commandflags_t flags;
51 splash_t *splash;
52 video_t *video;
David Sodmanbbcb0522014-09-19 10:34:07 -070053 dbus_t *dbus;
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070054
David Sodmanbbcb0522014-09-19 10:34:07 -070055 memset(&flags, 0, sizeof(flags));
David Sodmanbf3f2842014-11-12 08:26:58 -080056 flags.standalone = true;
David Sodmanbbcb0522014-09-19 10:34:07 -070057
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070058 ret = input_init();
59 if (ret) {
David Sodmanbbcb0522014-09-19 10:34:07 -070060 LOG(ERROR, "Input init failed");
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070061 return EXIT_FAILURE;
62 }
63
David Sodmanbf3f2842014-11-12 08:26:58 -080064 splash = splash_init();
David Sodmanbbcb0522014-09-19 10:34:07 -070065 if (splash == NULL) {
66 LOG(ERROR, "splash init failed");
67 return EXIT_FAILURE;
68 }
69
70 for (;;) {
71 c = getopt_long(argc, argv, "", command_options, NULL);
72
73 if (c == -1)
74 break;
75
76 switch (c) {
77 case FLAG_CLEAR:
78 splash_set_clear(splash, strtoul(optarg, NULL, 0));
79 break;
80
81 case FLAG_DAEMON:
82 daemonize();
David Sodmanbf3f2842014-11-12 08:26:58 -080083 flags.standalone = false;
David Sodmanbbcb0522014-09-19 10:34:07 -070084 break;
85
86 case FLAG_DEV_MODE:
87 splash_set_devmode(splash);
88 break;
89
90 case FLAG_PRINT_RESOLUTION:
91 flags.print_resolution = true;
92 break;
93
David Sodmanbbcb0522014-09-19 10:34:07 -070094 case FLAG_FRAME_INTERVAL:
95 splash_set_frame_rate(splash, strtoul(optarg, NULL, 0));
96 for (i = optind; i < argc; i++) {
97 splash_add_image(splash, argv[i]);
98 }
99 flags.frame_interval = true;
100 break;
101 }
102 }
103
104 /*
105 * The DBUS service launches later than the boot-splash service, and
106 * as a result, when splash_run starts dbus is not yet up, but, by
107 * the time splash_run completes, it is running. At the same time,
108 * splash_run needs dbus to determine when chrome is visible. So,
109 * it creates the dbus object and then passes it back to the caller
110 * who can then pass it to the other objects that need it
111 */
112 dbus = NULL;
113 if (flags.print_resolution) {
David Sodmanbf3f2842014-11-12 08:26:58 -0800114 video = video_init();
David Sodmanbbcb0522014-09-19 10:34:07 -0700115 printf("%d %d", video_getwidth(video), video_getheight(video));
116 return EXIT_SUCCESS;
117 }
118 else if (flags.frame_interval) {
119 ret = splash_run(splash, &dbus);
120 if (ret) {
121 LOG(ERROR, "splash_run failed: %d", ret);
122 return EXIT_FAILURE;
123 }
124 }
125
126 /*
127 * If splash_run didn't create the dbus object (for example, if
128 * we didn't supply the frame-interval parameter, then go ahead
129 * and create it now
130 */
131 if (dbus == NULL) {
132 dbus = dbus_init();
133 }
134
135 input_set_dbus(dbus);
David Sodmanbf3f2842014-11-12 08:26:58 -0800136 ret = input_run(flags.standalone);
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700137
138 input_close();
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -0700139
140 return ret;
141}