2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#include "mir/default_configuration_options.h"
20
#include "mir/default_configuration.h"
21
#include "mir/abnormal_exit.h"
26
boost::program_options::options_description desc,
27
mir::options::ProgramOption& options,
31
namespace po = boost::program_options;
36
("help,h", "this help text");
38
options.parse_arguments(desc, argc, argv);
40
if (options.is_set("help"))
42
std::ostringstream help_text;
44
BOOST_THROW_EXCEPTION(mir::AbnormalExit(help_text.str()));
47
catch (po::error const& error)
49
std::ostringstream help_text;
50
help_text << "Failed to parse command line options: " << error.what() << "." << std::endl << desc;
51
BOOST_THROW_EXCEPTION(mir::AbnormalExit(help_text.str()));
55
void parse_environment(
56
boost::program_options::options_description& desc,
57
mir::options::ProgramOption& options)
59
// If MIR_SERVER_HOST_SOCKET is unset, we want to substitute the value of
60
// MIR_SOCKET. Do this now, because MIR_SOCKET will get overwritten later.
61
auto host_socket = getenv("MIR_SERVER_HOST_SOCKET");
62
auto mir_socket = getenv("MIR_SOCKET");
63
if (!host_socket && mir_socket)
64
setenv("MIR_SERVER_HOST_SOCKET", mir_socket, 1);
66
options.parse_environment(desc, "MIR_SERVER_");
70
char const* const mir::ConfigurationOptions::server_socket_opt = "file,f";
71
char const* const mir::ConfigurationOptions::no_server_socket_opt = "no-file";
72
char const* const mir::ConfigurationOptions::enable_input_opt = "enable-input,i";
73
char const* const mir::ConfigurationOptions::session_mediator_report_opt = "session-mediator-report";
74
char const* const mir::ConfigurationOptions::msg_processor_report_opt = "msg-processor-report";
75
char const* const mir::ConfigurationOptions::compositor_report_opt = "compositor-report";
76
char const* const mir::ConfigurationOptions::display_report_opt = "display-report";
77
char const* const mir::ConfigurationOptions::legacy_input_report_opt = "legacy-input-report";
78
char const* const mir::ConfigurationOptions::connector_report_opt = "connector-report";
79
char const* const mir::ConfigurationOptions::scene_report_opt = "scene-report";
80
char const* const mir::ConfigurationOptions::input_report_opt = "input-report";
81
char const* const mir::ConfigurationOptions::host_socket_opt = "host-socket";
82
char const* const mir::ConfigurationOptions::standalone_opt = "standalone";
83
char const* const mir::ConfigurationOptions::frontend_threads_opt = "ipc-thread-pool";
84
char const* const mir::ConfigurationOptions::name_opt = "name";
85
char const* const mir::ConfigurationOptions::offscreen_opt = "offscreen";
87
char const* const mir::ConfigurationOptions::glog = "glog";
88
char const* const mir::ConfigurationOptions::glog_stderrthreshold = "glog-stderrthreshold";
89
char const* const mir::ConfigurationOptions::glog_minloglevel = "glog-minloglevel";
90
char const* const mir::ConfigurationOptions::glog_log_dir = "glog-log-dir";
91
int const mir::ConfigurationOptions::glog_stderrthreshold_default = 2;
92
int const mir::ConfigurationOptions::glog_minloglevel_default = 0;
93
char const* const mir::ConfigurationOptions::glog_log_dir_default = "";
95
bool const mir::ConfigurationOptions::enable_input_default = true;
97
char const* const mir::ConfigurationOptions::off_opt_value = "off";
98
char const* const mir::ConfigurationOptions::log_opt_value = "log";
99
char const* const mir::ConfigurationOptions::lttng_opt_value = "lttng";
101
char const* const mir::ConfigurationOptions::platform_graphics_lib = "platform-graphics-lib";
102
char const* const mir::ConfigurationOptions::default_platform_graphics_lib = "libmirplatformgraphics.so";
105
mir::DefaultConfigurationOptions::DefaultConfigurationOptions(int argc, char const* argv[]) :
108
program_options(std::make_shared<boost::program_options::options_description>(
109
"Command-line options.\n"
110
"Environment variables capitalise long form with prefix \"MIR_SERVER_\" and \"_\" in place of \"-\""))
112
namespace po = boost::program_options;
115
(standalone_opt, po::value<bool>(),
116
"Run mir in standalone mode. [bool:default=false]")
117
(host_socket_opt, po::value<std::string>(),
118
"Host socket filename. [string:default={$MIR_SOCKET,$XDG_RUNTIME_DIR/mir_socket}]")
119
(server_socket_opt, po::value<std::string>()->default_value(::mir::default_server_socket),
121
(no_server_socket_opt, "Do not provide a socket filename for client connections")
122
(platform_graphics_lib, po::value<std::string>()->default_value(default_platform_graphics_lib),
123
"Library to use for platform graphics support")
124
(enable_input_opt, po::value<bool>()->default_value(enable_input_default),
126
(compositor_report_opt, po::value<std::string>()->default_value(off_opt_value),
127
"Compositor reporting [{log,off}]")
128
(connector_report_opt, po::value<std::string>()->default_value(off_opt_value),
129
"How to handle the Connector report. [{log,off}]")
130
(display_report_opt, po::value<std::string>()->default_value(off_opt_value),
131
"How to handle the Display report. [{log,off}]")
132
(input_report_opt, po::value<std::string>()->default_value(off_opt_value),
133
"How to handle to Input report. [{log,lttng,off}]")
134
(legacy_input_report_opt, po::value<std::string>()->default_value(off_opt_value),
135
"How to handle the Legacy Input report. [{log,off}]")
136
(session_mediator_report_opt, po::value<std::string>()->default_value(off_opt_value),
137
"How to handle the SessionMediator report. [{log,off}]")
138
(msg_processor_report_opt, po::value<std::string>()->default_value(off_opt_value),
139
"How to handle the MessageProcessor report. [{log,lttng,off}]")
140
(scene_report_opt, po::value<std::string>()->default_value(off_opt_value),
141
"How to handle the scene report. [{log,off}]")
143
"Use google::GLog for logging")
144
(glog_stderrthreshold, po::value<int>()->default_value(glog_stderrthreshold_default),
145
"Copy log messages at or above this level "
146
"to stderr in addition to logfiles. The numbers "
147
"of severity levels INFO, WARNING, ERROR, and "
148
"FATAL are 0, 1, 2, and 3, respectively.")
149
(glog_minloglevel, po::value<int>()->default_value(glog_minloglevel_default),
150
"Log messages at or above this level. The numbers "
151
"of severity levels INFO, WARNING, ERROR, and "
152
"FATAL are 0, 1, 2, and 3, respectively."
154
(glog_log_dir, po::value<std::string>()->default_value(glog_log_dir_default),
155
"If specified, logfiles are written into this "
156
"directory instead of the default logging directory.")
157
(frontend_threads_opt, po::value<int>()->default_value(default_ipc_threads),
158
"threads in frontend thread pool.")
159
(name_opt, po::value<std::string>(),
160
"When nested, the name Mir uses when registering with the host.")
162
"Render to offscreen buffers instead of the real outputs.")
163
("vt", po::value<int>()->default_value(0), // TODO this not applicable on all graphics platforms
164
"VT to run on or 0 to use current.");
167
boost::program_options::options_description_easy_init mir::DefaultConfigurationOptions::add_options()
170
BOOST_THROW_EXCEPTION(std::logic_error("add_options() must be called before the_options()"));
172
return program_options->add_options();
175
void mir::DefaultConfigurationOptions::parse_options(boost::program_options::options_description& options_description, mir::options::ProgramOption& options) const
177
parse_arguments(options_description, options, argc, argv);
178
parse_environment(options_description, options);
181
std::shared_ptr<mir::options::Option> mir::DefaultConfigurationOptions::the_options() const
185
auto options = std::make_shared<mir::options::ProgramOption>();
186
parse_options(*program_options, *options);
187
this->options = options;