From 9367dc70a8144d0417f3d90d2473c759b422d0c8 Mon Sep 17 00:00:00 2001 From: Christopher James Halse Rogers Date: Mon, 9 Sep 2024 11:52:35 +1000 Subject: [PATCH] Configuration: Split options into global and per-module configuration. This lets each module define its own options, without needing the option names to be unique across all modules. Also organises the module-specific options into their own sections at the end of the help text. --- include/platform/mir/options/configuration.h | 21 +- .../mir/options/default_configuration.h | 48 ++++- include/platform/mir/options/program_option.h | 2 +- .../server/mir/default_server_configuration.h | 8 +- .../options/default_configuration.cpp | 195 +++++++++++++++++- src/platform/options/program_option.cpp | 21 +- src/server/default_server_configuration.cpp | 11 +- src/server/graphics/default_configuration.cpp | 10 +- src/server/graphics/platform_probe.cpp | 58 +++--- src/server/graphics/platform_probe.h | 12 +- src/server/server.cpp | 2 +- .../server_configuration_options.cpp | 34 +++ .../command_line_server_configuration.cpp | 1 - .../graphics/test_platform_prober.cpp | 75 ++++--- .../options/test_program_option.cpp | 22 -- 15 files changed, 399 insertions(+), 121 deletions(-) diff --git a/include/platform/mir/options/configuration.h b/include/platform/mir/options/configuration.h index f4af7a7af28..f37a2bbf5be 100644 --- a/include/platform/mir/options/configuration.h +++ b/include/platform/mir/options/configuration.h @@ -23,6 +23,8 @@ namespace mir { +class SharedLibrary; + namespace options { extern char const* const arw_server_socket_opt; @@ -66,17 +68,24 @@ extern char const* const auto_console; extern char const* const vt_option_name; -class Configuration +class OptionsProvider { public: - virtual std::shared_ptr the_options() const = 0; + /** + * The options not associated with a specific loaded module + */ + virtual std::shared_ptr global_options() const = 0; + /** + * All options, including those added by the specified module + */ + virtual auto the_options_for(SharedLibrary const& module) const -> std::shared_ptr = 0; protected: + OptionsProvider() = default; + virtual ~OptionsProvider() = default; - Configuration() = default; - virtual ~Configuration() = default; - Configuration(Configuration const&) = delete; - Configuration& operator=(Configuration const&) = delete; + OptionsProvider(OptionsProvider const&) = delete; + OptionsProvider& operator=(OptionsProvider const&) = delete; }; } } diff --git a/include/platform/mir/options/default_configuration.h b/include/platform/mir/options/default_configuration.h index cb3c9d3ace5..6315d921c15 100644 --- a/include/platform/mir/options/default_configuration.h +++ b/include/platform/mir/options/default_configuration.h @@ -19,15 +19,15 @@ #include "mir/options/configuration.h" #include "mir/options/program_option.h" +#include "mir/shared_library.h" #include #include namespace mir { -class SharedLibrary; namespace options { -class DefaultConfiguration : public Configuration +class DefaultConfiguration : public OptionsProvider { public: DefaultConfiguration(int argc, char const* argv[]); @@ -54,7 +54,8 @@ class DefaultConfiguration : public Configuration void add_platform_options(); // accessed via the base interface, when access to add_options() has been "lost" - std::shared_ptr the_options() const override; + std::shared_ptr global_options() const override; + auto the_options_for(SharedLibrary const& module) const -> std::shared_ptr