diff options
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/devices.hpp | 2 | ||||
| -rw-r--r-- | kapi/kapi/devices/device_registry.hpp | 60 | ||||
| -rw-r--r-- | kapi/kapi/devices/manager.hpp | 46 | ||||
| -rw-r--r-- | kapi/kapi/test_support/devices.hpp | 1 |
4 files changed, 62 insertions, 47 deletions
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 <kapi/devices/character_device.hpp> // IWYU pragma: export #include <kapi/devices/cpu.hpp> // IWYU pragma: export #include <kapi/devices/device.hpp> // IWYU pragma: export +#include <kapi/devices/device_registry.hpp> // IWYU pragma: export #include <kapi/devices/driver.hpp> // IWYU pragma: export #include <kapi/devices/driver_registry.hpp> // IWYU pragma: export #include <kapi/devices/error.hpp> // IWYU pragma: export #include <kapi/devices/interface.hpp> // IWYU pragma: export #include <kapi/devices/interface_registry.hpp> // IWYU pragma: export -#include <kapi/devices/manager.hpp> // IWYU pragma: export #include <kstd/memory.hpp> #include <kstd/result.hpp> 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 <kapi/devices.hpp> + +#include <kapi/devices/device.hpp> + +#include <kstd/flat_map.hpp> +#include <kstd/memory.hpp> +#include <kstd/string.hpp> +#include <kstd/vector.hpp> + +#include <string_view> + +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> 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<device>; + + //! Get all currently registered devices. + //! + //! @return every device current reachable through the registry. + [[nodiscard]] auto all() const -> kstd::vector<kstd::shared_ptr<device>>; + + private: + kstd::flat_map<kstd::string, kstd::weak_ptr<device>> 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 <kapi/devices.hpp> - -#include <kapi/devices/device.hpp> - -#include <kstd/memory.hpp> -#include <kstd/vector.hpp> - -#include <string_view> - -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> 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<device>; - - //! Get all currently registered devices. - //! - //! @return every device current reachable through the registry. - [[nodiscard]] auto all() -> kstd::vector<kstd::shared_ptr<device>>; - - //! @} - -} // 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 |
