diff options
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/devices/driver_registry.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/kapi/kapi/devices/driver_registry.hpp b/kapi/kapi/devices/driver_registry.hpp index 8af76b01..196b14c1 100644 --- a/kapi/kapi/devices/driver_registry.hpp +++ b/kapi/kapi/devices/driver_registry.hpp @@ -8,9 +8,45 @@ #include <kstd/memory.hpp> #include <kstd/vector.hpp> +#include <string_view> + namespace kapi::devices { + //! @addtogroup kapi-devices + //! @{ + + struct driver_descriptor + { + virtual ~driver_descriptor() = default; + + //! Get the name of the driver + [[nodiscard]] virtual auto name() const noexcept -> std::string_view = 0; + + //! Create a new instance of the driver represented by this descriptor. + [[nodiscard]] virtual auto make_instance() const -> kstd::shared_ptr<driver> = 0; + }; + + template<typename Type> + struct kernel_driver + { + constexpr auto static instance = Type{}; + [[using gnu: section("kernel_drivers"), used, visibility("hidden")]] constexpr auto static pointer{ + kstd::make_observer<kapi::devices::driver_descriptor const>(&instance), + }; + }; + + template<typename Type> + struct platform_driver + { + constexpr auto static instance = Type{}; + [[using gnu: section("platform_drivers"), used, visibility("hidden")]] constexpr auto static pointer{ + kstd::make_observer<kapi::devices::driver_descriptor const>(&instance), + }; + }; + + //! @} + //! @addtogroup kapi-devices-kernel-defined //! @{ |
