aboutsummaryrefslogtreecommitdiff
path: root/kapi/kapi/filesystem/character_device.hpp
blob: b839410d01afbbbd8a0001cfd82ebfd3ece32118 (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
#ifndef TEACHOS_KAPI_FILESYSTEM_CHARACTER_DEVICE_HPP
#define TEACHOS_KAPI_FILESYSTEM_CHARACTER_DEVICE_HPP

// IWYU pragma: private, include <kapi/filesystem.hpp>

#include <kapi/devices/interface_id.hpp>

#include <kstd/result.hpp>
#include <kstd/units.hpp>

#include <cstddef>
#include <span>

namespace kapi::filesystem
{

  struct character_device
  {
    constexpr auto static id = kapi::devices::interface_id{"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::filesystem

#endif