contur2
Loading...
Searching...
No Matches
network_device.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <memory>
10
11#include "contur/io/i_device.h"
12
13namespace contur {
14
19 class NetworkDevice final : public IDevice
20 {
21 public:
23 static constexpr DeviceId NETWORK_DEVICE_ID = 2;
24
27 explicit NetworkDevice(std::size_t bufferCapacity = 256);
28 ~NetworkDevice() override;
29
30 // Non-copyable, movable
31 NetworkDevice(const NetworkDevice &) = delete;
34 NetworkDevice &operator=(NetworkDevice &&) noexcept;
35
36 [[nodiscard]] DeviceId id() const noexcept override;
37 [[nodiscard]] std::string_view name() const noexcept override;
38 [[nodiscard]] Result<RegisterValue> read() override;
39 [[nodiscard]] Result<void> write(RegisterValue value) override;
40 [[nodiscard]] bool isReady() const noexcept override;
41
43 [[nodiscard]] std::size_t bufferSize() const noexcept;
44
46 [[nodiscard]] bool hasData() const noexcept;
47
48 private:
49 struct Impl;
50 std::unique_ptr<Impl> impl_;
51 };
52
53} // namespace contur
IDevice()=default
~NetworkDevice() override
bool hasData() const noexcept
Returns true if the buffer has unread data.
std::string_view name() const noexcept override
Returns the human-readable device name.
std::size_t bufferSize() const noexcept
Returns the number of values currently in the buffer.
Result< RegisterValue > read() override
Reads a value from the device.
NetworkDevice(std::size_t bufferCapacity=256)
Constructs a network device with the given buffer capacity.
bool isReady() const noexcept override
Returns true if the device is ready for I/O operations.
NetworkDevice(NetworkDevice &&) noexcept
Result< void > write(RegisterValue value) override
Writes a value to the device.
NetworkDevice & operator=(const NetworkDevice &)=delete
static constexpr DeviceId NETWORK_DEVICE_ID
Default network device ID.
std::unique_ptr< Impl > impl_
NetworkDevice(const NetworkDevice &)=delete
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
IDevice — abstract interface for I/O devices.
Definition block.h:15
std::int32_t RegisterValue
Value stored in a CPU register.
Definition types.h:21
std::uint16_t DeviceId
Unique identifier for an I/O device.
Definition types.h:24