Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DirectHubImpl< T > Class Template Reference
Inheritance diagram for DirectHubImpl< T >:
DirectHubInterface< T > StateFlowBase Atomic Destructable Executable Notifiable QMember Destructable

Public Member Functions

 DirectHubImpl (DirectHubService *service)
 
Serviceget_service () override
 
void register_port (DirectHubPort< T > *port) override
 Adds a port to this hub.
 
void unregister_port (DirectHubPort< T > *port) override
 Synchronously unregisters a port.
 
void unregister_port (DirectHubPort< T > *port, Notifiable *done) override
 Removes a port from this hub.
 
void enqueue_send (Executable *caller) override
 Signals that the caller wants to send a message to the hub.
 
MessageAccessor< T > * mutable_message () override
 Accessor to fill in the message payload.
 
void do_send () override
 Sends a message to the hub.
 
bool should_send_to (DirectHubPort< T > *p)
 Filters a message going towards a specific output port.
 

Private Member Functions

DirectHubServiceservice ()
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Private Attributes

std::vector< DirectHubPort< T > * > ports_
 Stores the registered output ports. Protected by Atomic *this.
 
MessageAccessor< T > msg_
 The message we are trying to send.
 

Additional Inherited Members

- 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.
 
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Protected Member Functions inherited from Executable
void test_deletion ()
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
void init ()
 Initiailize a QMember, in place of a public placement construction.
 
- Static Protected 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 Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

template<class T>
class DirectHubImpl< T >

Definition at line 142 of file DirectHub.cxx.

Constructor & Destructor Documentation

◆ DirectHubImpl()

template<class T >
DirectHubImpl< T >::DirectHubImpl ( DirectHubService service)
inline

Definition at line 147 of file DirectHub.cxx.

◆ ~DirectHubImpl()

template<class T >
DirectHubImpl< T >::~DirectHubImpl ( )
inline

Definition at line 152 of file DirectHub.cxx.

Member Function Documentation

◆ do_send()

template<class T >
void DirectHubImpl< T >::do_send ( )
inlineoverridevirtual

Sends a message to the hub.

Before this is called, the message has to be filled in via mutable_message().

Implements DirectHubInterface< T >.

Definition at line 204 of file DirectHub.cxx.

◆ enqueue_send()

template<class T >
void DirectHubImpl< T >::enqueue_send ( Executable caller)
inlineoverridevirtual

Signals that the caller wants to send a message to the hub.

When the hub is ready for that, will execute *caller. This might happen inline within this function call, or on a different executor.

Parameters
callercallback that actually sends the message. It is required to call do_send() inline.

Implements DirectHubInterface< T >.

Definition at line 194 of file DirectHub.cxx.

◆ get_service()

template<class T >
Service * DirectHubImpl< T >::get_service ( )
inlineoverridevirtual
Returns
an executor service.

Implements DirectHubInterface< T >.

Definition at line 157 of file DirectHub.cxx.

◆ mutable_message()

template<class T >
MessageAccessor< T > * DirectHubImpl< T >::mutable_message ( )
inlineoverridevirtual

Accessor to fill in the message payload.

Must be called only from within the callback as invoked by enqueue_send.

Returns
mutable structure to fill in the message. This structure was cleared by the hub before it is returned here.

Implements DirectHubInterface< T >.

Definition at line 199 of file DirectHub.cxx.

◆ register_port()

template<class T >
void DirectHubImpl< T >::register_port ( DirectHubPort< T > *  port)
inlineoverridevirtual

Adds a port to this hub.

This port will be receiving all further messages.

Parameters
portthe downstream port.

Implements DirectHubInterface< T >.

Definition at line 162 of file DirectHub.cxx.

◆ service()

template<class T >
DirectHubService * DirectHubImpl< T >::service ( )
inlineprivate

Definition at line 238 of file DirectHub.cxx.

◆ should_send_to()

template<class T >
bool DirectHubImpl< T >::should_send_to ( DirectHubPort< T > *  p)
inline

Filters a message going towards a specific output port.

Parameters
pthe output port
Returns
true if this message should be sent to that output port.

Definition at line 232 of file DirectHub.cxx.

◆ unregister_port() [1/2]

template<class T >
void DirectHubImpl< T >::unregister_port ( DirectHubPort< T > *  port)
inlineoverridevirtual

Synchronously unregisters a port.

Implements DirectHubInterface< T >.

Definition at line 169 of file DirectHub.cxx.

◆ unregister_port() [2/2]

template<class T >
void DirectHubImpl< T >::unregister_port ( DirectHubPort< T > *  port,
Notifiable done 
)
inlineoverridevirtual

Removes a port from this hub.

This port must have been registered previously.

Parameters
portthe downstream port.

Implements DirectHubInterface< T >.

Definition at line 179 of file DirectHub.cxx.

Member Data Documentation

◆ msg_

template<class T >
MessageAccessor<T> DirectHubImpl< T >::msg_
private

The message we are trying to send.

Definition at line 247 of file DirectHub.cxx.

◆ ports_

template<class T >
std::vector<DirectHubPort<T> *> DirectHubImpl< T >::ports_
private

Stores the registered output ports. Protected by Atomic *this.

Definition at line 244 of file DirectHub.cxx.


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