|
PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
|
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 |
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.
|
inline |
Register a callback invoked after every successful Send().
| callback | Callback to invoke. |
Definition at line 109 of file cyclic_raw_ethernet_socket_stub.h.
References onSend.
|
inline |
Queue a received Ethernet frame.
| data | Ethernet frame bytes to return from Recv(). |
Definition at line 73 of file cyclic_raw_ethernet_socket_stub.h.
References receiveActions.
|
inline |
Queue a receive exception.
Definition at line 79 of file cyclic_raw_ethernet_socket_stub.h.
References receiveActions.
|
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.
|
inlineoverridevirtual |
Receive the next queued frame or 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.
|
inlineoverridevirtual |
Send an Ethernet frame through the stub.
| data | Frame bytes. |
Implements profinet::IRawEthernetSocket.
Definition at line 116 of file cyclic_raw_ethernet_socket_stub.h.
References mutex, onSend, sendExceptionMessage, sendThrows, and sentFrames.
|
inline |
Return a transmitted frame.
| index | Zero-based frame index. |
Definition at line 95 of file cyclic_raw_ethernet_socket_stub.h.
References sentFrames.
|
inline |
Return the number of frames sent through the stub.
Definition at line 86 of file cyclic_raw_ethernet_socket_stub.h.
References mutex, and sentFrames.
|
inline |
Configure the exception message used by Recv().
| message | Exception text. |
Definition at line 60 of file cyclic_raw_ethernet_socket_stub.h.
References recvExceptionMessage.
|
inline |
Configure the exception message used by Send().
| message | Exception text. |
Definition at line 53 of file cyclic_raw_ethernet_socket_stub.h.
References sendExceptionMessage.
|
inline |
Configure whether Send() throws.
| enabled | Whether Send() should throw. |
Definition at line 46 of file cyclic_raw_ethernet_socket_stub.h.
References sendThrows.
|
inlineoverridevirtual |
Configure the receive timeout.
| value | Timeout used by the production receive loop. |
Implements profinet::IRawEthernetSocket.
Definition at line 154 of file cyclic_raw_ethernet_socket_stub.h.
References timeout.
|
inline |
Return the most recently configured socket timeout.
Definition at line 102 of file cyclic_raw_ethernet_socket_stub.h.
References timeout.
|
mutableprivate |
Definition at line 181 of file cyclic_raw_ethernet_socket_stub.h.
Referenced by Send(), and SentFrameCount().
|
private |
Callback invoked after a successful send.
Definition at line 176 of file cyclic_raw_ethernet_socket_stub.h.
|
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().
|
private |
Receive exception text.
Definition at line 179 of file cyclic_raw_ethernet_socket_stub.h.
Referenced by Recv(), and SetRecvExceptionMessage().
|
private |
Send exception text.
Definition at line 173 of file cyclic_raw_ethernet_socket_stub.h.
Referenced by Send(), and SetSendExceptionMessage().
|
private |
Whether Send() throws an exception.
Definition at line 167 of file cyclic_raw_ethernet_socket_stub.h.
Referenced by Send(), and SetSendThrows().
|
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().
|
private |
Timeout configured through SetTimeout().
Definition at line 170 of file cyclic_raw_ethernet_socket_stub.h.
Referenced by SetTimeout(), and Timeout().