Ocean
Ocean::Network::StreamingServer Class Reference

This class implements a streaming server. More...

Inheritance diagram for Ocean::Network::StreamingServer:

Data Structures

class  Channel
 This class implements a channel. More...
 
class  Connection
 This class holds some information connected with a TCP connection. More...
 

Public Types

typedef Callback< void, const StateChannelCallback
 Definition of a callback function on channel start, stop or pause requests. More...
 
typedef unsigned int ChannelId
 Definition of a channel id. More...
 
- Public Types inherited from Ocean::Network::Streaming
enum  State { STATE_START , STATE_PAUSE , STATE_STOP , STATE_TYPE_CHANGED }
 Definition of different streaming states. More...
 
typedef MessageQueue::Id SessionId
 Definition of a session id. More...
 

Public Member Functions

 StreamingServer ()
 Creates a new streaming server. More...
 
 ~StreamingServer () override
 Destructs a streaming server. More...
 
bool setAddress (const Address4 &address)
 Sets the server address. More...
 
bool setPort (const Port &port)
 Sets the server port. More...
 
Address4 address () const
 Returns the server address. More...
 
Port port () const
 Returns the server port. More...
 
bool enable ()
 Enables the streaming server. More...
 
bool disable ()
 Disables the streaming server. More...
 
bool isEnabled () const
 Returns whether the server is enabled. More...
 
ChannelId registerChannel (const std::string &channel, const std::string &dataType, const ChannelCallback &callback)
 Registers a new channel. More...
 
bool changeDataType (const ChannelId channelId, const std::string &dataType)
 Changes the data type of a channel. More...
 
bool unregisterChannel (const ChannelId channelId)
 Unregister a channel. More...
 
bool hasChannel (const std::string &channel) const
 Returns whether this server holds a specified channel. More...
 
void release ()
 Releases all channels. More...
 
bool stream (const ChannelId channelId, const void *data, const size_t size)
 Sets new streaming data for a specified channel. More...
 
size_t channels () const
 Returns the number of registered channels. More...
 
std::string generateUniqueChannel () const
 Returns a generated but unique channel name. More...
 
- Public Member Functions inherited from Ocean::Network::Streaming
const std::string & name () const
 Returns the name of this streaming object. More...
 
const std::string & description () const
 Returns the description of this streaming object. More...
 
double responseTimeout () const
 Returns the timeout value the streaming object waits for response messages. More...
 
virtual bool setName (const std::string &name)
 Sets the name of this streaming object. More...
 
virtual bool setDescription (const std::string &description)
 Sets the description of this streaming object. More...
 
bool setResponseTimeout (const double timeout)
 Sets the timeout value the streaming object waits for response messages. More...
 

Static Public Member Functions

static constexpr ChannelId invalidChannelId ()
 Returns an invalid channel id. More...
 

Protected Types

typedef std::map< ChannelId, ChannelChannelMap
 Definition of a map mapping channel ids to channels. More...
 
typedef std::unordered_map< TCPServer::ConnectionId, ConnectionConnectionMap
 Definition of a map mapping TCP connection ids to server stream connections. More...
 

Protected Member Functions

bool onTCPConnection (const Address4 &address, const Port &port, const TCPServer::ConnectionId connectionId)
 New TCP connection request function. More...
 
void onCommand (const TCPServer::ConnectionId tcpConnectionId, const std::string &command, const std::string &value, const SessionId sessionId)
 New command function. More...
 
