~raof/mir/proper-driver-loading

« back to all changes in this revision

Viewing changes to src/platform/options/default_configuration.cpp

  • Committer: Christopher James Halse Rogers
  • Date: 2014-11-27 04:57:28 UTC
  • Revision ID: christopher.halse.rogers@canonical.com-20141127045728-rtlr58ckdkhnbocy
Implement server-side graphics platform probe

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
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"
25
26
 
26
27
#include <dlfcn.h>
27
28
 
53
54
char const* const mo::lttng_opt_value = "lttng";
54
55
 
55
56
char const* const mo::platform_graphics_lib = "platform-graphics-lib";
 
57
char const* const mo::platform_graphics_path = "platform-graphics-path";
56
58
 
57
59
namespace
58
60
{
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;
 
63
 
 
64
std::shared_ptr<mir::SharedLibrary> graphics_lib;
62
65
 
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),
121
126
            "Enable input.")
122
127
        (compositor_report_opt, po::value<std::string>()->default_value(off_opt_value),
152
157
        add_platform_options();
153
158
}
154
159
 
 
160
namespace
 
161
{
 
162
class NullSharedLibraryProberReport : public mir::SharedLibraryProberReport
 
163
{
 
164
public:
 
165
    void probing_path(boost::filesystem::path const& /*path*/) override
 
166
    {
 
167
    }
 
168
    void probing_failed(boost::filesystem::path const& /*path*/, std::exception const& /*error*/) override
 
169
    {
 
170
    }
 
171
    void loading_library(boost::filesystem::path const& /*filename*/) override
 
172
    {
 
173
    }
 
174
    void loading_failed(boost::filesystem::path const& /*filename*/, std::exception const& /*error*/) override
 
175
    {
 
176
    }
 
177
};
 
178
}
 
179
 
155
180
void mo::DefaultConfiguration::add_platform_options()
156
181
{
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),
 
190
        "");
162
191
    mo::ProgramOption options;
163
192
    options.parse_arguments(program_options, argc, argv);
164
193
 
165
 
    std::string graphics_libname;
 
194
    ensure_loaded_with_rtld_global();
 
195
 
 
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)
168
 
    {
169
 
        graphics_libname = std::string{env_libname};
170
 
    }
171
 
    else
172
 
    {
173
 
        graphics_libname = options.get<std::string>(platform_graphics_lib);
174
 
    }
175
 
 
176
 
    ensure_loaded_with_rtld_global();
177
 
 
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");
 
199
    try
 
200
    {
 
201
        if (options.is_set(platform_graphics_lib))
 
202
        {
 
203
            graphics_lib = std::make_shared<mir::SharedLibrary>(options.get<std::string>(platform_graphics_lib));
 
204
        }
 
205
        else if (env_libname)
 
206
        {
 
207
            graphics_lib = std::make_shared<mir::SharedLibrary>(std::string{env_libname});
 
208
        }
 
209
        else
 
210
        {
 
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);
 
215
        }
 
216
 
 
217
        auto add_platform_options = graphics_lib->load_function<mir::graphics::AddPlatformOptions>(std::string("add_platform_options"));
 
218
        add_platform_options(*this->program_options);
 
219
    }
 
220
    catch(...)
 
221
    {
 
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.
 
227
    }
181
228
}
182
229
 
183
230
boost::program_options::options_description_easy_init mo::DefaultConfiguration::add_options()