diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-23 01:38:56 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-23 01:38:56 +0200 |
| commit | 526709a1e86d55dd88e2dbdbc471795efce9046b (patch) | |
| tree | 04d9de462f506f983d3a991179eccfd68300cc14 /kernel/kapi/devices/bus.cpp | |
| parent | 0361a4912affe1594def1aa24e387fe5440afaee (diff) | |
| download | kernel-526709a1e86d55dd88e2dbdbc471795efce9046b.tar.xz kernel-526709a1e86d55dd88e2dbdbc471795efce9046b.zip | |
kapi: bootstrap owning device tree
Diffstat (limited to 'kernel/kapi/devices/bus.cpp')
| -rw-r--r-- | kernel/kapi/devices/bus.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/kernel/kapi/devices/bus.cpp b/kernel/kapi/devices/bus.cpp index d9f3f991..179a04a8 100644 --- a/kernel/kapi/devices/bus.cpp +++ b/kernel/kapi/devices/bus.cpp @@ -9,6 +9,7 @@ #include <kstd/vector.hpp> #include <algorithm> +#include <span> #include <utility> namespace kapi::devices @@ -41,29 +42,30 @@ namespace kapi::devices return child_status; } - auto bus::add_child(kstd::unique_ptr<device> child) -> void + auto bus::add_child(kstd::shared_ptr<device> child) -> void { - auto observer = m_observers.emplace_back(child.get()); - child->set_parent(kstd::make_observer(this)); - m_devices.push_back(std::move(child)); - if (!kapi::devices::register_device(*observer)) + child->set_parent(kstd::static_pointer_cast<bus>(shared_from_this())); + + if (!kapi::devices::register_device(child)) { kapi::system::panic("[OS:DEV] Failed to register child device"); } + auto & attached = m_devices.emplace_back(std::move(child)); + if (m_initialized.test()) { - kstd::println("[OS:DEV] Initializing child device {}@{}", observer->name(), name()); - if (!observer->init()) + kstd::println("[OS:DEV] Initializing child device {}@{}", attached->name(), name()); + if (!attached->init()) { kapi::system::panic("[OS:DEV] Failed to initialize child device"); } } } - [[nodiscard]] auto bus::children() const -> kstd::vector<kstd::observer_ptr<device>> const & + [[nodiscard]] auto bus::children() const -> std::span<kstd::shared_ptr<device> const> { - return m_observers; + return {m_devices.data(), m_devices.size()}; } auto bus::enumerate() -> bool |
