|
Open Model Railroad Network (OpenMRN)
|
Base service for OpenLCB streaming protocol. More...
#include <Stream.hxx>
Classes | |
| struct | Metadata |
| Stream metadata, often cast to StreamHandle. More... | |
Public Types | |
| typedef void * | StreamHandle |
| Stream handle type. | |
Public Member Functions | |
| StreamHandle | sopen (NodeHandle dst, long long timeout) |
| Open a stream. | |
| void | sclose (StreamHandle handle) |
| Close a stream. | |
| ssize_t | swrite (StreamHandle handle, const void *buf, size_t size) |
| Write data to a stream. | |
| ssize_t | sread (StreamHandle handle, void *buf, size_t size) |
| Read data from a stream. | |
Static Public Attributes | |
| static const size_t | CHANNELS_PER_NODE |
| number of simultaneous open streams per virtual node instance | |
| static const uint16_t | MAX_BUFFER_SIZE |
| Max buffer size for stream transmission segments. | |
Protected Member Functions | |
| Stream () | |
| Default constructor. | |
| ~Stream () | |
| Default destructor. | |
| void | packet (Defs::MTI mti, NodeHandle src, Buffer *data) |
| Handle incoming stream messages. | |
Private Types | |
| enum | Flag { PERMINATE_ERROR = 0x40 , ACCEPT = 0x80 } |
| possible flag values. More... | |
| enum | State { PENDING_O , WAITING_O , CONNECTED_O , CLOSED_O , PENDING_I , WAITING_I , CONNECTED_I , CLOSED_I } |
| Possible stream states. More... | |
| enum | Protocol { DISCOVER_1 = 0x0600000000000000 , DISCOVER_2 = 0x0500000000000000 , DISCOVER_3 = 0x0400000000000000 , DISCOVER_4 = 0x0300000000000000 , DISCOVER_5 = 0x0200000000000000 , DISCOVER_6 = 0x0100000000000000 , DISCOVERED = 0x0000000000000000 , DISCOVERED_DEC = 0x0100000000000000 , DISCOVER_MASK = 0xFF00000000000000 , DISCOVER_SHIFT = 56 } |
Private Member Functions | |
| virtual int | write (Defs::MTI mti, NodeHandle dst, Buffer *data)=0 |
| Write a message from a node. | |
| virtual BufferQueueWait * | rx_queue ()=0 |
| Get handle to the receive queue for incoming NMRAnet messages. | |
| void | initiate_request (NodeHandle src, Buffer *buffer) |
| Handle incoming stream initiate request messages. | |
| void | initiate_reply (NodeHandle src, Buffer *buffer) |
| Handle incoming stream initiate reply messages. | |
| void | handle_data (NodeHandle src, Buffer *buffer) |
| Handle incoming stream data messages. | |
| void | proceed (NodeHandle src, Buffer *buffer) |
| Handle incoming stream proceed messages. | |
| void | complete (NodeHandle src, Buffer *buffer) |
| Handle incoming stream complete messages. | |
| DISALLOW_COPY_AND_ASSIGN (Stream) | |
Private Attributes | |
| RBTree< uint8_t, Metadata * > | outboundTree |
| tree for keeping track of outbound streams | |
| RBTree< uint8_t, Metadata * > | inboundTree |
| tree for keeping track of inbound streams | |
| size_t | count |
| number of active streams for this node | |
| OSSem | sem |
| wait for completion semaphore | |
Base service for OpenLCB streaming protocol.
This code does not work yet.
Definition at line 49 of file Stream.hxx.
| typedef void* openlcb::Stream::StreamHandle |
Stream handle type.
Definition at line 59 of file Stream.hxx.
|
private |
possible flag values.
| Enumerator | |
|---|---|
| PERMINATE_ERROR | a perminate error occured |
| ACCEPT | initiate request accepted |
Definition at line 117 of file Stream.hxx.
|
private |
Definition at line 138 of file Stream.hxx.
|
private |
Possible stream states.
Definition at line 125 of file Stream.hxx.
|
inlineprotected |
Default constructor.
Definition at line 93 of file Stream.hxx.
|
inlineprotected |
Default destructor.
Definition at line 103 of file Stream.hxx.
|
private |
Handle incoming stream complete messages.
| src | source Node ID |
| data | datagram to post |
Definition at line 478 of file Stream.cxx.
|
private |
Handle incoming stream data messages.
| src | source Node ID |
| data | datagram to post |
Definition at line 360 of file Stream.cxx.
|
private |
Handle incoming stream initiate reply messages.
| src | source Node ID |
| data | datagram to post |
Definition at line 321 of file Stream.cxx.
|
private |
Handle incoming stream initiate request messages.
| src | source Node ID |
| data | datagram to post |
Definition at line 254 of file Stream.cxx.
|
protected |
Handle incoming stream messages.
| mti | Message Type Indicator |
| src | source Node ID |
| data | datagram to post |
Definition at line 504 of file Stream.cxx.
|
private |
Handle incoming stream proceed messages.
| src | source Node ID |
| data | datagram to post |
Definition at line 440 of file Stream.cxx.
|
privatepure virtual |
Get handle to the receive queue for incoming NMRAnet messages.
| void openlcb::Stream::sclose | ( | StreamHandle | handle | ) |
Close a stream.
| handle | handle to stream to close |
| handle | to stream to close |
Definition at line 128 of file Stream.cxx.
| Stream::StreamHandle openlcb::Stream::sopen | ( | NodeHandle | dst, |
| long long | timeout | ||
| ) |
Open a stream.
| dst | destination node for stream |
| timeout | 0 = do not wait for success, deliver success asynchronously > 0, wait for success, or fail on timeout |
Definition at line 48 of file Stream.cxx.
| ssize_t openlcb::Stream::sread | ( | StreamHandle | handle, |
| void * | buf, | ||
| size_t | size | ||
| ) |
Read data from a stream.
| handle | handle to stream to read from |
| buf | buffer to copy data to |
| size | size in bytes to read from stream |
Definition at line 220 of file Stream.cxx.
| ssize_t openlcb::Stream::swrite | ( | StreamHandle | handle, |
| const void * | buf, | ||
| size_t | size | ||
| ) |
Write data to a stream.
| handle | handle to stream to write to |
| buf | buffer to copy data from |
| size | size in bytes to write to stream |
Definition at line 166 of file Stream.cxx.
|
privatepure virtual |
Write a message from a node.
We should already have a mutex lock at this at this point.
| mti | Message Type Indicator |
| dst | destination node ID, 0 if unavailable |
| data | NMRAnet packet data |
|
static |
number of simultaneous open streams per virtual node instance
Definition at line 53 of file Stream.hxx.
|
private |
number of active streams for this node
Definition at line 218 of file Stream.hxx.
tree for keeping track of inbound streams
Definition at line 215 of file Stream.hxx.
|
static |
Max buffer size for stream transmission segments.
Definition at line 56 of file Stream.hxx.
tree for keeping track of outbound streams
Definition at line 212 of file Stream.hxx.
|
private |
wait for completion semaphore
Definition at line 221 of file Stream.hxx.