~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to src/server/default_configuration_options.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
Import upstream version 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
 
 */
18
 
 
19
 
#include "mir/default_configuration_options.h"
20
 
#include "mir/default_configuration.h"
21
 
#include "mir/abnormal_exit.h"
22
 
 
23
 
namespace
24
 
{
25
 
void parse_arguments(
26
 
    boost::program_options::options_description desc,
27
 
    mir::options::ProgramOption& options,
28
 
    int argc,
29
 
    char const* argv[])
30
 
{
31
 
    namespace po = boost::program_options;
32
 
 
33
 
    try
34
 
    {
35
 
        desc.add_options()
36
 
            ("help,h", "this help text");
37
 
 
38
 
        options.parse_arguments(desc, argc, argv);
39
 
 
40
 
        if (options.is_set("help"))
41
 
        {
42
 
            std::ostringstream help_text;
43
 
            help_text << desc;
44
 
            BOOST_THROW_EXCEPTION(mir::AbnormalExit(help_text.str()));
45
 
        }
46
 
    }
47
 
    catch (po::error const& error)
48
 
    {
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()));
52
 
    }
53
 
}
54
 
 
55
 
void parse_environment(
56
 
    boost::program_options::options_description& desc,
57
 
    mir::options::ProgramOption& options)
58
 
{
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);
65
 
 
66
 
    options.parse_environment(desc, "MIR_SERVER_");
67
 
}
68
 
}
69
 
 
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";
86
 
 
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 = "";
94
 
 
95
 
bool const mir::ConfigurationOptions::enable_input_default = true;
96
 
 
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";
100
 
 
101
 
char const* const mir::ConfigurationOptions::platform_graphics_lib = "platform-graphics-lib";
102
 
char const* const mir::ConfigurationOptions::default_platform_graphics_lib = "libmirplatformgraphics.so";
103
 
 
104
 
 
105
 
mir::DefaultConfigurationOptions::DefaultConfigurationOptions(int argc, char const* argv[]) :
106
 
    argc(argc),
107
 
    argv(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 \"-\""))
111
 
{
112
 
    namespace po = boost::program_options;
113
 
 
114
 
    add_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),
120
 
            "Socket filename.")
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),
125
 
            "Enable input.")
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}]")
142
 
        (glog,
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."
153
 
            " [int:default=0]")
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.")
161
 
        (offscreen_opt,
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.");
165
 
}
166
 
 
167
 
boost::program_options::options_description_easy_init mir::DefaultConfigurationOptions::add_options()
168
 
{
169
 
    if (options)
170
 
        BOOST_THROW_EXCEPTION(std::logic_error("add_options() must be called before the_options()"));
171
 
 
172
 
    return program_options->add_options();
173
 
}
174
 
 
175
 
void mir::DefaultConfigurationOptions::parse_options(boost::program_options::options_description& options_description, mir::options::ProgramOption& options) const
176
 
{
177
 
    parse_arguments(options_description, options, argc, argv);
178
 
    parse_environment(options_description, options);
179
 
}
180
 
 
181
 
std::shared_ptr<mir::options::Option> mir::DefaultConfigurationOptions::the_options() const
182
 
{
183
 
    if (!options)
184
 
    {
185
 
        auto options = std::make_shared<mir::options::ProgramOption>();
186
 
        parse_options(*program_options, *options);
187
 
        this->options = options;
188
 
    }
189
 
    return options;
190
 
}