PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
profinet::sim::InMemoryEthernetSocket Class Referencefinal

Injectable raw-Ethernet endpoint attached to an in-memory bus. More...

#include <in_memory_ethernet.h>

+ Inheritance diagram for profinet::sim::InMemoryEthernetSocket:
+ Collaboration diagram for profinet::sim::InMemoryEthernetSocket:

Public Member Functions

 InMemoryEthernetSocket (InMemoryEthernetBus &bus, MacAddress localMac)
 Construct and attach a virtual endpoint.
 
 ~InMemoryEthernetSocket () override
 Disconnect and detach the endpoint.
 
 InMemoryEthernetSocket (const InMemoryEthernetSocket &)=delete
 
InMemoryEthernetSocket & operator= (const InMemoryEthernetSocket &)=delete
 
void Send (const std::vector< std::uint8_t > &frame) override
 Transmit one complete Ethernet frame onto the virtual bus.
 
void SetTimeout (std::chrono::milliseconds timeout) override
 Set the maximum time spent waiting for a frame.
 
std::vector< std::uint8_t > Recv () override
 Receive one frame or an empty vector after a timeout.
 
void SetReceiveEnabled (bool enabled)
 Enable or disable frame delivery into this endpoint receive queue.
 
bool ReceiveEnabled () const noexcept
 Return whether this endpoint currently accepts incoming frames.
 
const MacAddress & LocalMac () const noexcept
 Return the endpoint MAC address.
 
- Public Member Functions inherited from profinet::IRawEthernetSocket
virtual ~IRawEthernetSocket ()=default
 Virtual destructor for polymorphic use.
 

Private Member Functions

void Enqueue (const std::vector< std::uint8_t > &frame)
 Queue one frame for this endpoint.
 

Private Attributes

InMemoryEthernetBus & bus
 
MacAddress localMac {}
 
std::chrono::milliseconds timeout {1}
 
std::mutex mutex
 
std::condition_variable condition
 
std::deque< std::vector< std::uint8_t > > receiveQueue
 
bool connected = true
 
bool receiveEnabled = true
 

Friends

class InMemoryEthernetBus
 

Detailed Description

Injectable raw-Ethernet endpoint attached to an in-memory bus.

Definition at line 28 of file in_memory_ethernet.h.

Constructor & Destructor Documentation

◆ InMemoryEthernetSocket() [1/2]

profinet::sim::InMemoryEthernetSocket::InMemoryEthernetSocket ( InMemoryEthernetBus &  bus,
MacAddress  localMac 
)

Construct and attach a virtual endpoint.

Parameters
busOwning virtual Ethernet bus; it must outlive the endpoint.
localMacMAC address represented by this endpoint.

Definition at line 45 of file in_memory_ethernet.cpp.

References profinet::sim::InMemoryEthernetBus::Attach(), and bus.

+ Here is the call graph for this function:

◆ ~InMemoryEthernetSocket()

profinet::sim::InMemoryEthernetSocket::~InMemoryEthernetSocket ( )
override

Disconnect and detach the endpoint.

Definition at line 52 of file in_memory_ethernet.cpp.

References bus, and profinet::sim::InMemoryEthernetBus::Detach().

+ Here is the call graph for this function:

◆ InMemoryEthernetSocket() [2/2]

profinet::sim::InMemoryEthernetSocket::InMemoryEthernetSocket ( const InMemoryEthernetSocket &  )
delete

Member Function Documentation

◆ Enqueue()

void profinet::sim::InMemoryEthernetSocket::Enqueue ( const std::vector< std::uint8_t > &  frame)
private

Queue one frame for this endpoint.

Definition at line 130 of file in_memory_ethernet.cpp.

References condition, connected, frame, mutex, receiveEnabled, and receiveQueue.

◆ LocalMac()

const MacAddress & profinet::sim::InMemoryEthernetSocket::LocalMac ( ) const
inlinenoexcept

Return the endpoint MAC address.

Definition at line 61 of file in_memory_ethernet.h.

References localMac.

◆ operator=()

InMemoryEthernetSocket & profinet::sim::InMemoryEthernetSocket::operator= ( const InMemoryEthernetSocket &  )
delete

◆ ReceiveEnabled()

bool profinet::sim::InMemoryEthernetSocket::ReceiveEnabled ( ) const
noexcept

Return whether this endpoint currently accepts incoming frames.

Definition at line 93 of file in_memory_ethernet.cpp.

References mutex, and receiveEnabled.

◆ Recv()

std::vector< std::uint8_t > profinet::sim::InMemoryEthernetSocket::Recv ( )
overridevirtual

Receive one frame or an empty vector after a timeout.

Implements profinet::IRawEthernetSocket.

Definition at line 99 of file in_memory_ethernet.cpp.

References condition, connected, frame, mutex, receiveEnabled, receiveQueue, and timeout.

◆ Send()

void profinet::sim::InMemoryEthernetSocket::Send ( const std::vector< std::uint8_t > &  frame)
overridevirtual

Transmit one complete Ethernet frame onto the virtual bus.

Parameters
frameComplete Ethernet frame including destination and source MAC.

Implements profinet::IRawEthernetSocket.

Definition at line 57 of file in_memory_ethernet.cpp.

References bus, connected, frame, mutex, and profinet::sim::InMemoryEthernetBus::Transmit().

+ Here is the call graph for this function:

◆ SetReceiveEnabled()

void profinet::sim::InMemoryEthernetSocket::SetReceiveEnabled ( bool  enabled)

Enable or disable frame delivery into this endpoint receive queue.

Parameters
enabledTrue to accept incoming frames; false for TX-only endpoints.

Definition at line 80 of file in_memory_ethernet.cpp.

References condition, mutex, receiveEnabled, and receiveQueue.

◆ SetTimeout()

void profinet::sim::InMemoryEthernetSocket::SetTimeout ( std::chrono::milliseconds  timeout)
overridevirtual

Set the maximum time spent waiting for a frame.

Parameters
timeoutZero means wait indefinitely.

Implements profinet::IRawEthernetSocket.

Definition at line 70 of file in_memory_ethernet.cpp.

References mutex, and timeout.

Friends And Related Symbol Documentation

◆ InMemoryEthernetBus

friend class InMemoryEthernetBus
friend

Definition at line 67 of file in_memory_ethernet.h.

Member Data Documentation

◆ bus

InMemoryEthernetBus& profinet::sim::InMemoryEthernetSocket::bus
private

Definition at line 72 of file in_memory_ethernet.h.

Referenced by InMemoryEthernetSocket(), ~InMemoryEthernetSocket(), and Send().

◆ condition

std::condition_variable profinet::sim::InMemoryEthernetSocket::condition
private

◆ connected

bool profinet::sim::InMemoryEthernetSocket::connected = true
private

◆ localMac

MacAddress profinet::sim::InMemoryEthernetSocket::localMac {}
private

Definition at line 73 of file in_memory_ethernet.h.

Referenced by LocalMac().

◆ mutex

std::mutex profinet::sim::InMemoryEthernetSocket::mutex
mutableprivate

◆ receiveEnabled

bool profinet::sim::InMemoryEthernetSocket::receiveEnabled = true
private

Definition at line 79 of file in_memory_ethernet.h.

Referenced by Enqueue(), ReceiveEnabled(), Recv(), and SetReceiveEnabled().

◆ receiveQueue

std::deque<std::vector<std::uint8_t> > profinet::sim::InMemoryEthernetSocket::receiveQueue
private

◆ timeout

std::chrono::milliseconds profinet::sim::InMemoryEthernetSocket::timeout {1}
private

Definition at line 74 of file in_memory_ethernet.h.

Referenced by Recv(), and SetTimeout().


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