Ocean
|
This class implements a streaming server. More...
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 State > | ChannelCallback |
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, Channel > | ChannelMap |
Definition of a map mapping channel ids to channels. More... | |
typedef std::unordered_map< TCPServer::ConnectionId, Connection > | ConnectionMap |
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... | |
Streaming & | operator= (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... | |
This class implements a streaming server.
typedef Callback<void, const State> Ocean::Network::StreamingServer::ChannelCallback |
Definition of a callback function on channel start, stop or pause requests.
typedef unsigned int Ocean::Network::StreamingServer::ChannelId |
Definition of a channel id.
|
protected |
Definition of a map mapping channel ids to channels.
|
protected |
Definition of a map mapping TCP connection ids to server stream connections.
Ocean::Network::StreamingServer::StreamingServer | ( | ) |
Creates a new streaming server.
|
override |
Destructs a streaming server.
Address4 Ocean::Network::StreamingServer::address | ( | ) | const |
Returns the server address.
bool Ocean::Network::StreamingServer::changeDataType | ( | const ChannelId | channelId, |
const std::string & | dataType | ||
) |
Changes the data type of a channel.
channelId | SessionId of the channel to change the data type for |
dataType | New data type to set |
|
inline |
Returns the number of registered channels.
bool Ocean::Network::StreamingServer::disable | ( | ) |
Disables the streaming server.
bool Ocean::Network::StreamingServer::enable | ( | ) |
Enables the streaming server.
std::string Ocean::Network::StreamingServer::generateUniqueChannel | ( | ) | const |
Returns a generated but unique channel name.
bool Ocean::Network::StreamingServer::hasChannel | ( | const std::string & | channel | ) | const |
Returns whether this server holds a specified channel.
|
staticconstexpr |
Returns an invalid channel id.
|
inline |
Returns whether the server is enabled.
|
protected |
Function handling channel commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling channel select commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling client port commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
New command function.
tcpConnectionId | TCP server connection id |
command | New command to handle |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling connect commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling data type commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling disconnect commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling pause commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling server port commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling start commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
Function handling stop commands.
tcpConnectionId | TCP server connection id |
value | Command value |
sessionId | Unique id of the server which is not unique on the client side |
|
protected |
New TCP connection request function.
address | Sender address |
port | Sender port |
connectionId | TCP server specific connection id |
|
protected |
Callback function for TCP receive message.
tcpConnectionId | TCP server connection id |
data | Received data |
size | The size of the received data |
ChannelId Ocean::Network::StreamingServer::registerChannel | ( | const std::string & | channel, |
const std::string & | dataType, | ||
const ChannelCallback & | callback | ||
) |
void Ocean::Network::StreamingServer::release | ( | ) |
Releases all channels.
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.
address | Address to use for this streaming server |
bool Ocean::Network::StreamingServer::setPort | ( | const Port & | port | ) |
bool Ocean::Network::StreamingServer::stream | ( | const ChannelId | channelId, |
const void * | data, | ||
const size_t | size | ||
) |
bool Ocean::Network::StreamingServer::unregisterChannel | ( | const ChannelId | channelId | ) |
Unregister a channel.
channelId | SessionId of the channel to unregister |
Channel id counter.
|
protected |
Registered channels.
|
protected |
Map mapping TCP connection ids to subscribed channels.
|
protected |
Determines whether the server is enabled.
|
protected |
TCP server used for configuration tasks.