Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DispatchFlow< MessageType, NUM_PRIO > Class Template Reference

Type-specific implementations of the DispatchFlow methods. More...

#include <Dispatcher.hxx>

Inheritance diagram for DispatchFlow< MessageType, NUM_PRIO >:
TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > > DispatchFlowBase< BASE_NUM_PRIO > FlowInterface< MessageType > UntypedStateFlow< QList< NUM_PRIO > > StateFlowWithQueue StateFlowBase Atomic LinkedObject< StateFlowWithQueue > Executable Notifiable QMember Destructable GenericHubFlow< HubData > GenericHubFlow< CanHubData >

Public Types

typedef TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > > Base
 Helper typedef of the base class of *this.
 
typedef StateFlowBase::Action Action
 Imports types and functions to allow less typing for the implementation.
 
typedef FlowInterface< MessageType > HandlerType
 Interface type for handlers that can be registered.
 
typedef MessageType::value_type::id_type ID
 Maskable type of the dispatched messages upon which handlers can configure to trigger.
 
- Public Types inherited from TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >
typedef Base::Action Action
 Allows using Action without having StateFlowBase:: prefix in front of it.
 
- Public Types inherited from DispatchFlowBase< BASE_NUM_PRIO >
typedef StateFlowBase::Action Action
 Allows using Action without having StateFlowBase:: prefix in front of it.
 
- Public Types inherited from FlowInterface< MessageType >
typedef MessageType message_type
 Stores the message template type for external reference.
 

Public Member Functions

 DispatchFlow (Service *service)
 Constructor.
 
Action entry () OVERRIDE
 Override method that will be called after each incoming message is dequeued.
 
void register_handler (HandlerType *handler, ID id, ID mask)
 Adds a new handler to this dispatcher.
 
void unregister_handler (HandlerType *handler, ID id, ID mask)
 Removes a specific instance of a handler from this dispatcher.
 
void unregister_handler_all (HandlerType *handler)
 Removes all instances of a handler from this dispatcher.
 
void register_fallback_handler (HandlerType *handler)
 Sets one handler to receive all messages that no other handler has matched.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
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 > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
- Public Member Functions inherited from TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >
 TypedStateFlow (Service *service)
 Constructor.
 
virtual ~TypedStateFlow ()
 Destructor.
 
