Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
PoolToQueueFlow< T > Class Template Reference

This flow can be used to take all entries that show up in a FixedPool and send them (empty) to a stateflow for processing. More...

#include <PoolToQueueFlow.hxx>

Inheritance diagram for PoolToQueueFlow< T >:
StateFlowBase Executable Notifiable QMember Destructable

Public Member Functions

 PoolToQueueFlow (Service *service, FixedPool *source, FlowInterface< T > *dest)
 Constructor.
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
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.
 

Private Member Functions

Action get_next_entry ()
 Allocates the next entry from the pool.
 
Action got_entry ()
 Send the entry we got to the queue.
 

Private Attributes

FixedPoolsource_
 The pool to read all entries from.
 
FlowInterface< T > * dest_
 The queue to send all entries to.
 

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.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- 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 Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

template<class T>
class PoolToQueueFlow< T >

This flow can be used to take all entries that show up in a FixedPool and send them (empty) to a stateflow for processing.

This basically allows a regular stateflow for reacting to when the message it has sent out has finished processing by the destination.

Usage: create a FixedPool of a given size (that you want to buffer, usually 2 or 3) of the particular type T. Implement your request generator as a StateFlow<Buffer<T> >. Make the request generator's entry() state do the following: clear the incoming buffer, fill in the new request, then send off to the request processor.

Then create a PoolToQueueFlow<Buffer<T> > on the pool and give it the request generator's pointer.

Whenever the request processor is finished processing a request, the buffer will be returned to the pool, from there it will be automatically picked up by the PoolToQueueFlow, sent to the request generator, which will generate the next request and send it to the request processor. This will run in an infinite loop with the fixed buffer size.

Definition at line 59 of file PoolToQueueFlow.hxx.

Constructor & Destructor Documentation

◆ PoolToQueueFlow()

template<class T >
PoolToQueueFlow< T >::PoolToQueueFlow ( Service service,
FixedPool source,
FlowInterface< T > *  dest 
)
inline

Constructor.

Parameters
servicedefines which executor this flow will run in
sourcethe pool to allocate all entries from
destthe queue to send all allocated entries to.

Definition at line 67 of file PoolToQueueFlow.hxx.

Member Function Documentation

◆ get_next_entry()

template<class T >
Action PoolToQueueFlow< T >::get_next_entry ( )
inlineprivate

Allocates the next entry from the pool.

Returns
next state.

Definition at line 77 of file PoolToQueueFlow.hxx.

◆ got_entry()

template<class T >
Action PoolToQueueFlow< T >::got_entry ( )
inlineprivate

Send the entry we got to the queue.

Returns
next state.

Definition at line 83 of file PoolToQueueFlow.hxx.

Member Data Documentation

◆ dest_

template<class T >
FlowInterface<T>* PoolToQueueFlow< T >::dest_
private

The queue to send all entries to.

Definition at line 93 of file PoolToQueueFlow.hxx.

◆ source_

template<class T >
FixedPool* PoolToQueueFlow< T >::source_
private

The pool to read all entries from.

Definition at line 91 of file PoolToQueueFlow.hxx.


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