19
19
#include "mir/shared_library.h"
20
#include "mir/shared_library_loader.h"
21
20
#include "mir/options/default_configuration.h"
22
21
#include "mir/graphics/platform.h"
23
22
#include "mir/default_configuration.h"
24
23
#include "mir/abnormal_exit.h"
24
#include "mir/shared_library_prober.h"
25
#include "../graphics/platform_probe.h"
53
54
char const* const mo::lttng_opt_value = "lttng";
55
56
char const* const mo::platform_graphics_lib = "platform-graphics-lib";
57
char const* const mo::platform_graphics_path = "platform-graphics-path";
59
61
int const default_ipc_threads = 1;
60
62
bool const enable_input_default = true;
61
char const* const default_platform_graphics_lib = MIR_PLATFORM_DRIVER_BINARY;
64
std::shared_ptr<mir::SharedLibrary> graphics_lib;
63
66
// Hack around the way Qt loads mir:
64
67
// platform_api and therefore Mir are loaded via dlopen(..., RTLD_LOCAL).
115
118
"Socket filename [string:default=$XDG_RUNTIME_DIR/mir_socket or /tmp/mir_socket]")
116
119
(no_server_socket_opt, "Do not provide a socket filename for client connections")
117
120
(prompt_socket_opt, "Provide a \"..._trusted\" filename for prompt helper connections")
118
(platform_graphics_lib, po::value<std::string>()->default_value(default_platform_graphics_lib),
119
"Library to use for platform graphics support")
121
(platform_graphics_lib, po::value<std::string>(),
122
"Library to use for platform graphics support (default: autodetect)")
123
(platform_graphics_path, po::value<std::string>()->default_value(MIR_SERVER_PLATFORM_PLUGIN_PATH),
124
"Library to use for platform graphics support (default: " MIR_SERVER_PLATFORM_PLUGIN_PATH ")")
120
125
(enable_input_opt, po::value<bool>()->default_value(enable_input_default),
122
127
(compositor_report_opt, po::value<std::string>()->default_value(off_opt_value),
152
157
add_platform_options();
162
class NullSharedLibraryProberReport : public mir::SharedLibraryProberReport
165
void probing_path(boost::filesystem::path const& /*path*/) override
168
void probing_failed(boost::filesystem::path const& /*path*/, std::exception const& /*error*/) override
171
void loading_library(boost::filesystem::path const& /*filename*/) override
174
void loading_failed(boost::filesystem::path const& /*filename*/, std::exception const& /*error*/) override
155
180
void mo::DefaultConfiguration::add_platform_options()
157
182
namespace po = boost::program_options;
158
183
po::options_description program_options;
159
184
program_options.add_options()
160
185
(platform_graphics_lib,
161
po::value<std::string>()->default_value(default_platform_graphics_lib), "");
186
po::value<std::string>(), "");
187
program_options.add_options()
188
(platform_graphics_path,
189
po::value<std::string>()->default_value(MIR_SERVER_PLATFORM_PLUGIN_PATH),
162
191
mo::ProgramOption options;
163
192
options.parse_arguments(program_options, argc, argv);
165
std::string graphics_libname;
194
ensure_loaded_with_rtld_global();
196
// TODO: We should just load all the platform plugins we can and present their options.
166
197
auto env_libname = ::getenv("MIR_SERVER_PLATFORM_GRAPHICS_LIB");
167
if (!options.is_set(platform_graphics_lib) && env_libname)
169
graphics_libname = std::string{env_libname};
173
graphics_libname = options.get<std::string>(platform_graphics_lib);
176
ensure_loaded_with_rtld_global();
178
auto graphics_lib = load_library(graphics_libname);
179
auto add_platform_options = graphics_lib->load_function<mir::graphics::AddPlatformOptions>(std::string("add_platform_options"));
180
add_platform_options(*this->program_options);
198
auto env_libpath = ::getenv("MIR_SERVER_PLATFORM_GRAPHICS_PATH");
201
if (options.is_set(platform_graphics_lib))
203
graphics_lib = std::make_shared<mir::SharedLibrary>(options.get<std::string>(platform_graphics_lib));
205
else if (env_libname)
207
graphics_lib = std::make_shared<mir::SharedLibrary>(std::string{env_libname});
211
auto const plugin_path = env_libpath ? env_libpath : options.get<std::string>(platform_graphics_path);
212
NullSharedLibraryProberReport nuller;
213
auto plugins = mir::libraries_for_path(plugin_path, nuller);
214
graphics_lib = mir::graphics::module_for_device(plugins);
217
auto add_platform_options = graphics_lib->load_function<mir::graphics::AddPlatformOptions>(std::string("add_platform_options"));
218
add_platform_options(*this->program_options);
222
// We don't actually care at this point if this failed.
223
// Maybe we've been pointed at the wrong place. Maybe this platform doesn't actually
224
// *have* platform-specific options.
225
// Regardless, if we need a platform and can't find one then we'll bail later
226
// in startup with a useful error.
183
230
boost::program_options::options_description_easy_init mo::DefaultConfiguration::add_options()