void send (MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
 Sends a message to the state flow for processing.
 
- Public Member Functions inherited from DispatchFlowBase< BASE_NUM_PRIO >
 DispatchFlowBase (Service *service)
 Construct a dispatchflow.
 
size_t size ()
 
- Public Member Functions inherited from UntypedStateFlow< QList< NUM_PRIO > >
 UntypedStateFlow (Service *service)
 Constructor.
 
- Public Member Functions inherited from StateFlowWithQueue
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.
 
Serviceservice ()
 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 >
StateFlowWithQueuelink_next ()
 
- Public Member Functions inherited from FlowInterface< MessageType >
virtual Poolpool ()
 
virtual MessageType * type_helper ()
 This function is never user in the code, but GDB can use it to infer the correct message types.
 
MessageType * alloc ()
 Synchronously allocates a message buffer from the pool of this flow.
 
void alloc_async (Executable *target)
 Asynchronously allocates a message buffer from the pool of this flow.
 

Protected Member Functions

Base::ID get_message_id () OVERRIDE
 
Action allocate_and_clone () OVERRIDE
 Requests allocating a new buffer for sending off a clone.
 
Action clone ()
 Takes the allocated new buffer, copies the message into it and sends off to the clone target.
 
void send_transfer () OVERRIDE
 Takes the existing buffer and sends off to the target flow.
 
- Protected Member Functions inherited from TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >
void release () OVERRIDE
 Unrefs the current buffer.
 
void return_buffer ()
 For state flows that are operated using invoke_subflow_and_wait this is a way to hand back the buffer to the caller.
 
MessageType * message ()
 
MessageType * transfer_message ()
 Releases ownership of the current message.
 
- Protected Member Functions inherited from DispatchFlowBase< BASE_NUM_PRIO >
void register_handler (UntypedHandler *handler, ID id, ID mask)
 Adds a new handler to this dispatcher.
 
void unregister_handler (UntypedHandler *handler, ID id, ID mask)
 Removes a specific instance of a handler from this dispatcher.
 
void unregister_handler_all (UntypedHandler *handler)
 Removes all instances of a handler from this dispatcher.
 
void register_fallback_handler (UntypedHandler *handler)
 Sets one handler to receive all messages that no other handler has matched.
 
Action iterate ()
 Iterate on potential handlers, matching the ID of the incoming message to the handlers' masks.
 
Action clone_done ()
 State after a clone-and-send operation is complete.
 
Action iteration_done ()
 State when the entire iteration is done.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action again ()
 Call the current state again via call_immediately.
 
Action release_and_exit ()
 Terminates the processing of the current message.
 
- Protected Member Functions inherited from UntypedStateFlow< QList< NUM_PRIO > >
void send (BufferBase *msg, unsigned priority=UINT_MAX)
 Sends a message to the state flow for processing.
 
QMemberqueue_next (unsigned *priority) OVERRIDE
 Takes the front entry in the queue.
 
bool queue_empty () OVERRIDE
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
- Protected Member Functions inherited from StateFlowWithQueue
 StateFlowWithQueue (Service *service)
 Constructor.
 
Action exit ()
 Terminates the processing of this flow.
 
Action release_and_exit ()
 Terminates the processing of the current message.
 
BufferBasemessage ()
 
BufferBasetransfer_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 >
StateFlowWithQueuelink_this ()
 
 LinkedObject ()
 Constructor. Puts *this on the linked list.
 
 ~LinkedObject ()
 Constructor. Removes *this from the linked list.
 
StateFlowWithQueuelink_next ()
 

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 StateFlowWithQueuelink_head ()
 
static Atomichead_mu ()
 Locks the list for modification (at any entry!).
 
- Static Public Member Functions inherited from FlowInterface< MessageType >
static MessageType * cast_alloc (QMember *entry)
 Down casts and initializes an asynchronous allocation result to the appropriate flow's buffer type.
 
- Protected Types inherited from DispatchFlowBase< BASE_NUM_PRIO >
typedef uint32_t ID
 Proxy the identifier type for customers to use.
 
typedef void UntypedHandler
 Generic handler type.
 
- Protected Types inherited from UntypedStateFlow< QList< NUM_PRIO > >
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Static Protected Member Functions inherited from LinkedObject< StateFlowWithQueue >
static StateFlowWithQueuelink_head ()
 
static Atomichead_mu ()
 Locks the list for modification (at any entry!).
 
- Protected Attributes inherited from DispatchFlowBase< BASE_NUM_PRIO >
UntypedHandlerlastHandlerToCall_
 If non-NULL we still need to call this handler.
 
UntypedHandlerfallbackHandler_
 Handler to give all messages that were not matched by any other handler registration.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Protected Attributes inherited from LinkedObject< StateFlowWithQueue >
StateFlowWithQueuelink_
 Linked list pointer.
 
- Static Protected Attributes inherited from LinkedObject< StateFlowWithQueue >
static StateFlowWithQueuehead_
 Beginning of the list.
 

Detailed Description

template<class MessageType, int NUM_PRIO>
class DispatchFlow< MessageType, NUM_PRIO >

Type-specific implementations of the DispatchFlow methods.

see DispatchFlowBase.

Definition at line 215 of file Dispatcher.hxx.

Member Typedef Documentation

◆ Action

template<class MessageType , int NUM_PRIO>
typedef StateFlowBase::Action DispatchFlow< MessageType, NUM_PRIO >::Action

Imports types and functions to allow less typing for the implementation.

Definition at line 226 of file Dispatcher.hxx.

◆ Base

template<class MessageType , int NUM_PRIO>
typedef TypedStateFlow<MessageType, DispatchFlowBase<BASE_NUM_PRIO> > DispatchFlow< MessageType, NUM_PRIO >::Base

Helper typedef of the base class of *this.

Definition at line 218 of file Dispatcher.hxx.

◆ HandlerType

template<class MessageType , int NUM_PRIO>
typedef FlowInterface<MessageType> DispatchFlow< MessageType, NUM_PRIO >::HandlerType

Interface type for handlers that can be registered.

Definition at line 232 of file Dispatcher.hxx.

◆ ID

template<class MessageType , int NUM_PRIO>
typedef MessageType::value_type::id_type DispatchFlow< MessageType, NUM_PRIO >::ID

Maskable type of the dispatched messages upon which handlers can configure to trigger.

Definition at line 235 of file Dispatcher.hxx.

Constructor & Destructor Documentation

◆ DispatchFlow()

template<class MessageType , int NUM_PRIO>
DispatchFlow< MessageType, NUM_PRIO >::DispatchFlow ( Service service)
inline

Constructor.

Parameters
servicespecifies which thread to execute this state flow on.

Definition at line 222 of file Dispatcher.hxx.

Member Function Documentation

◆ allocate_and_call() [1/2]

template<class MessageType , int NUM_PRIO>
Action StateFlowBase::allocate_and_call ( Callback  c,
QAsync queue 
)
inline

Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.

Parameters
cis the state to transition to after allocation
queueis the queue to allocate from.
Returns
new state object to return from state function.

Definition at line 372 of file StateFlow.hxx.

◆ allocate_and_call() [2/2]

template<class MessageType , int NUM_PRIO>
template<class T >
Action StateFlowBase::allocate_and_call ( FlowInterface< Buffer< T > > *  target_flow,
Callback  c,
Pool pool = nullptr 
)
inline

Allocates a buffer from a pool and proceed to the next state when allocation is successful.

Parameters
target_flowdefines the type of buffer to allocate.
cCallback "state" to move to after allocation
poolpool to allocate from; defaults to the pool of the target flow.
Returns
function pointer to be returned from state function

Definition at line 351 of file StateFlow.hxx.

◆ allocate_and_clone()

template<class MessageType , int NUM_PRIO>
Action DispatchFlow< MessageType, NUM_PRIO >::allocate_and_clone ( )
inlineprotectedvirtual

Requests allocating a new buffer for sending off a clone.

Implements DispatchFlowBase< BASE_NUM_PRIO >.

Definition at line 291 of file Dispatcher.hxx.

◆ call_immediately()

template<class MessageType , int NUM_PRIO>
Action StateFlowBase::call_immediately ( Callback  c)
inline

Imediately call the next state upon return.

Parameters
cCallback "state" to move to
Returns
function pointer to be returned from state function

Definition at line 318 of file StateFlow.hxx.

◆ clone()

template<class MessageType , int NUM_PRIO>
Action DispatchFlow< MessageType, NUM_PRIO >::clone ( )
inlineprotected

Takes the allocated new buffer, copies the message into it and sends off to the clone target.

Returns
next action.

Definition at line 302 of file Dispatcher.hxx.

◆ entry()

template<class MessageType , int NUM_PRIO>
Action DispatchFlow< MessageType, NUM_PRIO >::entry ( )
inlinevirtual

Override method that will be called after each incoming message is dequeued.

Returns
next state.

Implements TypedStateFlow< MessageType, DispatchFlowBase< BASE_NUM_PRIO > >.

Definition at line 239 of file Dispatcher.hxx.

◆ get_allocation_result()

template<class MessageType , int NUM_PRIO>
template<class T >
Buffer< T > * StateFlowBase::get_allocation_result ( FlowInterface< Buffer< T > > *  target_flow)
inline

Takes the result of the asynchronous allocation.

This should be the first statement in the state where the allocation transitioned.

Parameters
target_flowis the StateFlow for which we allocated.
Returns
an initialized buffer of the correct type.

Definition at line 422 of file StateFlow.hxx.

◆ get_message_id()

template<class MessageType , int NUM_PRIO>
Base::ID DispatchFlow< MessageType, NUM_PRIO >::get_message_id ( )
inlineprotectedvirtual
Returns
the identifier bits of the current message.

Implements DispatchFlowBase< BASE_NUM_PRIO >.

Definition at line 286 of file Dispatcher.hxx.

◆ register_fallback_handler()

template<class MessageType , int NUM_PRIO>
void DispatchFlow< MessageType, NUM_PRIO >::register_fallback_handler ( HandlerType handler)
inline

Sets one handler to receive all messages that no other handler has matched.

May be called only once in the lifetime of a dispatcher object.

Parameters
handleris the handler pointer for the fallback handler.

Definition at line 279 of file Dispatcher.hxx.

◆ register_handler()

template<class MessageType , int NUM_PRIO>
void DispatchFlow< MessageType, NUM_PRIO >::register_handler ( HandlerType handler,
ID  id,
ID  mask 
)
inline

Adds a new handler to this dispatcher.

A handler will be called if incoming_id & mask == id & mask. If negateMatch_ then the handler will be called if incoming_id & mask != id & mask.

Parameters
idis the identifier of the message to listen to.
maskis the mask of the ID matcher. 0=match all; 0xff...f=match one
handleris the flow to forward message to. It must stay alive so long as *this is alive or the handler is removed.

Definition at line 256 of file Dispatcher.hxx.

◆ send_transfer()

template<class MessageType , int NUM_PRIO>
void DispatchFlow< MessageType, NUM_PRIO >::send_transfer ( )
inlineprotectedvirtual

Takes the existing buffer and sends off to the target flow.

Only used as the last action. Requires: lastHandlerToCall != nullptr.

Implements DispatchFlowBase< BASE_NUM_PRIO >.

Definition at line 319 of file Dispatcher.hxx.

◆ unregister_handler()

template<class MessageType , int NUM_PRIO>
void DispatchFlow< MessageType, NUM_PRIO >::unregister_handler ( HandlerType handler,
ID  id,
ID  mask 
)
inline

Removes a specific instance of a handler from this dispatcher.

Parameters
handlerhandler pointer to unregister.
idbits to unregister the handler for
maskmask to unregister the handler for.

Definition at line 266 of file Dispatcher.hxx.

◆ unregister_handler_all()

template<class MessageType , int NUM_PRIO>
void DispatchFlow< MessageType, NUM_PRIO >::unregister_handler_all ( HandlerType handler)
inline

Removes all instances of a handler from this dispatcher.

Definition at line 271 of file Dispatcher.hxx.


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