From 906510c90750b09d5b05914f03f190c14460e03e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 25 Jul 2026 00:29:35 +0200 Subject: chore: hide protocol implementations --- kernel/kernel/bus/boot_modules.cpp | 68 ++++++++++++++++++++++---------------- kernel/kernel/bus/boot_modules.hpp | 7 +--- 2 files changed, 40 insertions(+), 35 deletions(-) (limited to 'kernel') diff --git a/kernel/kernel/bus/boot_modules.cpp b/kernel/kernel/bus/boot_modules.cpp index ac5a2068..069d414f 100644 --- a/kernel/kernel/bus/boot_modules.cpp +++ b/kernel/kernel/bus/boot_modules.cpp @@ -11,50 +11,60 @@ namespace kernel::bus { - auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool + namespace { - for (auto token : std::views::split(cmdline, ' ')) + auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool { - auto const text = std::string_view{token}; - auto const equals = text.find('='); - if (equals != std::string_view::npos && text.substr(0, equals) == key && text.substr(equals + 1) == value) + for (auto token : std::views::split(cmdline, ' ')) { - return true; + auto const text = std::string_view{token}; + auto const equals = text.find('='); + if (equals != std::string_view::npos && text.substr(0, equals) == key && text.substr(equals + 1) == value) + { + return true; + } } + return false; } - return false; - } - boot_modules::boot_modules() - : kapi::devices::bus{"boot_modules"} - {} + struct boot_modules_protocol : kapi::devices::bus_protocol + { + auto enumerate(kapi::devices::bus &) -> void override + { + // The boot modules virtual bus does not support enumeration. + } - auto boot_modules::enumerate(kapi::devices::bus &) -> void {} + [[nodiscard]] auto match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const + -> kstd::result override + { + auto signature = dev.as(); + auto claim = drv.as(); - auto boot_modules::match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const - -> kstd::result - { - auto signature = dev.as(); - auto claim = drv.as(); + if (!signature || !claim) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } - if (!signature || !claim) - { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } + auto const [key, value] = claim->parameter(); - auto const [key, value] = claim->parameter(); + if (!has_parameter(signature->command_line(), key, value)) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } - if (!has_parameter(signature->command_line(), key, value)) - { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } + return 0u; + } - return 0u; - } + } constinit protocol_instance; + } // namespace + + boot_modules::boot_modules() + : kapi::devices::bus{"boot_modules"} + {} auto boot_modules::protocol() -> kapi::devices::bus_protocol * { - return this; + return &protocol_instance; } } // namespace kernel::bus diff --git a/kernel/kernel/bus/boot_modules.hpp b/kernel/kernel/bus/boot_modules.hpp index 147cfdf2..c73e0d74 100644 --- a/kernel/kernel/bus/boot_modules.hpp +++ b/kernel/kernel/bus/boot_modules.hpp @@ -11,15 +11,10 @@ namespace kernel::bus //! The boot modules bus. //! //! Boot modules used to back devices may be attached to this bus. - struct boot_modules final : kapi::devices::bus, kapi::devices::bus_protocol + struct boot_modules final : kapi::devices::bus { boot_modules(); - auto enumerate(kapi::devices::bus & self) -> void override; - - [[nodiscard]] auto match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const - -> kstd::result override; - [[nodiscard]] auto protocol() -> kapi::devices::bus_protocol * override; }; -- cgit v1.2.3