void onConnect (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling connect commands. More...
 
void onDisconnect (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling disconnect commands. More...
 
void onClientPort (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling client port commands. More...
 
void onServerPort (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling server port commands. More...
 
void onChannelSelect (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling channel select commands. More...
 
void onStart (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling start commands. More...
 
void onPause (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling pause commands. More...
 
void onStop (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling stop commands. More...
 
void onChannelRequest (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling channel commands. More...
 
void onDataTypeRequest (const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
 Function handling data type commands. More...
 
void onTCPReceive (const TCPServer::ConnectionId tcpConnectionId, const void *data, const size_t size)
 Callback function for TCP receive message. More...
 
- Protected Member Functions inherited from Ocean::Network::Streaming
 Streaming ()
 Creates a new streaming object. More...
 
 Streaming (const Streaming &streaming)=delete
 Disabled copy constructor. More...
 
virtual ~Streaming ()=default
 Destructs an object. More...
 
bool parse (const unsigned char *data, const size_t size, bool &isResponse, std::string &message, std::string &value, SessionId &sessionId)
 Parses a command or a response. More...
 
Streamingoperator= (const Streaming &streaming)=delete
 Disabled copy operator. More...
 

Protected Attributes

bool isEnabled_ = false
 Determines whether the server is enabled. More...
 
TCPServer tcpServer_
 TCP server used for configuration tasks. More...
 
ChannelMap channelMap_
 Registered channels. More...
 
ChannelId channelIdCounter_ = ChannelId(0)
 Channel id counter. More...
 
ConnectionMap connectionMap_
 Map mapping TCP connection ids to subscribed channels. More...
 
Lock lock_
 Server lock. More...
 
- Protected Attributes inherited from Ocean::Network::Streaming
std::string name_
 Name of this streaming object. More...
 
std::string description_
 Description of this streaming object. More...
 
double responseTimeout_ = 2.0
 Timeout value for response messages. More...
 
MessageQueue messageQueue_ = MessageQueue(100)
 Message queue. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from Ocean::Network::Streaming
static const std::string & connectCommand ()
 Definition of a connect command. More...
 
static const std::string & connectResponseP ()
 Definition of a positive connect response. More...
 
static const std::string & connectResponseN ()
 Definition of a negative connect response. More...
 
static const std::string & disconnectCommand ()
 Definition of a disconnect command. More...
 
static const std::string & disconnectResponseP ()
 Definition of a positive disconnect response. More...
 
static const std::string & disconnectResponseN ()
 Definition of a negative disconnect response. More...
 
static const std::string & channelSelectCommand ()
 Definition of a channel select command. More...
 
static const std::string & channelSelectResponseP ()
 Definition of a positive channel select response. More...
 
static const std::string & channelSelectResponseN ()
 Definition of a negative channel select response. More...
 
static const std::string & startCommand ()
 Definition of a start command. More...
 
static const std::string & startResponseP ()
 Definition of a positiv start response. More...
 
static const std::string & startResponseN ()
 Definition fo a negative start response. More...
 
static const std::string & pauseCommand ()
 Definition of a pause command. More...
 
static const std::string & pauseResponseP ()
 Definition of a positive pause response. More...
 
static const std::string & pauseResponseN ()
 Definition of a negative pause response. More...
 
static const std::string & stopCommand ()
 Definition of a stop command. More...
 
static const std::string & stopResponseP ()
 Definition of a positive stop response. More...
 
static const std::string & stopResponseN ()
 Definition of a negative stop response. More...
 
static const std::string & clientPortCommand ()
 Definition of a client port command. More...
 
static const std::string & clientPortResponseP ()
 Definition of a positive client port response. More...
 
static const std::string & clientPortResponseN ()
 Definition of a negative client port response. More...
 
static const std::string & serverPortCommand ()
 Definition of a server port command. More...
 
static const std::string & serverPortResponseP ()
 Definition of a positive server port response. More...
 
static const std::string & serverPortResponseN ()
 Definition of a negative server port response. More...
 
static const std::string & channelRequestCommand ()
 Definition of a channel request command. More...
 
static const std::string & channelRequestResponseP ()
 Definition of a positive channel request response. More...
 
static const std::string & channelRequestResponseN ()
 Definition of a negative channel request response. More...
 
static const std::string & changedDataTypeCommand ()
 Definition of a changed data type command. More...
 
static const std::string & changedDataTypeResponseP ()
 Definition of a positive changed data type request. More...
 
static const std::string & changedDataTypeResponseN ()
 Definition of a negative change data type request. More...
 
static const std::string & dataTypeRequestCommand ()
 Definition of a data type request command. More...
 
static const std::string & dataTypeRequestResponseP ()
 Definition of a positive data type request response. More...
 
static const std::string & dataTypeRequestResponseN ()
 Definition of a negative data type request response. More...
 
static std::string createCommand (const std::string &command, const SessionId sessionId)
 Creates a new command message. More...
 
static std::string createCommand (const std::string &command, const std::string &value, const SessionId sessionId)
 Creates a new command message with a value. More...
 
static std::string createResponse (const std::string &response, const SessionId sessionId)
 Creates a new response message. More...
 
static std::string createResponse (const std::string &response, const std::string &value, const SessionId sessionId)
 Creates a new response message with a value. More...
 

Detailed Description

This class implements a streaming server.

Member Typedef Documentation

◆ ChannelCallback

Definition of a callback function on channel start, stop or pause requests.

◆ ChannelId

Definition of a channel id.

◆ ChannelMap

Definition of a map mapping channel ids to channels.

◆ ConnectionMap

Definition of a map mapping TCP connection ids to server stream connections.

Constructor & Destructor Documentation

◆ StreamingServer()

Ocean::Network::StreamingServer::StreamingServer ( )

Creates a new streaming server.

◆ ~StreamingServer()

Ocean::Network::StreamingServer::~StreamingServer ( )
override

Destructs a streaming server.

Member Function Documentation

◆ address()

Address4 Ocean::Network::StreamingServer::address ( ) const

Returns the server address.

Returns
Server address

◆ changeDataType()

bool Ocean::Network::StreamingServer::changeDataType ( const ChannelId  channelId,
const std::string &  dataType 
)

Changes the data type of a channel.

Parameters
channelIdSessionId of the channel to change the data type for
dataTypeNew data type to set
Returns
True, if succeeded

◆ channels()

size_t Ocean::Network::StreamingServer::channels ( ) const
inline

Returns the number of registered channels.

Returns
Channels

◆ disable()

bool Ocean::Network::StreamingServer::disable ( )

Disables the streaming server.

Returns
True, if succeeded

◆ enable()

bool Ocean::Network::StreamingServer::enable ( )

Enables the streaming server.

Returns
True, if succeeded

◆ generateUniqueChannel()

std::string Ocean::Network::StreamingServer::generateUniqueChannel ( ) const

Returns a generated but unique channel name.

Returns
Unique channel name

◆ hasChannel()

bool Ocean::Network::StreamingServer::hasChannel ( const std::string &  channel) const

Returns whether this server holds a specified channel.

Returns
True, if the channel exists already

◆ invalidChannelId()

constexpr StreamingServer::ChannelId Ocean::Network::StreamingServer::invalidChannelId ( )
staticconstexpr

Returns an invalid channel id.

Returns
Invalid channel id

◆ isEnabled()

bool Ocean::Network::StreamingServer::isEnabled ( ) const
inline

Returns whether the server is enabled.

Returns
True, if so

◆ onChannelRequest()

void Ocean::Network::StreamingServer::onChannelRequest ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling channel commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onChannelSelect()

void Ocean::Network::StreamingServer::onChannelSelect ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling channel select commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onClientPort()

void Ocean::Network::StreamingServer::onClientPort ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling client port commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onCommand()

void Ocean::Network::StreamingServer::onCommand ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  command,
const std::string &  value,
const SessionId  sessionId 
)
protected

New command function.

Parameters
tcpConnectionIdTCP server connection id
commandNew command to handle
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onConnect()

void Ocean::Network::StreamingServer::onConnect ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling connect commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onDataTypeRequest()

void Ocean::Network::StreamingServer::onDataTypeRequest ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling data type commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onDisconnect()

void Ocean::Network::StreamingServer::onDisconnect ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling disconnect commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onPause()

void Ocean::Network::StreamingServer::onPause ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling pause commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onServerPort()

void Ocean::Network::StreamingServer::onServerPort ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling server port commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onStart()

void Ocean::Network::StreamingServer::onStart ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling start commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onStop()

void Ocean::Network::StreamingServer::onStop ( const TCPServer::ConnectionId  tcpConnectionId,
const std::string &  value,
const SessionId  sessionId 
)
protected

Function handling stop commands.

Parameters
tcpConnectionIdTCP server connection id
valueCommand value
sessionIdUnique id of the server which is not unique on the client side

◆ onTCPConnection()

bool Ocean::Network::StreamingServer::onTCPConnection ( const Address4 address,
const Port port,
const TCPServer::ConnectionId  connectionId 
)
protected

New TCP connection request function.

Parameters
addressSender address
portSender port
connectionIdTCP server specific connection id

◆ onTCPReceive()

void Ocean::Network::StreamingServer::onTCPReceive ( const TCPServer::ConnectionId  tcpConnectionId,
const void *  data,
const size_t  size 
)
protected

Callback function for TCP receive message.

Parameters
tcpConnectionIdTCP server connection id
dataReceived data
sizeThe size of the received data

◆ port()

Port Ocean::Network::StreamingServer::port ( ) const

Returns the server port.

Returns
Server port

◆ registerChannel()

ChannelId Ocean::Network::StreamingServer::registerChannel ( const std::string &  channel,
const std::string &  dataType,
const ChannelCallback callback 
)

Registers a new channel.

Parameters
channelUnique name of the new channel to register
dataTypeData type provides by the channel
callbackChannel request callback
Returns
Valid channel id if succeeded

◆ release()

void Ocean::Network::StreamingServer::release ( )

Releases all channels.

◆ setAddress()

bool Ocean::Network::StreamingServer::setAddress ( const Address4 address)

Sets the server address.

If the systems supports more than one network address use this function to define which address to use for this server.
However, normally is not necessary to define the local address.

Parameters
addressAddress to use for this streaming server
Returns
True, if succeeded

◆ setPort()

bool Ocean::Network::StreamingServer::setPort ( const Port port)

Sets the server port.

Parameters
portServer port to set
Returns
True, if succeeded

◆ stream()

bool Ocean::Network::StreamingServer::stream ( const ChannelId  channelId,
const void *  data,
const size_t  size 
)

Sets new streaming data for a specified channel.

Parameters
channelIdSessionId of the streaming channel
dataStreaming data
sizeStreaming data size in bytes
Returns
True, if the data was accepted

◆ unregisterChannel()

bool Ocean::Network::StreamingServer::unregisterChannel ( const ChannelId  channelId)

Unregister a channel.

Parameters
channelIdSessionId of the channel to unregister
Returns
True, if succeeded

Field Documentation

◆ channelIdCounter_

ChannelId Ocean::Network::StreamingServer::channelIdCounter_ = ChannelId(0)
protected

Channel id counter.

◆ channelMap_

ChannelMap Ocean::Network::StreamingServer::channelMap_
protected

Registered channels.

◆ connectionMap_

ConnectionMap Ocean::Network::StreamingServer::connectionMap_
protected

Map mapping TCP connection ids to subscribed channels.

◆ isEnabled_

bool Ocean::Network::StreamingServer::isEnabled_ = false
protected

Determines whether the server is enabled.

◆ lock_

Lock Ocean::Network::StreamingServer::lock_
mutableprotected

Server lock.

◆ tcpServer_

TCPServer Ocean::Network::StreamingServer::tcpServer_
protected

TCP server used for configuration tasks.


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