Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
StreamReceiver.hxx
Go to the documentation of this file.
1
36#ifndef _OPENLCB_STREAMRECEIVER_HXX_
37#define _OPENLCB_STREAMRECEIVER_HXX_
38
40
41#include "openlcb/IfCan.hxx"
43#include "utils/ByteBuffer.hxx"
44#include "utils/LimitedPool.hxx"
45
46namespace openlcb
47{
48
50{
51public:
57 StreamReceiverCan(IfCan *interface, uint8_t local_stream_id);
58
60
64 void send(Buffer<StreamReceiveRequest> *msg, unsigned prio = 0) override;
65
69 void cancel_request() override;
70
71private:
73 void announced_stream();
74
76 Action entry() override
77 {
78 return return_ok();
79 }
80
81 Action wait_for_wakeup()
82 {
84 {
86 }
87 isWaiting_ = 1;
88 return wait_and_call(STATE(wakeup));
89 }
90
92 Action wakeup();
93
96 Action init_reply();
97 Action init_buffer_ready();
98
101 Action window_reached();
104 Action have_raw_buffer();
105
111
113 inline void handle_bytes_received(const uint8_t *data, size_t len);
114
120
122 void unregister_handlers();
123
126 {
127 return static_cast<IfCan *>(service());
128 }
129
132 {
133 return request()->dst_;
134 }
135
137 MessageHandler::GenericHandler streamInitiateHandler_ {
139
140 class StreamDataHandler;
141 friend class StreamDataHandler;
142
144 MessageHandler::GenericHandler streamCompleteHandler_ {
146
152
155
159
161 std::unique_ptr<StreamDataHandler> dataHandler_;
162
165
168
171 const uint8_t assignedStreamId_;
172
174 uint8_t streamClosed_ : 1;
176 uint8_t pendingInit_ : 1;
178 uint8_t pendingCancel_ : 1;
180 uint8_t isWaiting_ : 1;
181}; // class StreamReceiver
182
183} // namespace openlcb
184
185#endif // _OPENLCB_STREAMRECEIVER_HXX_
void handle_stream_complete()
Handles incoming stream data complete message.
Pool * rawBufferPool
Use this BufferPool to allocate raw buffers.
Definition Buffer.cxx:38
Buffer< RawData > RawBuffer
Buffers of this type will be allocated from the rawBufferPool to hold the payloads of untyped data st...
BufferPtr< RawData > RawBufferPtr
Holds a raw buffer.
BufferPtr< ByteChunk > ByteBufferPtr
Buffer pointer type for references.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
Action return_ok()
Terminates the flow and returns the request buffer to the caller with an error code of OK (zero).
StreamReceiveRequest * request()
Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits th...
Return type for a state flow callback.
Service * service()
Return a pointer to the service I am bound to.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard.
Definition IfCan.hxx:65
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
void cancel_request() override
Cancels the currently pending stream receive request.
Action wakeup()
Root of the flow when something happens in the handlers.
size_t totalByteCount_
How many bytes we have transmitted in this stream so far.
void unregister_handlers()
Removes all handlers that are registered.
void handle_stream_initiate(Buffer< GenMessage > *message)
Invoked by the GenericHandler when a stream initiate message arrives.
std::unique_ptr< StreamDataHandler > dataHandler_
Helper object that receives the actual stream CAN frames.
ByteBufferPtr currentBuffer_
The buffer that we are currently filling with incoming data.
Action have_raw_buffer()
Called when the allocation of the raw buffer is successful.
LimitedPool lastBufferPool_
This pool is used to allocate one raw buffer per stream window size.
Action init_reply()
Invoked when we get the stream initiate request.
void announced_stream()
Helper function for send() when a stream has to start synchronously.
uint8_t streamClosed_
1 if we received the stream complete message.
MessageHandler::GenericHandler streamInitiateHandler_
Helper class for incoming message for stream initiate.
uint8_t pendingInit_
1 if we received the stream init request message.
void send(Buffer< StreamReceiveRequest > *msg, unsigned prio=0) override
Implements the flow interface for the request API.
Action window_reached()
Invoked when the stream window runs out.
void handle_stream_complete(Buffer< GenMessage > *message)
Invoked by the GenericHandler when a stream complete message arrives.
uint16_t streamWindowRemaining_
Remaining stream window size.
uint8_t isWaiting_
1 if we are currently waiting for a notification
Action entry() override
This state is not used, but it's virtual abstract.
uint8_t pendingCancel_
1 if we received a cancel request
RawBufferPtr lastBuffer_
The buffer that will be the last one in this stream window.
const uint8_t assignedStreamId_
Unique stream ID at the destination (local) node, assigned at construction time.
void handle_bytes_received(const uint8_t *data, size_t len)
Handles data arriving from the network.
MessageHandler::GenericHandler streamCompleteHandler_
Helper class for incoming message for stream complete.