Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration: Split options into global and per-module configuration #3590

Merged
merged 19 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d1f1cdd
mir::SharedLibrary: Add a stable Handle for SharedLibrary
RAOF Sep 6, 2024
99aa10a
Configuration: Split options into global and per-module configuration.
RAOF Sep 9, 2024
bed2be1
mo::DefaultConfiguration: Add missing `#include <format>`
RAOF Sep 9, 2024
277ca7d
mo::DefaultConfiguration: Don't accidentally consume an unparsed opti…
RAOF Sep 10, 2024
19a0bdd
mo::DefaultConfiguration: Micro-optimisation
RAOF Sep 10, 2024
3449d22
mg::DefaultConfiguration: Clean up stray debug logging
RAOF Sep 10, 2024
02970b4
mo::DefaultConfiguration: Drop bespoke `LibraryMap` in favour of `uno…
RAOF Sep 10, 2024
46b165c
Run symbols-generator to placate it
RAOF Sep 10, 2024
3010703
m/g/platform_probe.cpp: Sort headers according to style
RAOF Sep 10, 2024
7fd62d0
Appease that beast of the apocalypse a little more
RAOF Sep 10, 2024
4c70400
tests/PlatformProbe: Fix stack-use-after-return
RAOF Sep 12, 2024
3829f96
Rename `OptionsProvider` back to `Configuration`
tarek-y-ismail Sep 30, 2024
8695081
Rename `Configuration::the_options_for` to `options_for`
tarek-y-ismail Sep 30, 2024
9cf38fa
Remove unused catch variable
tarek-y-ismail Sep 30, 2024
ca44d84
Move new symbols from 2.17 and 2.18 stenzas to 2.19
tarek-y-ismail Oct 2, 2024
008af61
Move more stray symbols from 2.17 stenza to 2.19
tarek-y-ismail Oct 2, 2024
b277640
SharedLibrary::Handle no longer defines the hash function in std
mattkae Oct 7, 2024
101d1e0
SharedLibrary::Handle no longer defines the hash function in std (#3625)
mattkae Oct 7, 2024
65ab963
Reinstate ProgramOptionEnv.parse_environment
AlanGriffiths Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/common/mir/shared_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MIR_SHARED_LIBRARY_H_
#define MIR_SHARED_LIBRARY_H_

#include <compare>
#include <string>

namespace mir
Expand Down Expand Up @@ -49,6 +50,22 @@ class SharedLibrary
(void*&)result = load_symbol(function_name.c_str(), version.c_str());
return result;
}

class Handle
{
public:
auto operator<=>(Handle const& rhs) const -> std::strong_ordering;
auto operator==(Handle const& rhs) const -> bool = default;
auto operator!=(Handle const& rhs) const -> bool = default;
private:
friend class SharedLibrary;
friend struct std::hash<Handle>;

Handle(void* handle);
void* handle;
};

auto get_handle() const -> Handle;
private:
void* const so;
void* load_symbol(char const* function_name) const;
Expand All @@ -58,5 +75,10 @@ class SharedLibrary
};
}

template<>
struct std::hash<mir::SharedLibrary::Handle>
{
auto operator()(mir::SharedLibrary::Handle const& h) const noexcept -> std::size_t;
};

#endif /* MIR_SHARED_LIBRARY_H_ */
13 changes: 11 additions & 2 deletions include/platform/mir/options/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace mir
{
class SharedLibrary;

namespace options
{
extern char const* const arw_server_socket_opt;
Expand Down Expand Up @@ -69,12 +71,19 @@ extern char const* const vt_option_name;
class Configuration
{
public:
virtual std::shared_ptr<options::Option> the_options() const = 0;
/**
* The options not associated with a specific loaded module
*/
virtual std::shared_ptr<options::Option> global_options() const = 0;
/**
* All options, including those added by the specified module
*/
virtual auto options_for(SharedLibrary const& module) const -> std::shared_ptr<options::Option> = 0;

protected:

Configuration() = default;
virtual ~Configuration() = default;

Configuration(Configuration const&) = delete;
Configuration& operator=(Configuration const&) = delete;
};
Expand Down
9 changes: 7 additions & 2 deletions include/platform/mir/options/default_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

#include "mir/options/configuration.h"
#include "mir/options/program_option.h"
#include "mir/shared_library.h"
#include <boost/program_options/options_description.hpp>
#include <vector>
#include <unordered_map>

namespace mir
{
class SharedLibrary;
namespace options
{
class DefaultConfiguration : public Configuration
Expand Down Expand Up @@ -54,7 +55,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<options::Option> the_options() const override;
std::shared_ptr<options::Option> global_options() const override;
auto options_for(SharedLibrary const& module) const -> std::shared_ptr<Option> override;

virtual void parse_arguments(
boost::program_options::options_description desc,
Expand All @@ -74,6 +76,9 @@ class DefaultConfiguration : public Configuration
char const** const argv;
std::function<void(int argc, char const* const* argv)> const unparsed_arguments_handler;
std::shared_ptr<boost::program_options::options_description> const program_options;

std::unordered_map<SharedLibrary::Handle, boost::program_options::options_description> module_options_desc;
std::unordered_map<SharedLibrary::Handle, std::shared_ptr<Option>> mutable module_options;
std::shared_ptr<Option> mutable options;
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/platform/mir/options/program_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProgramOption : public Option

void parse_environment(
boost::program_options::options_description const& description,
char const* prefix);
std::function<std::string(std::string)> env_var_name_mapper);

void parse_file(
boost::program_options::options_description const& description,
Expand Down
23 changes: 23 additions & 0 deletions src/common/sharedlibrary/shared_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

#include "mir/shared_library.h"
#include <compare>
#include <cstddef>

#ifdef MIR_DONT_USE_DLVSYM
#include <mir/log.h>
Expand Down Expand Up @@ -74,3 +76,24 @@ void* mir::SharedLibrary::load_symbol(char const* function_name, char const* ver
}
#endif
}

auto mir::SharedLibrary::get_handle() const -> Handle
{
return Handle{so};
}

mir::SharedLibrary::Handle::Handle(void* handle)
: handle{handle}
{
}

auto mir::SharedLibrary::Handle::operator<=>(Handle const& rhs) const -> std::strong_ordering
{
return handle <=> rhs.handle;
}

auto std::hash<mir::SharedLibrary::Handle>::operator()(mir::SharedLibrary::Handle const& handle) const noexcept
-> std::size_t
{
return std::hash<void*>{}(handle.handle);
}
12 changes: 11 additions & 1 deletion src/common/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ global:
non-virtual?thunk?to?mir::logging::Logger::log*;
non-virtual?thunk?to?mir::logging::MultiLogger::log*;
operator*;
std::hash?mir::SharedLibrary::Handle?::operator*;
tarek-y-ismail marked this conversation as resolved.
Show resolved Hide resolved
typeinfo?for?MirInputConfig;
typeinfo?for?MirInputDevice;
typeinfo?for?MirKeyboardConfig;
Expand All @@ -499,6 +500,7 @@ global:
typeinfo?for?mir::IntOwnedFd;
typeinfo?for?mir::NonBlockingExecutor;
typeinfo?for?mir::PosixRWMutex;
typeinfo?for?mir::SharedLibrary::Handle;
tarek-y-ismail marked this conversation as resolved.
Show resolved Hide resolved
typeinfo?for?mir::SharedLibrary;
typeinfo?for?mir::SharedLibraryProberReport;
typeinfo?for?mir::Signal;
Expand Down Expand Up @@ -695,4 +697,12 @@ MIR_COMMON_2.18 {
MirTouchpadConfig::disable_with_external_mouse*;
mir::event_type_to_c_str*;
};
} MIR_COMMON_2.17;
} MIR_COMMON_2.17;

MIR_COMMON_2.19 {
global: extern "C++" {
mir::SharedLibrary::Handle::?Handle*;
mir::SharedLibrary::Handle::operator*;
mir::SharedLibrary::get_handle*;
};
} MIR_COMMON_2.18;
2 changes: 2 additions & 0 deletions src/include/server/mir/default_server_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MIR_DEFAULT_SERVER_CONFIGURATION_H_

#include "mir/cached_ptr.h"
#include "mir/options/option.h"
#include "mir/server_configuration.h"
#include "mir/shell/window_manager_builder.h"

Expand Down Expand Up @@ -347,6 +348,7 @@ class DefaultServerConfiguration : public virtual ServerConfiguration

protected:
std::shared_ptr<options::Option> the_options() const;
auto the_options_provider() const -> std::shared_ptr<options::Configuration>;
std::shared_ptr<input::DefaultInputDeviceHub> the_default_input_device_hub();
std::shared_ptr<graphics::DisplayConfigurationObserver> the_display_configuration_observer();
std::shared_ptr<input::SeatObserver> the_seat_observer();
Expand Down
Loading
Loading