|
Open Model Railroad Network (OpenMRN)
|
A state flow that has an incoming message queue, pends on that queue, and runs a flow for every message that comes in from that queue. More...
#include <StateFlow.hxx>
Public Member Functions | |
| void | notify () override |
| Wakeup call arrived. Schedules *this on the executor. | |
| bool | is_waiting () |
Public Member Functions inherited from StateFlowBase | |
| void | run () override |
| Callback from the executor. | |
| Service * | service () |
| Return a pointer to the service I am bound to. | |
Public Member Functions inherited from Executable | |
| void | test_deletion () |
Public Member Functions inherited from QMember | |
| void | init () |
| Initiailize a QMember, in place of a public placement construction. | |
Public Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_next () |
Protected Member Functions | |
| StateFlowWithQueue (Service *service) | |
| Constructor. | |
| virtual Action | entry ()=0 |
| Entry into the StateFlow activity. | |
| virtual QMember * | queue_next (unsigned *priority)=0 |
| Takes the front entry in the queue. | |
| virtual bool | queue_empty ()=0 |
| virtual void | release ()=0 |
| Releases the current message buffer back to the pool it came from. | |
| Action | exit () |
| Terminates the processing of this flow. | |
| Action | release_and_exit () |
| Terminates the processing of the current message. | |
| BufferBase * | message () |
| BufferBase * | transfer_message () |
| Releases ownership of the current message. | |
| void | reset_message (BufferBase *message, unsigned priority) |
| Sets the current message being processed. | |
| unsigned | priority () |
| void | set_priority (unsigned priority) |
| Overrides the current priority. | |
| void | start_flow_at_init (Callback c) |
| Call this from the constructor of the child class to do some work before the main queue processing loop begins. | |
Protected Member Functions inherited from StateFlowBase | |
| StateFlowBase (Service *service) | |
| Constructor. | |
| ~StateFlowBase () | |
| Destructor. | |
| void | reset_flow (Callback c) |
| Resets the flow to the specified state. | |
| bool | is_state (Callback c) |
| bool | is_terminated () |
| void | start_flow (Callback c) |
| Resets the flow to the specified state and starts it. | |
| Action | again () |
| Call the current state again via call_immediately. | |
| Action | exit () |
| Terminate current StateFlow activity. | |
| Action | delete_this () |
| Terminates the flow and deletes *this. | |
| Action | set_terminated () |
| Sets the flow to terminated state. | |
| Action | call_immediately (Callback c) |
| Imediately call the next state upon return. | |
| Action | wait () |
| Wait for an asynchronous call. | |
| Action | wait_and_call (Callback c) |
| Wait for resource to become available before proceeding to next state. | |
| template<class T > | |
| Action | allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr) |
| Allocates a buffer from a pool and proceed to the next state when allocation is successful. | |
| Action | allocate_and_call (Callback c, QAsync *queue) |
| Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete. | |
| template<class T > | |
| Buffer< T > * | full_allocation_result (FlowInterface< Buffer< T > > *target_flow) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| T * | full_allocation_result (TypedQAsync< T > *queue) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| void | cast_allocation_result (T **member) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| Buffer< T > * | get_allocation_result (FlowInterface< Buffer< T > > *target_flow) |
| Takes the result of the asynchronous allocation. | |
| Action | yield_and_call (Callback c) |
| Place the current flow to the back of the executor, and transition to a new state after we get the CPU again. | |
| Action | yield () |
| Place the current flow to the back of the executor, and re-try the current state after we get the CPU again. | |
| Action | sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c) |
| Suspends execution of this control flow for a specified time. | |
| template<class T , typename... Args> | |
| Action | invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args) |
| Calls a helper flow to perform some actions. | |
| Action | read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Blocks until size bytes are read and then invokes the next state. | |
| Action | read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read. | |
| Action | read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now. | |
| Action | read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Blocks until size bytes are read, or a timeout expires. | |
| Action | internal_try_read () |
| Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading. | |
| Action | write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written. | |
| Action | internal_try_write () |
| Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing. | |
Protected Member Functions inherited from QMember | |
| QMember () | |
| Constructor. | |
| ~QMember () | |
| Destructor. | |
Protected Member Functions inherited from Atomic | |
| void | lock () |
| void | unlock () |
Protected Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_this () |
| LinkedObject () | |
| Constructor. Puts *this on the linked list. | |
| ~LinkedObject () | |
| Constructor. Removes *this from the linked list. | |
| StateFlowWithQueue * | link_next () |
Private Member Functions | |
| Action | wait_for_message () |
Private Attributes | |
| unsigned | queueSize_ |
| For debugging: how many entries are currently waiting in the queue of this stateflow. | |
| BufferBase * | currentMessage_ |
| Message we are currently processing. | |
| unsigned | currentPriority_: 31 |
| Priority of the current message we are processing. | |
| unsigned | isWaiting_: 1 |
| True if we are in the pending state, waiting for an entry to show up in the queue. | |
Static Private Attributes | |
| static const unsigned | MAX_PRIORITY_ = 0x7FFFFFFFU |
| Largest acceptable priority value for a stateflow. | |
Friends | |
| template<class Q > | |
| class | UntypedStateFlow |
| template<class M , class B > | |
| class | TypedStateFlow |
| class | GlobalEventFlow |
Additional Inherited Members | |
Static Public Member Functions inherited from StateFlowBase | |
| template<class T , typename... Args> | |
| static void | invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args) |
| Calls a helper flow to perform some actions. | |
Static Public Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | link_head () |
| static Atomic * | head_mu () |
| Locks the list for modification (at any entry!). | |
Protected Types inherited from StateFlowBase | |
| typedef Action(StateFlowBase::* | Callback) () |
| State Flow callback prototype. | |
Static Protected Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | link_head () |
| static Atomic * | head_mu () |
| Locks the list for modification (at any entry!). | |
Protected Attributes inherited from QMember | |
| QMember * | next |
| pointer to the next member in the queue | |
Protected Attributes inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_ |
| Linked list pointer. | |
Static Protected Attributes inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | head_ |
| Beginning of the list. | |
A state flow that has an incoming message queue, pends on that queue, and runs a flow for every message that comes in from that queue.
Definition at line 968 of file StateFlow.hxx.
| StateFlowWithQueue::~StateFlowWithQueue | ( | ) |
Definition at line 51 of file StateFlow.cxx.
|
protected |
Constructor.
| service | specifies which thread to execute this state flow on. |
Definition at line 41 of file StateFlow.cxx.
|
protectedpure virtual |
Entry into the StateFlow activity.
Pure virtual which must be defined by derived class. Must eventually (through some number of states) call release_and_exit() to transition to getting next message.
Implemented in MockSend, ProgrammingTrackBackend, openlcb::RailcomToOpenLCBDebugProxy, DispatchFlowBase< NUM_PRIO >, DispatchFlowBase< BASE_NUM_PRIO >, DispatchFlow< MessageType, NUM_PRIO >, openlcb::BootloaderClient::WriteResponseHandler, openlcb::BootloaderPort, openlcb::BroadcastTimeServerDateRolloverFinish, openlcb::BroadcastTimeServerTime, openlcb::BroadcastTimeServerSync, openlcb::BroadcastTimeServerSet, openlcb::BulkAliasAllocator, openlcb::DccAccyProducer, openlcb::MemoryConfigHandler, openlcb::MemoryConfigClient, openlcb::MemoryConfigClient::ResponseFlow, openlcb::MemoryConfigClientWithStream, openlcb::MemoryConfigStreamHandler, openlcb::InitializeFlow, openlcb::SimpleInfoFlow, openlcb::SNIPClient, openlcb::StreamReceiverCan, openlcb::TractionThrottle, traction_modem::TxFlow, BufferPort, HubToGcPort, ESPWifiClient, GCAdapter::BinaryToGCMember, GCAdapter::GCToBinaryMember, DisplayPort, FdHubWriteFlow< typename HFlow::value_type >, HubDeviceSelect< HFlow, ReadFlow >::WriteFlow, FdLoggingServer, TypedStateFlow< Buffer< AliasInfo >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BootloaderRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerDateRolloverFinishInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerSetInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerSyncInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerTimeInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BulkAliasRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< CanHubData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< CanHubData >, UntypedStateFlow< QList< 5 > > >, TypedStateFlow< Buffer< CanMessageData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< CanMessageData >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< Chunk >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< D >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< Data >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< dcc::Packet >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< DccAccyProducerInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< EventHandlerCall >, UntypedStateFlow< QList< 5 > > >, TypedStateFlow< Buffer< GenMessage >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< GenMessage >, UntypedStateFlow< QList< 4 > > >, TypedStateFlow< Buffer< HubData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< MemoryConfigClientRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< NodeCanonicalizeRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< ProgrammingTrackRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< RequestType >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< SNIPClientRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< StreamReceiveRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< ThrottleCommand >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< ThrottleCommand >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< TractionThrottleInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< typename HFlow::value_type >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< ByteBuffer, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >, and TypedStateFlow< MessageType, UntypedStateFlow< QueueType > >.
|
inlineprotected |
Terminates the processing of this flow.
Takes the next message and start processing agian from entry().
Definition at line 1020 of file StateFlow.hxx.
|
inline |
Definition at line 982 of file StateFlow.hxx.
|
inlineprotected |
Definition at line 1036 of file StateFlow.hxx.
|
overridevirtual |
Wakeup call arrived. Schedules *this on the executor.
Reimplemented from StateFlowBase.
Definition at line 109 of file StateFlow.cxx.
|
inlineprotected |
Definition at line 1062 of file StateFlow.hxx.
|
protectedpure virtual |
Implemented in UntypedStateFlow< QueueType >, UntypedStateFlow< QList< 1 > >, UntypedStateFlow< QList< 4 > >, UntypedStateFlow< QList< 5 > >, and UntypedStateFlow< QList< NUM_PRIO > >.
|
protectedpure virtual |
Takes the front entry in the queue.
Must be called with the lock held.
| priority | will be set to the priority of the queue member removed fomr the queue. |
Implemented in UntypedStateFlow< QueueType >, UntypedStateFlow< QList< 1 > >, UntypedStateFlow< QList< 4 > >, UntypedStateFlow< QList< 5 > >, and UntypedStateFlow< QList< NUM_PRIO > >.
|
protectedpure virtual |
Releases the current message buffer back to the pool it came from.
The state flow will continue running (and not get another message) until it reaches the state exit().
Implemented in TypedStateFlow< Buffer< AliasInfo >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BootloaderRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerDateRolloverFinishInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerSetInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerSyncInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BroadcastTimeServerTimeInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< BulkAliasRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< CanHubData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< CanHubData >, UntypedStateFlow< QList< 5 > > >, TypedStateFlow< Buffer< CanMessageData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< CanMessageData >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< Chunk >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< D >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< Data >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< dcc::Packet >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< DccAccyProducerInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< EventHandlerCall >, UntypedStateFlow< QList< 5 > > >, TypedStateFlow< Buffer< GenMessage >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< GenMessage >, UntypedStateFlow< QList< 4 > > >, TypedStateFlow< Buffer< HubData >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< MemoryConfigClientRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< NodeCanonicalizeRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< ProgrammingTrackRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< RequestType >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< SNIPClientRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< StreamReceiveRequest >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< ThrottleCommand >, DispatchFlowBase< BASE_NUM_PRIO > >, TypedStateFlow< Buffer< ThrottleCommand >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< TractionThrottleInput >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< Buffer< typename HFlow::value_type >, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< ByteBuffer, UntypedStateFlow< QList< 1 > > >, TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >, and TypedStateFlow< MessageType, UntypedStateFlow< QueueType > >.
|
inlineprotected |
Terminates the processing of the current message.
Flows should end with this action. Frees the current message.
Definition at line 1029 of file StateFlow.hxx.
|
inlineprotected |
Sets the current message being processed.
| message | is the buffer of the new message. This request transfers one reference of ownership. |
| priority | what prio to run the flow on. |
Definition at line 1055 of file StateFlow.hxx.
|
inlineprotected |
Overrides the current priority.
Definition at line 1068 of file StateFlow.hxx.
|
inlineprotected |
Call this from the constructor of the child class to do some work before the main queue processing loop begins.
When the initialization states are done, call 'return exit()' to start the main loop.
| c | is the state to call before the main loop. |
Definition at line 1077 of file StateFlow.hxx.
|
inlineprotected |
Releases ownership of the current message.
Definition at line 1044 of file StateFlow.hxx.
|
private |
Definition at line 74 of file StateFlow.cxx.
|
friend |
Definition at line 1103 of file StateFlow.hxx.
|
friend |
Definition at line 1102 of file StateFlow.hxx.
|
friend |
Definition at line 1101 of file StateFlow.hxx.
|
private |
Message we are currently processing.
Definition at line 1092 of file StateFlow.hxx.
|
private |
Priority of the current message we are processing.
Definition at line 1095 of file StateFlow.hxx.
|
private |
True if we are in the pending state, waiting for an entry to show up in the queue.
Protected by Atomic *this.
Definition at line 1099 of file StateFlow.hxx.
|
staticprivate |
Largest acceptable priority value for a stateflow.
Definition at line 1106 of file StateFlow.hxx.
|
private |
For debugging: how many entries are currently waiting in the queue of this stateflow.
Definition at line 1089 of file StateFlow.hxx.