Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches

Simulated network (LAN) device. More...

#include <network_device.h>

Inheritance diagram for contur::NetworkDevice:

Public Member Functions

 NetworkDevice (std::size_t bufferCapacity=256)
 Constructs a network device with the given buffer capacity.
 ~NetworkDevice () override
 Destroys network device.
 NetworkDevice (const NetworkDevice &)=delete
NetworkDeviceoperator= (const NetworkDevice &)=delete
 NetworkDevice (NetworkDevice &&) noexcept
 Move-constructs network device state.
NetworkDeviceoperator= (NetworkDevice &&) noexcept
 Move-assigns network device state.
DeviceId id () const noexcept override
 Returns the unique device identifier.
std::string_view name () const noexcept override
 Returns the human-readable device name.
Result< RegisterValueread () override
 Reads a value from the device.
Result< void > write (RegisterValue value) override
 Writes a value to the device.
bool isReady () const noexcept override
 Returns true if the device is ready for I/O operations.
std::size_t bufferSize () const noexcept
 Returns the number of values currently in the buffer.
bool hasData () const noexcept
 Returns true if the buffer has unread data.
Public Member Functions inherited from contur::IDevice
virtual ~IDevice ()=default

Static Public Attributes

static constexpr DeviceId NETWORK_DEVICE_ID = 2
 Default network device ID.

Private Attributes

std::unique_ptr< Impl > impl_

Additional Inherited Members

Protected Member Functions inherited from contur::IDevice
 IDevice ()=default
 IDevice (const IDevice &)=default
IDeviceoperator= (const IDevice &)=default
 IDevice (IDevice &&)=default
IDeviceoperator= (IDevice &&)=default

Detailed Description

Simulated network (LAN) device.

Writes enqueue data into an internal send buffer. Reads dequeue from a receive buffer (loopback / echo mode for simulation).

Definition at line 19 of file network_device.h.

Constructor & Destructor Documentation

◆ NetworkDevice() [1/3]

contur::NetworkDevice::NetworkDevice ( std::size_t bufferCapacity = 256)
explicit

Constructs a network device with the given buffer capacity.

Parameters
bufferCapacityMaximum number of values in the send/receive buffer.

Referenced by NetworkDevice(), NetworkDevice(), operator=(), and operator=().

◆ ~NetworkDevice()

contur::NetworkDevice::~NetworkDevice ( )
override

Destroys network device.

◆ NetworkDevice() [2/3]

contur::NetworkDevice::NetworkDevice ( const NetworkDevice & )
delete

References NetworkDevice().

◆ NetworkDevice() [3/3]

contur::NetworkDevice::NetworkDevice ( NetworkDevice && )
noexcept

Move-constructs network device state.

References NetworkDevice().

Member Function Documentation

◆ bufferSize()

std::size_t contur::NetworkDevice::bufferSize ( ) const
nodiscardnoexcept

Returns the number of values currently in the buffer.

References bufferSize().

Referenced by bufferSize().

◆ hasData()

bool contur::NetworkDevice::hasData ( ) const
nodiscardnoexcept

Returns true if the buffer has unread data.

References hasData().

Referenced by hasData().

◆ id()

DeviceId contur::NetworkDevice::id ( ) const
nodiscardoverridevirtualnoexcept

Returns the unique device identifier.

Implements contur::IDevice.

◆ isReady()

bool contur::NetworkDevice::isReady ( ) const
nodiscardoverridevirtualnoexcept

Returns true if the device is ready for I/O operations.

Implements contur::IDevice.

References isReady().

Referenced by isReady().

◆ name()

std::string_view contur::NetworkDevice::name ( ) const
nodiscardoverridevirtualnoexcept

Returns the human-readable device name.

Implements contur::IDevice.

References name().

Referenced by name().

◆ operator=() [1/2]

NetworkDevice & contur::NetworkDevice::operator= ( const NetworkDevice & )
delete

References NetworkDevice().

◆ operator=() [2/2]

NetworkDevice & contur::NetworkDevice::operator= ( NetworkDevice && )
noexcept

Move-assigns network device state.

References NetworkDevice().

◆ read()

Result< RegisterValue > contur::NetworkDevice::read ( )
nodiscardoverridevirtual

Reads a value from the device.

Returns
The read value, or an error if the device is not ready or read is unsupported.

Implements contur::IDevice.

References read().

Referenced by read().

◆ write()

Result< void > contur::NetworkDevice::write ( RegisterValue value)
nodiscardoverridevirtual

Writes a value to the device.

Parameters
valueThe value to write.
Returns
Success or an error if the device is not ready or write is unsupported.

Implements contur::IDevice.

References write().

Referenced by write().

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::NetworkDevice::impl_
private

Definition at line 64 of file network_device.h.

◆ NETWORK_DEVICE_ID

DeviceId contur::NetworkDevice::NETWORK_DEVICE_ID = 2
staticconstexpr

Default network device ID.

Definition at line 23 of file network_device.h.


The documentation for this class was generated from the following file: