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

Deterministic socket stub used by cyclic controller unit tests. More...

#include <cyclic_raw_ethernet_socket_stub.h>

+ Inheritance diagram for profinet::cyclic::test::CyclicRawEthernetSocketStub:
+ Collaboration diagram for profinet::cyclic::test::CyclicRawEthernetSocketStub:

Classes

struct  ReceiveAction
 Queued receive action. More...
 

Public Member Functions

void SetSendThrows (bool enabled)
 Configure whether Send() throws.
 
void SetSendExceptionMessage (std::string message)
 Configure the exception message used by Send().
 
void SetRecvExceptionMessage (std::string message)
 Configure the exception message used by Recv().
 
void QueueTimeout ()
 Queue a receive timeout result represented by an empty frame.
 
void QueueReceive (Bytes data)
 Queue a received Ethernet frame.
 
void QueueReceiveException ()
 Queue a receive exception.
 
std::size_t SentFrameCount () const
 Return the number of frames sent through the stub.
 
const Bytes & SentFrame (std::size_t index) const
 Return a transmitted frame.
 
std::chrono::milliseconds Timeout () const
 Return the most recently configured socket timeout.
 
void OnSend (std::function< void()> callback)
 Register a callback invoked after every successful Send().
 
void Send (const Bytes &data) override
 Send an Ethernet frame through the stub.
 
Bytes Recv () override
 Receive the next queued frame or timeout.
 
void SetTimeout (std::chrono::milliseconds value) override
 Configure the receive timeout.
 
- Public Member Functions inherited from profinet::IRawEthernetSocket
virtual ~IRawEthernetSocket ()=default
 Virtual destructor for polymorphic use.
 

Private Attributes

std::deque< ReceiveAction > receiveActions
 Queued receive actions consumed by Recv().
 
std::vector< Bytes > sentFrames
 Frames successfully sent through the stub.
 
bool sendThrows {false}
 Whether Send() throws an exception.
 
std::chrono::milliseconds timeout {0}
 Timeout configured through SetTimeout().
 
std::string sendExceptionMessage {"send failure"}
 Send exception text.
 
std::function< void()> onSend
 Callback invoked after a successful send.
 
std::string recvExceptionMessage {"receive failure"}
 Receive exception text.
 
std::mutex mutex
 

Detailed Description

Deterministic socket stub used by cyclic controller unit tests.

The stub records transmitted frames, returns queued receive results and can inject exceptions into Send() or Recv(). It implements only the raw socket operations used by CyclicController, keeping tests independent from real AF_PACKET sockets.

Definition at line 31 of file cyclic_raw_ethernet_socket_stub.h.

Member Function Documentation

◆ OnSend()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::OnSend ( std::function< void()>  callback)
inline

Register a callback invoked after every successful Send().

Parameters
callbackCallback to invoke.

Definition at line 109 of file cyclic_raw_ethernet_socket_stub.h.

References onSend.

◆ QueueReceive()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::QueueReceive ( Bytes  data)
inline

Queue a received Ethernet frame.

Parameters
dataEthernet frame bytes to return from Recv().

Definition at line 73 of file cyclic_raw_ethernet_socket_stub.h.

References receiveActions.

◆ QueueReceiveException()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::QueueReceiveException ( )
inline

Queue a receive exception.

Definition at line 79 of file cyclic_raw_ethernet_socket_stub.h.

References receiveActions.

◆ QueueTimeout()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::QueueTimeout ( )
inline

Queue a receive timeout result represented by an empty frame.

Definition at line 66 of file cyclic_raw_ethernet_socket_stub.h.

References receiveActions.

◆ Recv()

Bytes profinet::cyclic::test::CyclicRawEthernetSocketStub::Recv ( )
inlineoverridevirtual

Receive the next queued frame or timeout.

Returns
Queued frame, or an empty byte vector for a timeout.

Implements profinet::IRawEthernetSocket.

Definition at line 134 of file cyclic_raw_ethernet_socket_stub.h.

References profinet::cyclic::test::CyclicRawEthernetSocketStub::ReceiveAction::data, receiveActions, recvExceptionMessage, and profinet::cyclic::test::CyclicRawEthernetSocketStub::ReceiveAction::throwException.

◆ Send()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::Send ( const Bytes &  data)
inlineoverridevirtual

Send an Ethernet frame through the stub.

Parameters
dataFrame bytes.

Implements profinet::IRawEthernetSocket.

Definition at line 116 of file cyclic_raw_ethernet_socket_stub.h.

References mutex, onSend, sendExceptionMessage, sendThrows, and sentFrames.

◆ SentFrame()

const Bytes & profinet::cyclic::test::CyclicRawEthernetSocketStub::SentFrame ( std::size_t  index) const
inline

Return a transmitted frame.

Parameters
indexZero-based frame index.
Returns
Transmitted Ethernet frame.

Definition at line 95 of file cyclic_raw_ethernet_socket_stub.h.

References sentFrames.

◆ SentFrameCount()

std::size_t profinet::cyclic::test::CyclicRawEthernetSocketStub::SentFrameCount ( ) const
inline

Return the number of frames sent through the stub.

Returns
Number of Send() calls completed successfully.

Definition at line 86 of file cyclic_raw_ethernet_socket_stub.h.

References mutex, and sentFrames.

◆ SetRecvExceptionMessage()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::SetRecvExceptionMessage ( std::string  message)
inline

Configure the exception message used by Recv().

Parameters
messageException text.

Definition at line 60 of file cyclic_raw_ethernet_socket_stub.h.

References recvExceptionMessage.

◆ SetSendExceptionMessage()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::SetSendExceptionMessage ( std::string  message)
inline

Configure the exception message used by Send().

Parameters
messageException text.

Definition at line 53 of file cyclic_raw_ethernet_socket_stub.h.

References sendExceptionMessage.

◆ SetSendThrows()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::SetSendThrows ( bool  enabled)
inline

Configure whether Send() throws.

Parameters
enabledWhether Send() should throw.

Definition at line 46 of file cyclic_raw_ethernet_socket_stub.h.

References sendThrows.

◆ SetTimeout()

void profinet::cyclic::test::CyclicRawEthernetSocketStub::SetTimeout ( std::chrono::milliseconds  value)
inlineoverridevirtual

Configure the receive timeout.

Parameters
valueTimeout used by the production receive loop.

Implements profinet::IRawEthernetSocket.

Definition at line 154 of file cyclic_raw_ethernet_socket_stub.h.

References timeout.

◆ Timeout()

std::chrono::milliseconds profinet::cyclic::test::CyclicRawEthernetSocketStub::Timeout ( ) const
inline

Return the most recently configured socket timeout.

Returns
Configured timeout.

Definition at line 102 of file cyclic_raw_ethernet_socket_stub.h.

References timeout.

Member Data Documentation

◆ mutex

std::mutex profinet::cyclic::test::CyclicRawEthernetSocketStub::mutex
mutableprivate

Definition at line 181 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by Send(), and SentFrameCount().

◆ onSend

std::function<void()> profinet::cyclic::test::CyclicRawEthernetSocketStub::onSend
private

Callback invoked after a successful send.

Definition at line 176 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by OnSend(), and Send().

◆ receiveActions

std::deque<ReceiveAction> profinet::cyclic::test::CyclicRawEthernetSocketStub::receiveActions
private

Queued receive actions consumed by Recv().

Definition at line 161 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by QueueReceive(), QueueReceiveException(), QueueTimeout(), and Recv().

◆ recvExceptionMessage

std::string profinet::cyclic::test::CyclicRawEthernetSocketStub::recvExceptionMessage {"receive failure"}
private

Receive exception text.

Definition at line 179 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by Recv(), and SetRecvExceptionMessage().

◆ sendExceptionMessage

std::string profinet::cyclic::test::CyclicRawEthernetSocketStub::sendExceptionMessage {"send failure"}
private

Send exception text.

Definition at line 173 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by Send(), and SetSendExceptionMessage().

◆ sendThrows

bool profinet::cyclic::test::CyclicRawEthernetSocketStub::sendThrows {false}
private

Whether Send() throws an exception.

Definition at line 167 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by Send(), and SetSendThrows().

◆ sentFrames

std::vector<Bytes> profinet::cyclic::test::CyclicRawEthernetSocketStub::sentFrames
private

Frames successfully sent through the stub.

Definition at line 164 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by Send(), SentFrame(), and SentFrameCount().

◆ timeout

std::chrono::milliseconds profinet::cyclic::test::CyclicRawEthernetSocketStub::timeout {0}
private

Timeout configured through SetTimeout().

Definition at line 170 of file cyclic_raw_ethernet_socket_stub.h.

Referenced by SetTimeout(), and Timeout().


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