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

This is a self-owned flow which reads an memory space into a stream. More...

#include <MemoryConfigStream.hxx>

Inheritance diagram for openlcb::MemorySpaceStreamReadFlow:
StateFlowBase Executable Notifiable QMember Destructable

Public Types

using CallbackFn = std::function< void(uint16_t)>
 This callback function will be called with an error code, or 0 on success.
 

Public Member Functions

 MemorySpaceStreamReadFlow (Node *node, MemorySpace *space, NodeHandle dst, uint8_t dst_stream_id, uint32_t ofs, uint32_t len, CallbackFn started_cb)
 Constructor.
 
uint8_t get_src_stream_id ()
 
uint8_t get_dst_stream_id ()
 
- 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 alloc_stream ()
 
Action got_sender ()
 
Action initiate_stream ()
 
Action wait_for_started ()
 
Action alloc_buffer ()
 
Action have_raw_buffer ()
 
Action try_read ()
 
Action wait_for_close ()
 
Action done_stream ()
 
StreamTransportstream_transport ()
 

Private Attributes

LimitedPool sendBufferPool_ {sizeof(RawBuffer), 2, rawBufferPool}
 This pool is used to allocate raw buffers to read data into from the memory space.
 
ByteBufferPtr sendBuffer_
 We keep reading into this buffer from the memory space.
 
StateFlowTimer timer_ {this}
 Helper object for waiting.
 
NodeHandle dst_
 Address to which we are sending the stream.
 
CallbackFn startedCb_
 callback to invoke after start is successful.
 
MemorySpacespace_
 Memory space we are reading.
 
uint8_t srcStreamId_ {StreamDefs::INVALID_STREAM_ID}
 Destination stream ID on the target node.
 
uint8_t dstStreamId_
 Destination stream ID on the target node.
 
Nodenode_
 Node from which we are sending the stream.
 
uint32_t ofs_
 Next byte to read.
 
uint32_t len_
 How many bytes are left to read.
 
StreamSenderCansenderCan_
 
StreamSendersender_
 

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

This is a self-owned flow which reads an memory space into a stream.

Definition at line 47 of file MemoryConfigStream.hxx.

Member Typedef Documentation

◆ CallbackFn

using openlcb::MemorySpaceStreamReadFlow::CallbackFn = std::function<void(uint16_t)>

This callback function will be called with an error code, or 0 on success.

Definition at line 52 of file MemoryConfigStream.hxx.

Constructor & Destructor Documentation

◆ MemorySpaceStreamReadFlow()

openlcb::MemorySpaceStreamReadFlow::MemorySpaceStreamReadFlow ( Node node,
MemorySpace space,
NodeHandle  dst,
uint8_t  dst_stream_id,
uint32_t  ofs,
uint32_t  len,
CallbackFn  started_cb 
)
inline

Constructor.

Does NOT transfer ownership; this class will delete itself.

Parameters
nodevirtual nde where to send the stream from.
spacememory space pointer
dsttarget node to send data to
dst_stream_idsream ID on the target node
ofswhere to start reading from in the memory space
lenhow many bytes to send (0xFFFFFFFF to send until EOF)
started_cbwill be invoked when the stream initiate reply arrives and data can be sent to the stream.

Definition at line 65 of file MemoryConfigStream.hxx.

Member Function Documentation

◆ alloc_buffer()

Action openlcb::MemorySpaceStreamReadFlow::alloc_buffer ( )
inlineprivate

Definition at line 140 of file MemoryConfigStream.hxx.

◆ alloc_stream()

Action openlcb::MemorySpaceStreamReadFlow::alloc_stream ( )
inlineprivate

Definition at line 94 of file MemoryConfigStream.hxx.

◆ done_stream()

Action openlcb::MemorySpaceStreamReadFlow::done_stream ( )
inlineprivate

Definition at line 222 of file MemoryConfigStream.hxx.

◆ get_dst_stream_id()

uint8_t openlcb::MemorySpaceStreamReadFlow::get_dst_stream_id ( )
inline
Returns
the currently running flow's destination stream ID.

Definition at line 88 of file MemoryConfigStream.hxx.

◆ get_src_stream_id()

uint8_t openlcb::MemorySpaceStreamReadFlow::get_src_stream_id ( )
inline
Returns
the currently running flow's source stream ID.

Definition at line 82 of file MemoryConfigStream.hxx.

