public

Inheritance Graph

graph BT
	DataConnection
	DataConnection --> ReferenceCounter
	click DataConnection "classUtil_1_1Network_1_1DataConnection"
	click ReferenceCounter "classUtil_1_1ReferenceCounter"

Description

A high level wrapper for a network connection of two endpoints (using tcp). It allows synchronizing of key-value pairs and sending of small data packages using multiple virtual channels. These channels allow multiple interleaved communications using a single network connection.

Note: Internally creates an additional thread.

Note: Is not designed for sending huge blocks of data at once.

Note: The maximum length of a key is 256 characters - additional characters are truncated.

Note: The given TCPConnection must only be accessed by the DataConnection or the data will get corrupted! [ DataConnection ]

Public Types

   
   
typedef uint16_t channelId_t
   
typedef std::vector< uint8_t > dataPacket_t
   
typedef std::deque< std::pair< channelId_t , dataPacket_t > > incomingValueStorage_t
   
typedef std::vector< std::pair< channelId_t , dataPacket_t > > outgoingValueStorage_t
   
typedef std::map< std::pair< channelId_t , StringIdentifier >, dataPacket_t > keyValueStorage_t
   
typedef std::function< void( channelId_t , const dataPacket_t &)> valueTypeHandler_t
   
typedef std::function< void( channelId_t , const StringIdentifier &, const dataPacket_t &)> keyValueTypeHandler_t

Public Static Attributes

   
   
const channelId_t FALLBACK_HANDLER

Public Functions

   
   
  DataConnection( TCPConnection * connection)
(ctor)
   
  ~DataConnection()
   
bool isOpen() const
   
void close()
   
void sendKeyValue( channelId_t channel, const StringIdentifier & key, const dataPacket_t & data)
   
void sendValue( channelId_t channel, const dataPacket_t & data)
   
bool extractIncomingKeyValuePair( channelId_t & channel, StringIdentifier & key, dataPacket_t & data)
   
bool extractIncomingValue( channelId_t & channel, dataPacket_t & data)
   
void registerKeyValueChannelHandler( channelId_t type, const keyValueTypeHandler_t & h)
   
void registerValueChannelHandler( channelId_t type, const valueTypeHandler_t & h)
   
void removeKeyValueChannelHandler( channelId_t type)
   
void removeValueChannelHandler( channelId_t type)
   
void handleIncomingData(float ms)

Documentation

typedef
Util::Network::DataConnection::channelId_t

public
 
 
typedef uint16_t channelId_t

Defined in Util/Network/DataConnection.h:46


typedef
Util::Network::DataConnection::dataPacket_t

public
 
 
typedef std::vector< uint8_t > dataPacket_t

Defined in Util/Network/DataConnection.h:47


typedef
Util::Network::DataConnection::incomingValueStorage_t

public
 
 
typedef std::deque< std::pair< channelId_t , dataPacket_t > > incomingValueStorage_t

Defined in Util/Network/DataConnection.h:48


typedef
Util::Network::DataConnection::outgoingValueStorage_t

public
 
 
typedef std::vector< std::pair< channelId_t , dataPacket_t > > outgoingValueStorage_t

Defined in Util/Network/DataConnection.h:49


typedef
Util::Network::DataConnection::keyValueStorage_t

public
 
 
typedef std::map< std::pair< channelId_t , StringIdentifier >, dataPacket_t > keyValueStorage_t

Defined in Util/Network/DataConnection.h:50


typedef
Util::Network::DataConnection::valueTypeHandler_t

public
 
 
typedef std::function< void( channelId_t , const dataPacket_t &)> valueTypeHandler_t

Defined in Util/Network/DataConnection.h:51


typedef
Util::Network::DataConnection::keyValueTypeHandler_t

public
 
 
typedef std::function< void( channelId_t , const StringIdentifier &, const dataPacket_t &)> keyValueTypeHandler_t

Defined in Util/Network/DataConnection.h:52


variable
Util::Network::DataConnection::FALLBACK_HANDLER

public static
 
 
const channelId_t FALLBACK_HANDLER

Defined in Util/Network/DataConnection.h:54


function
Util::Network::DataConnection::DataConnection

public
     
     
DataConnection( TCPConnection * connection )

(ctor)

Defined in Util/Network/DataConnection.h:57


function
Util::Network::DataConnection::~DataConnection

public
   
   
~DataConnection( )

Defined in Util/Network/DataConnection.h:58


function
Util::Network::DataConnection::isOpen

public const
   
   
bool isOpen( ) const

Defined in Util/Network/DataConnection.h:60


function
Util::Network::DataConnection::close

public
   
   
void close( )

Defined in Util/Network/DataConnection.h:61


function
Util::Network::DataConnection::sendKeyValue

public inline
     
     
void sendKeyValue( channelId_t channel,
  const StringIdentifier & key,
  const dataPacket_t & data
)    

Send the given key,data - pair to the connected endpoint.

Note: it is not guaranteed that this specific data is transferred for the given key. If a new value is send to the same key, the old one is skipped.

Note: it is not guaranteed that the key value pairs are end in the order of this function call.

Defined in Util/Network/DataConnection.h:69


function
Util::Network::DataConnection::sendValue

public inline
     
     
void sendValue( channelId_t channel,
  const dataPacket_t & data
)    

Send the given data to the connected endpoint. If the connection is open, it will be received in the same order as it has been sent and no data should be lost.

Note: don’t send too much data at once.

Defined in Util/Network/DataConnection.h:78


function
Util::Network::DataConnection::extractIncomingKeyValuePair

public inline
     
     
bool extractIncomingKeyValuePair( channelId_t & channel,
  StringIdentifier & key,
  dataPacket_t & data
)    

Note: prefer using a type-handler (and call only from a single thread!)

Returns

true iff data could be extracted.

Defined in Util/Network/DataConnection.h:85


function
Util::Network::DataConnection::extractIncomingValue

public inline
     
     
bool extractIncomingValue( channelId_t & channel,
  dataPacket_t & data
)    

Note: prefer using a type-handler (and call only from a single thread!)

Returns

true iff data could be extracted.

Defined in Util/Network/DataConnection.h:99


function
Util::Network::DataConnection::registerKeyValueChannelHandler

public inline
     
     
void registerKeyValueChannelHandler( channelId_t type,
  const keyValueTypeHandler_t & h
)    

Defined in Util/Network/DataConnection.h:110


function
Util::Network::DataConnection::registerValueChannelHandler

public inline
     
     
void registerValueChannelHandler( channelId_t type,
  const valueTypeHandler_t & h
)    

Defined in Util/Network/DataConnection.h:114


function
Util::Network::DataConnection::removeKeyValueChannelHandler

public inline
     
     
void removeKeyValueChannelHandler( channelId_t type )

Defined in Util/Network/DataConnection.h:118


function
Util::Network::DataConnection::removeValueChannelHandler

public inline
     
     
void removeValueChannelHandler( channelId_t type )

Defined in Util/Network/DataConnection.h:122


function
Util::Network::DataConnection::handleIncomingData

public
     
     
void handleIncomingData( float ms )

Use the registered handler to handle the incoming data.

Note:

Parameters

if
a time is given,after the given amount of ms, the handling is stopped.

Defined in Util/Network/DataConnection.h:131