diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-24 19:27:20 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-24 19:27:20 +0200 |
| commit | 3d09b0bd2c35740b34b87c1400e0a3d93647a5d2 (patch) | |
| tree | 3722c12441ef14e824fa192055cc86c785667ee6 /kernel/kapi/boot_module/registry.cpp | |
| parent | 65ba51c7fdcf09dce6b1d690fe059e71d026d1a6 (diff) | |
| download | kernel-3d09b0bd2c35740b34b87c1400e0a3d93647a5d2.tar.xz kernel-3d09b0bd2c35740b34b87c1400e0a3d93647a5d2.zip | |
kapi: extract real boot module registry singleton
Diffstat (limited to 'kernel/kapi/boot_module/registry.cpp')
| -rw-r--r-- | kernel/kapi/boot_module/registry.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/kernel/kapi/boot_module/registry.cpp b/kernel/kapi/boot_module/registry.cpp new file mode 100644 index 00000000..80c76129 --- /dev/null +++ b/kernel/kapi/boot_module/registry.cpp @@ -0,0 +1,131 @@ +#include <kapi/boot_modules/registry.hpp> + +#include <kapi/boot_modules.hpp> +#include <kapi/system.hpp> +#include <kapi/test_support/boot_modules.hpp> + +#include <cstddef> +#include <optional> +#include <utility> + +namespace kapi::boot_modules +{ + + namespace + { + constinit auto instance = std::optional<registry>{}; + } + + auto registry::init() -> void + { + if (instance) + { + system::panic("[OS] Boot module registry has already been initialized."); + } + + instance.emplace(); + } + + auto registry::get() -> registry & + { + if (!instance) + { + system::panic("[OS] Boot module registry has not been initialized."); + } + + return *instance; + } + + auto registry::begin() const noexcept -> const_iterator + { + return m_modules.begin(); + } + + auto registry::end() const noexcept -> const_iterator + { + return m_modules.end(); + } + + auto registry::cbegin() const noexcept -> const_iterator + { + return m_modules.cbegin(); + } + + auto registry::cend() const noexcept -> const_iterator + { + return m_modules.cend(); + } + + auto registry::rbegin() const noexcept -> const_reverse_iterator + { + return m_modules.rbegin(); + } + + auto registry::rend() const noexcept -> const_reverse_iterator + { + return m_modules.rend(); + } + + auto registry::crbegin() const noexcept -> const_reverse_iterator + { + return m_modules.crbegin(); + } + + auto registry::crend() const noexcept -> const_reverse_iterator + { + return m_modules.crend(); + } + + auto registry::front() const noexcept -> const_reference + { + return m_modules.front(); + } + + auto registry::back() const noexcept -> const_reference + { + return m_modules.back(); + } + + auto registry::size() const noexcept -> std::size_t + { + return m_modules.size(); + } + + auto registry::empty() const noexcept -> bool + { + return m_modules.empty(); + } + + auto registry::at(std::size_t index) const -> const_reference + { + return m_modules.at(index); + } + + auto registry::operator[](std::size_t index) const noexcept -> const_reference + { + return m_modules[index]; + } + + auto registry::add(boot_module module) -> void + { + m_modules.push_back(module); + } + +} // namespace kapi::boot_modules + +namespace kapi::test_support::boot_modules +{ + + auto deinit_registry() -> void + { + kapi::boot_modules::instance.reset(); + } + + auto inject_registry(kapi::boot_modules::registry && registry) -> std::optional<kapi::boot_modules::registry> + { + auto old = std::move(kapi::boot_modules::instance); + kapi::boot_modules::instance.emplace(std::move(registry)); + return old; + } + +} // namespace kapi::test_support::boot_modules |
