From 4cc05543d48a35908b0756e133bd668745bd95c3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 26 Jul 2026 13:23:46 +0200 Subject: kapi: implement device removal --- kapi/kapi/devices/device_registry.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'kapi') diff --git a/kapi/kapi/devices/device_registry.hpp b/kapi/kapi/devices/device_registry.hpp index 3952db66..a65bd4ad 100644 --- a/kapi/kapi/devices/device_registry.hpp +++ b/kapi/kapi/devices/device_registry.hpp @@ -18,12 +18,36 @@ namespace kapi::devices //! @addtogroup kapi-devices-kernel-defined //! @{ + //! The interface for types interested in being notified about changes in the device registry. + struct device_registry_observer + { + //! Enable correct destruction through base pointers. + virtual ~device_registry_observer() = default; + + //! Called after a device has been added to the registry. + //! + //! @param device The device that was added. + virtual auto on_device_added(kstd::shared_ptr const & device) -> void = 0; + + //! Called after a device has been removed from the registry. + //! + //! @param device The device that was remove. + virtual auto on_device_removed(device & device) -> void = 0; + }; + + //! @} + + //! @addtogroup kapi-devices-kernel-defined + //! @{ + struct device_registry { device_registry() = default; + //! Initialize the global singleton registry instance. auto static init() -> void; + //! Get the global singleton registry instance. auto static get() -> device_registry &; //! Add a new device to the kernel's device registry. @@ -49,8 +73,14 @@ namespace kapi::devices //! @return every device current reachable through the registry. [[nodiscard]] auto all() const -> kstd::vector>; + //! Subscribe to device registry notifications. + //! + //! @param observer The observer to notify. + auto subscribe(kstd::weak_ptr observer) -> void; + private: kstd::flat_map> m_devices{}; + kstd::vector> m_observers{}; }; //! @} -- cgit v1.2.3