diff options
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/kapi/devices.hpp | 1 | ||||
| -rw-r--r-- | kapi/kapi/devices/block_device.hpp | 4 | ||||
| -rw-r--r-- | kapi/kapi/devices/character_device.hpp | 39 |
3 files changed, 42 insertions, 2 deletions
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 <kapi/devices/block_device.hpp> // IWYU pragma: export #include <kapi/devices/bus.hpp> // IWYU pragma: export +#include <kapi/devices/character_device.hpp> // IWYU pragma: export #include <kapi/devices/cpu.hpp> // IWYU pragma: export #include <kapi/devices/device.hpp> // IWYU pragma: export #include <kapi/devices/interface.hpp> // 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 <kapi/devices.hpp> 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 <kapi/devices.hpp> + +#include <kapi/devices/interface.hpp> + +#include <kstd/result.hpp> +#include <kstd/units.hpp> + +#include <cstddef> +#include <span> + +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<std::byte> buffer) const -> kstd::result<kstd::units::bytes> = 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<std::byte const> buffer) -> kstd::result<kstd::units::bytes> = 0; + }; + +} // namespace kapi::devices + +#endif
\ No newline at end of file |
