blob: 00d04311f42e09987f2822eda3b579b6721960d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
|