diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-31 08:56:17 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-31 08:56:17 +0200 |
| commit | 9e85f9d1f34d08213a918d9c1b0845c179e323af (patch) | |
| tree | d3694b22e1b41cbc3bfd340f8f9db47a6602ec73 /kapi/include | |
| parent | ffac763323b88809d2f361bc01cdf9bfe0b1d67f (diff) | |
| download | teachos-9e85f9d1f34d08213a918d9c1b0845c179e323af.tar.xz teachos-9e85f9d1f34d08213a918d9c1b0845c179e323af.zip | |
move device into kapi
Diffstat (limited to 'kapi/include')
| -rw-r--r-- | kapi/include/kapi/devices/device.hpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/kapi/include/kapi/devices/device.hpp b/kapi/include/kapi/devices/device.hpp new file mode 100644 index 0000000..a049cf5 --- /dev/null +++ b/kapi/include/kapi/devices/device.hpp @@ -0,0 +1,81 @@ +#ifndef TEACH_OS_KAPI_DEVICES_DEVICE_HPP +#define TEACH_OS_KAPI_DEVICES_DEVICE_HPP + +#include <kstd/string> + +#include <cstddef> + +namespace kapi::devices +{ + /** + * @brief Base device identified by a major, minor number and name. + */ + struct device + { + /** + * @brief Create a device identifier from @p major, @p minor and @p name. + * @param major Device major number. + * @param minor Device minor number. + * @param name Device name. + */ + device(size_t major, size_t minor, kstd::string const & name) + : m_major(major) + , m_minor(minor) + , m_name(name) + {} + + /** + * @brief Virtual destructor for device. + */ + virtual ~device() = default; + + /** + * @brief Initialize the device. + * @return true on success, false otherwise. + */ + virtual auto init() -> bool = 0; + + /** + * @brief Returns the major number of the device. + * @return Device major number. + */ + [[nodiscard]] auto major() const -> size_t + { + return m_major; + } + + /** + * @brief Returns the minor number of the device. + * @return Device minor number. + */ + [[nodiscard]] auto minor() const -> size_t + { + return m_minor; + } + + /** + * @brief Returns the name of the device. + * @return Device name. + */ + [[nodiscard]] auto name() const -> kstd::string const & + { + return m_name; + } + + /** + * @brief Check if the device is a block device. + * @return true if this device is a block device, false otherwise. + */ + [[nodiscard]] virtual auto is_block_device() const -> bool + { + return false; + } + + private: + size_t m_major; + size_t m_minor; + kstd::string m_name; + }; +} // namespace kapi::devices + +#endif
\ No newline at end of file |
