aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/devices/device_registry.hpp30
1 files changed, 30 insertions, 0 deletions
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<device> 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<kstd::shared_ptr<device>>;
+ //! Subscribe to device registry notifications.
+ //!
+ //! @param observer The observer to notify.
+ auto subscribe(kstd::weak_ptr<device_registry_observer> observer) -> void;
+
private:
kstd::flat_map<kstd::string, kstd::weak_ptr<device>> m_devices{};
+ kstd::vector<kstd::weak_ptr<device_registry_observer>> m_observers{};
};
//! @}