◆ got_sender()

Action openlcb::MemorySpaceStreamReadFlow::got_sender ( )
inlineprivate
Todo:
the APIs are not on the right object in StreamSender, so we have to do this down cast.

Definition at line 100 of file MemoryConfigStream.hxx.

◆ have_raw_buffer()

Action openlcb::MemorySpaceStreamReadFlow::have_raw_buffer ( )
inlineprivate

Definition at line 146 of file MemoryConfigStream.hxx.

◆ initiate_stream()

Action openlcb::MemorySpaceStreamReadFlow::initiate_stream ( )
inlineprivate

Definition at line 112 of file MemoryConfigStream.hxx.

◆ stream_transport()

StreamTransport * openlcb::MemorySpaceStreamReadFlow::stream_transport ( )
inlineprivate

Definition at line 230 of file MemoryConfigStream.hxx.

◆ try_read()

Action openlcb::MemorySpaceStreamReadFlow::try_read ( )
inlineprivate

Definition at line 156 of file MemoryConfigStream.hxx.

◆ wait_for_close()

Action openlcb::MemorySpaceStreamReadFlow::wait_for_close ( )
inlineprivate

Definition at line 204 of file MemoryConfigStream.hxx.

◆ wait_for_started()

Action openlcb::MemorySpaceStreamReadFlow::wait_for_started ( )
inlineprivate

Definition at line 120 of file MemoryConfigStream.hxx.

Member Data Documentation

◆ dst_

NodeHandle openlcb::MemorySpaceStreamReadFlow::dst_
private

Address to which we are sending the stream.

Definition at line 245 of file MemoryConfigStream.hxx.

◆ dstStreamId_

uint8_t openlcb::MemorySpaceStreamReadFlow::dstStreamId_
private

Destination stream ID on the target node.

Definition at line 253 of file MemoryConfigStream.hxx.

◆ len_

uint32_t openlcb::MemorySpaceStreamReadFlow::len_
private

How many bytes are left to read.

0xFFFFFFFF if all bytes until EOF need to be read.

Definition at line 260 of file MemoryConfigStream.hxx.

◆ node_

Node* openlcb::MemorySpaceStreamReadFlow::node_
private

Node from which we are sending the stream.

Definition at line 255 of file MemoryConfigStream.hxx.

◆ ofs_

uint32_t openlcb::MemorySpaceStreamReadFlow::ofs_
private

Next byte to read.

Definition at line 257 of file MemoryConfigStream.hxx.

◆ sendBuffer_

ByteBufferPtr openlcb::MemorySpaceStreamReadFlow::sendBuffer_
private

We keep reading into this buffer from the memory space.

Definition at line 241 of file MemoryConfigStream.hxx.

◆ sendBufferPool_

LimitedPool openlcb::MemorySpaceStreamReadFlow::sendBufferPool_ {sizeof(RawBuffer), 2, rawBufferPool}
private

This pool is used to allocate raw buffers to read data into from the memory space.

By keeping the count limited we can ensure that we only carry 2 kbytes of data in RAM before it gets dumped into the CAN-bus packets.

Definition at line 239 of file MemoryConfigStream.hxx.

◆ sender_

StreamSender* openlcb::MemorySpaceStreamReadFlow::sender_
private

Definition at line 264 of file MemoryConfigStream.hxx.

◆ senderCan_

StreamSenderCan* openlcb::MemorySpaceStreamReadFlow::senderCan_
private

Definition at line 263 of file MemoryConfigStream.hxx.

◆ space_

MemorySpace* openlcb::MemorySpaceStreamReadFlow::space_
private

Memory space we are reading.

Definition at line 249 of file MemoryConfigStream.hxx.

◆ srcStreamId_

uint8_t openlcb::MemorySpaceStreamReadFlow::srcStreamId_ {StreamDefs::INVALID_STREAM_ID}
private

Destination stream ID on the target node.

Definition at line 251 of file MemoryConfigStream.hxx.

◆ startedCb_

CallbackFn openlcb::MemorySpaceStreamReadFlow::startedCb_
private

callback to invoke after start is successful.

Definition at line 247 of file MemoryConfigStream.hxx.

◆ timer_

StateFlowTimer openlcb::MemorySpaceStreamReadFlow::timer_ {this}
private

Helper object for waiting.

Definition at line 243 of file MemoryConfigStream.hxx.


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