Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::BLEHubPort::InputFlow Class Reference

State flow that handles data arriving from this bluetooth connection. More...

#include <BLEHubPort.hxx>

Inheritance diagram for openlcb::BLEHubPort::InputFlow:
StateFlowBase Atomic Executable Notifiable QMember Destructable

Public Member Functions

 InputFlow (BLEHubPort *parent, DirectHubInterface< uint8_t[]> *hub, std::unique_ptr< MessageSegmenter > segmenter)
 
void input_data (const uint8_t *data, size_t len)
 Called by the BLE stack when input data arrives from this remote endpoint.
 
Action take_input ()
 Moves over data from the other thread which is in the transferBuf_.
 
Action segment_head ()
 Takes the head of segmentBuf_, and performs the message segmentation on it.
 
Action send_output ()
 Called when one full message is segmented into outputBuf_.
 
Action send_callback ()
 This is the callback state that is invoked inline by the hub.
 
Action send_done ()
 
- 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 Attributes

BLEHubPortparent_
 Owning outside flow.
 
bool flowWaiting_
 True if the flow is paused and waiting for more data to arrive.
 
uint8_t inlineCall_: 1
 1 if we got the send callback inline from the read_done.
 
uint8_t sendComplete_: 1
 1 if the run callback actually happened inline.
 
LinkedDataBufferPtr appendBuf_
 Current buffer for the input data. Owned by the input thread.
 
LinkedDataBufferPtr transferBuf_
 Buffer for transferring data rfrom the input thread to the service thread.
 
LinkedDataBufferPtr segmentBuf_
 Buffer for the data being segmented.
 
LinkedDataBufferPtr outputBuf_
 Buffer for one sent message. This is the output of the segmenter.
 
std::unique_ptr< MessageSegmentersegmenter_
 Implementation (and state) of the business logic that segments incoming bytes into messages that shall be given to the hub.
 
DirectHubInterface< uint8_t[]> * hub_
 Parent hub where output data is coming from.
 

Friends

class BLEHubPort
 

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
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Detailed Description

State flow that handles data arriving from this bluetooth connection.

Definition at line 320 of file BLEHubPort.hxx.

Constructor & Destructor Documentation

◆ InputFlow()

openlcb::BLEHubPort::InputFlow::InputFlow ( BLEHubPort parent,
DirectHubInterface< uint8_t[]> *  hub,
std::unique_ptr< MessageSegmenter segmenter 
)
inline

Definition at line 323 of file BLEHubPort.hxx.

Member Function Documentation

◆ input_data()

void openlcb::BLEHubPort::InputFlow::input_data ( const uint8_t *  data,
size_t  len 
)
inline

Called by the BLE stack when input data arrives from this remote endpoint.

Parameters
datapayload that arrived. The data will be copied inline, and does not need to exist beyond when this function returns.
lennumber of bytes in the data payload.

Definition at line 342 of file BLEHubPort.hxx.

◆ segment_head()

Action openlcb::BLEHubPort::InputFlow::segment_head ( )
inline

Takes the head of segmentBuf_, and performs the message segmentation on it.

Puts the resulting byte offsets into the outputBuf_.

Definition at line 388 of file BLEHubPort.hxx.

◆ send_callback()

Action openlcb::BLEHubPort::InputFlow::send_callback ( )
inline

This is the callback state that is invoked inline by the hub.

Since the hub invokes this->run(), a standard StateFlow will execute whatever state is current. We have set STATE(send_callback) as the current state above, hence the code continues in this function.

Todo:
do we need to add barriernotifiables here?

Definition at line 440 of file BLEHubPort.hxx.

◆ send_done()

Action openlcb::BLEHubPort::InputFlow::send_done ( )
inline

Definition at line 466 of file BLEHubPort.hxx.

◆ send_output()

Action openlcb::BLEHubPort::InputFlow::send_output ( )
inline

Called when one full message is segmented into outputBuf_.

Sends this to the hub.

Definition at line 420 of file BLEHubPort.hxx.

◆ take_input()

Action openlcb::BLEHubPort::InputFlow::take_input ( )
inline

Moves over data from the other thread which is in the transferBuf_.

Continues on to segment and send them as messages to the hub.

Definition at line 378 of file BLEHubPort.hxx.

Friends And Related Symbol Documentation

◆ BLEHubPort

friend class BLEHubPort
friend

Definition at line 473 of file BLEHubPort.hxx.

Member Data Documentation

◆ appendBuf_

LinkedDataBufferPtr openlcb::BLEHubPort::InputFlow::appendBuf_
private

Current buffer for the input data. Owned by the input thread.

Definition at line 487 of file BLEHubPort.hxx.

◆ flowWaiting_

bool openlcb::BLEHubPort::InputFlow::flowWaiting_
private

True if the flow is paused and waiting for more data to arrive.

Guarded by atomic *this.

Definition at line 480 of file BLEHubPort.hxx.

◆ hub_

DirectHubInterface<uint8_t[]>* openlcb::BLEHubPort::InputFlow::hub_
private

Parent hub where output data is coming from.

Definition at line 500 of file BLEHubPort.hxx.

◆ inlineCall_

uint8_t openlcb::BLEHubPort::InputFlow::inlineCall_
private

1 if we got the send callback inline from the read_done.

Definition at line 482 of file BLEHubPort.hxx.

◆ outputBuf_

LinkedDataBufferPtr openlcb::BLEHubPort::InputFlow::outputBuf_
private

Buffer for one sent message. This is the output of the segmenter.

Definition at line 495 of file BLEHubPort.hxx.

◆ parent_

BLEHubPort* openlcb::BLEHubPort::InputFlow::parent_
private

Owning outside flow.

Definition at line 476 of file BLEHubPort.hxx.

◆ segmentBuf_

LinkedDataBufferPtr openlcb::BLEHubPort::InputFlow::segmentBuf_
private

Buffer for the data being segmented.

Owned by (only manipulated on) the Service executor.

Definition at line 493 of file BLEHubPort.hxx.

◆ segmenter_

std::unique_ptr<MessageSegmenter> openlcb::BLEHubPort::InputFlow::segmenter_
private

Implementation (and state) of the business logic that segments incoming bytes into messages that shall be given to the hub.

Definition at line 498 of file BLEHubPort.hxx.

◆ sendComplete_

uint8_t openlcb::BLEHubPort::InputFlow::sendComplete_
private

1 if the run callback actually happened inline.

Definition at line 484 of file BLEHubPort.hxx.

◆ transferBuf_

LinkedDataBufferPtr openlcb::BLEHubPort::InputFlow::transferBuf_
private

Buffer for transferring data rfrom the input thread to the service thread.

Guarded by atomic *this.

Definition at line 490 of file BLEHubPort.hxx.


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