From e99eb52d9923606dd325862a5f2e649eee0b2d3e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 24 Jul 2026 17:50:16 +0200 Subject: kapi: formally extract device registry --- kapi/kapi/devices.hpp | 2 +- kapi/kapi/devices/device_registry.hpp | 60 +++++++++++++++++++++++++++++++++++ kapi/kapi/devices/manager.hpp | 46 --------------------------- kapi/kapi/test_support/devices.hpp | 1 + 4 files changed, 62 insertions(+), 47 deletions(-) create mode 100644 kapi/kapi/devices/device_registry.hpp delete mode 100644 kapi/kapi/devices/manager.hpp (limited to 'kapi') diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp index 92c8df89..ed082bed 100644 --- a/kapi/kapi/devices.hpp +++ b/kapi/kapi/devices.hpp @@ -7,12 +7,12 @@ #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export +#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export -#include // IWYU pragma: export #include #include diff --git a/kapi/kapi/devices/device_registry.hpp b/kapi/kapi/devices/device_registry.hpp new file mode 100644 index 00000000..00d04311 --- /dev/null +++ b/kapi/kapi/devices/device_registry.hpp @@ -0,0 +1,60 @@ +#ifndef TEACHOS_KAPI_DEVICES_MANAGER_HPP +#define TEACHOS_KAPI_DEVICES_MANAGER_HPP + +// IWYU pragma: private, include + +#include + +#include +#include +#include +#include + +#include + +namespace kapi::devices +{ + + //! @addtogroup kapi-devices-kernel-defined + //! @{ + + struct device_registry + { + device_registry() = default; + + auto static init() -> void; + + auto static get() -> device_registry &; + + //! Add a new device tp the kernel's device registry. + //! + //! @param device The device to register. + //! @return true if the device was registered successfully, false otherwise. + auto add(kstd::shared_ptr device) -> bool; + + //! Remove a device from the kernel's device registry. + //! + //! @param device The device to unregister. + //! @return true if the device was unregistered successfully, false otherwise. + auto remove(device & device) -> bool; + + //! Find a device by its name. + //! + //! @param name the name of the device. + //! @return a shared pointer to the device iff. the device was found and is still alive, nullptr otherwise. + [[nodiscard]] auto find(std::string_view name) const -> kstd::shared_ptr; + + //! Get all currently registered devices. + //! + //! @return every device current reachable through the registry. + [[nodiscard]] auto all() const -> kstd::vector>; + + private: + kstd::flat_map> m_devices{}; + }; + + //! @} + +} // namespace kapi::devices + +#endif \ No newline at end of file diff --git a/kapi/kapi/devices/manager.hpp b/kapi/kapi/devices/manager.hpp deleted file mode 100644 index de6ebf97..00000000 --- a/kapi/kapi/devices/manager.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef TEACHOS_KAPI_DEVICES_MANAGER_HPP -#define TEACHOS_KAPI_DEVICES_MANAGER_HPP - -// IWYU pragma: private, include - -#include - -#include -#include - -#include - -namespace kapi::devices -{ - - //! @addtogroup kapi-devices-kernel-defined - //! @{ - - //! Register a new device with the kernel's device manager. - //! - //! @param device The device to register. - //! @return true if the device was registered successfully, false otherwise. - auto register_device(kstd::shared_ptr device) -> bool; - - //! Unregister a device from the kernel's device manager. - //! - //! @param device The device to unregister. - //! @return true if the device was unregistered successfully, false otherwise. - auto unregister_device(device & device) -> bool; - - //! Find a device by its name. - //! - //! @param name the name of the device. - //! @return a shared pointer to the device iff. the device was found and is still alive, nullptr otherwise. - auto find_device(std::string_view name) -> kstd::shared_ptr; - - //! Get all currently registered devices. - //! - //! @return every device current reachable through the registry. - [[nodiscard]] auto all() -> kstd::vector>; - - //! @} - -} // namespace kapi::devices - -#endif \ No newline at end of file diff --git a/kapi/kapi/test_support/devices.hpp b/kapi/kapi/test_support/devices.hpp index b4d410d6..3cb1cd8b 100644 --- a/kapi/kapi/test_support/devices.hpp +++ b/kapi/kapi/test_support/devices.hpp @@ -6,6 +6,7 @@ namespace kapi::test_support::devices auto deinit() -> void; auto deinit_interface_registry() -> void; auto deinit_driver_registry() -> void; + auto deinit_device_registry() -> void; } // namespace kapi::test_support::devices #endif -- cgit v1.2.3