Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::Stream Class Referenceabstract

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
 

Detailed Description

Base service for OpenLCB streaming protocol.

This code does not work yet.

Definition at line 49 of file Stream.hxx.

Member Typedef Documentation

◆ StreamHandle

Stream handle type.

Definition at line 59 of file Stream.hxx.

Member Enumeration Documentation

◆ Flag

enum openlcb::Stream::Flag
private

possible flag values.

Enumerator
PERMINATE_ERROR 

a perminate error occured

ACCEPT 

initiate request accepted

Definition at line 117 of file Stream.hxx.

◆ Protocol

enum openlcb::Stream::Protocol
private

Definition at line 138 of file Stream.hxx.

◆ State

enum openlcb::Stream::State
private

Possible stream states.

Enumerator
PENDING_O 

connection pending, outbound

WAITING_O 

waiting on a pending connection, outbound

CONNECTED_O 

connection made, outbound

CLOSED_O 

connection closed, outbound

PENDING_I 

connection pending, inbound

WAITING_I 

waiting on a pending connection, inbound

CONNECTED_I 

connection made, inbound

CLOSED_I 

connection closed, inbound

Definition at line 125 of file Stream.hxx.

Constructor & Destructor Documentation

◆ Stream()

openlcb::Stream::Stream ( )
inlineprotected

Default constructor.

Definition at line 93 of file Stream.hxx.

◆ ~Stream()

openlcb::Stream::~Stream ( )
inlineprotected

Default destructor.

Definition at line 103 of file Stream.hxx.

Member Function Documentation

◆ complete()

void openlcb::Stream::complete ( NodeHandle  src,
Buffer buffer 
)
private

Handle incoming stream complete messages.

Parameters
srcsource Node ID
datadatagram to post

Definition at line 478 of file Stream.cxx.

◆ handle_data()

void openlcb::Stream::handle_data ( NodeHandle  src,
Buffer buffer 
)
private

Handle incoming stream data messages.

Parameters
srcsource Node ID
datadatagram to post

Definition at line 360 of file Stream.cxx.

◆ initiate_reply()

void openlcb::Stream::initiate_reply ( NodeHandle  src,
Buffer buffer 
)
private

Handle incoming stream initiate reply messages.

Parameters
srcsource Node ID
datadatagram to post

Definition at line 321 of file Stream.cxx.

◆ initiate_request()

void openlcb::Stream::initiate_request ( NodeHandle  src,
Buffer buffer 
)
private

Handle incoming stream initiate request messages.

Parameters
srcsource Node ID
datadatagram to post

Definition at line 254 of file Stream.cxx.

◆ packet()

void openlcb::Stream::packet ( Defs::MTI  mti,
NodeHandle  src,
Buffer data 
)
protected

Handle incoming stream messages.

Parameters
mtiMessage Type Indicator
srcsource Node ID
datadatagram to post

Definition at line 504 of file Stream.cxx.

◆ proceed()

void openlcb::Stream::proceed ( NodeHandle  src,
Buffer buffer 
)
private

Handle incoming stream proceed messages.

Parameters
srcsource Node ID
datadatagram to post

Definition at line 440 of file Stream.cxx.

◆ rx_queue()

virtual BufferQueueWait * openlcb::Stream::rx_queue ( )
privatepure virtual

Get handle to the receive queue for incoming NMRAnet messages.

Returns
handle to queue

◆ sclose()

void openlcb::Stream::sclose ( StreamHandle  handle)

Close a stream.

Parameters
handlehandle to stream to close
handleto stream to close

Definition at line 128 of file Stream.cxx.

◆ sopen()

Stream::StreamHandle openlcb::Stream::sopen ( NodeHandle  dst,
long long  timeout 
)

Open a stream.

Parameters
dstdestination node for stream
timeout0 = do not wait for success, deliver success asynchronously > 0, wait for success, or fail on timeout
Returns
NULL on fail, else stream handle on success or pending success
Todo:
(Stuart Baker) is there a race between connected and timeout

Definition at line 48 of file Stream.cxx.

◆ sread()

ssize_t openlcb::Stream::sread ( StreamHandle  handle,
void *  buf,
size_t  size 
)

Read data from a stream.

Parameters
handlehandle to stream to read from
bufbuffer to copy data to
sizesize in bytes to read from stream
Returns
number of bytes read, else -1 on error with errno set to indicate error

Definition at line 220 of file Stream.cxx.

◆ swrite()

ssize_t openlcb::Stream::swrite ( StreamHandle  handle,
const void *  buf,
size_t  size 
)

Write data to a stream.

Parameters
handlehandle to stream to write to
bufbuffer to copy data from
sizesize in bytes to write to stream
Returns
number of bytes written, else -1 on error with errno set to indicate error

Definition at line 166 of file Stream.cxx.

◆ write()

virtual int openlcb::Stream::write ( Defs::MTI  mti,
NodeHandle  dst,
Buffer data 
)
privatepure virtual

Write a message from a node.

We should already have a mutex lock at this at this point.

Parameters
mtiMessage Type Indicator
dstdestination node ID, 0 if unavailable
dataNMRAnet packet data
Returns
0 upon success

Member Data Documentation

◆ CHANNELS_PER_NODE

const size_t openlcb::Stream::CHANNELS_PER_NODE
static

number of simultaneous open streams per virtual node instance

Definition at line 53 of file Stream.hxx.

◆ count

size_t openlcb::Stream::count
private

number of active streams for this node

Definition at line 218 of file Stream.hxx.

◆ inboundTree

RBTree<uint8_t, Metadata*> openlcb::Stream::inboundTree
private

tree for keeping track of inbound streams

Definition at line 215 of file Stream.hxx.

◆ MAX_BUFFER_SIZE

const uint16_t openlcb::Stream::MAX_BUFFER_SIZE
static

Max buffer size for stream transmission segments.

Definition at line 56 of file Stream.hxx.

◆ outboundTree

RBTree<uint8_t, Metadata*> openlcb::Stream::outboundTree
private

tree for keeping track of outbound streams

Definition at line 212 of file Stream.hxx.

◆ sem

OSSem openlcb::Stream::sem
private

wait for completion semaphore

Definition at line 221 of file Stream.hxx.


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