From 14685093004d767669fcfecaad875f7ab2aae76d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 16 Jul 2026 21:55:48 +0200 Subject: kapi: add character device capability --- kapi/kapi/devices.hpp | 1 + kapi/kapi/devices/block_device.hpp | 4 ++-- kapi/kapi/devices/character_device.hpp | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 kapi/kapi/devices/character_device.hpp diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp index 989ca0fa..e86e9ee7 100644 --- a/kapi/kapi/devices.hpp +++ b/kapi/kapi/devices.hpp @@ -3,6 +3,7 @@ #include // IWYU pragma: export #include // IWYU pragma: export +#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export diff --git a/kapi/kapi/devices/block_device.hpp b/kapi/kapi/devices/block_device.hpp index 4b3eab61..dfd08899 100644 --- a/kapi/kapi/devices/block_device.hpp +++ b/kapi/kapi/devices/block_device.hpp @@ -1,5 +1,5 @@ -#ifndef TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP -#define TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP +#ifndef TEACHOS_KAPI_DEVICES_BLOCK_DEVICE_HPP +#define TEACHOS_KAPI_DEVICES_BLOCK_DEVICE_HPP // IWYU pragma: private, include diff --git a/kapi/kapi/devices/character_device.hpp b/kapi/kapi/devices/character_device.hpp new file mode 100644 index 00000000..7e7e8d6d --- /dev/null +++ b/kapi/kapi/devices/character_device.hpp @@ -0,0 +1,39 @@ +#ifndef TEACHOS_KAPI_DEVICES_CHARACTER_DEVICE_HPP +#define TEACHOS_KAPI_DEVICES_CHARACTER_DEVICE_HPP + +// IWYU pragma: private, include + +#include + +#include +#include + +#include +#include + +namespace kapi::devices +{ + + struct character_device + { + constexpr auto static id = interface{"char"}; + + //! Virtual destructor to enable clean deletes through base pointers. + virtual ~character_device() = default; + + //! Read data from the stream into a given buffer. + //! + //! @param buffer The buffer to read into. + //! @return The number of bytes read on success, an error otherwise. + [[nodiscard]] auto virtual read(std::span buffer) const -> kstd::result = 0; + + //! Write data from a buffer into the stream. + //! + //! @param buffer The buffer to write from. + //! @return The number of bytes written on success, an error otherwise. + auto virtual write_block(std::span buffer) -> kstd::result = 0; + }; + +} // namespace kapi::devices + +#endif \ No newline at end of file -- cgit v1.2.3