8 #ifndef FACEBOOK_NETWORK_STREAMING_SERVER_H
9 #define FACEBOOK_NETWORK_STREAMING_SERVER_H
48 static constexpr
ChannelId invalidChannelId();
68 static constexpr
StreamId invalidStreamId();
104 inline bool isStreaming()
const;
116 inline Address4 senderAddress()
const;
122 inline Port senderPort()
const;
128 inline const Address4& receiverAddress()
const;
134 inline const Port& receiverPort()
const;
142 bool stream(
const void* data,
const size_t size);
174 bool isStreaming_ =
false;
180 typedef std::map<StreamId, std::shared_ptr<Stream>>
StreamMap;
238 inline const std::string& name()
const;
244 inline const std::string& dataType()
const;
268 bool stream(
const void* data,
const size_t size);
279 unsigned int activeStreams_ = 0u;
331 inline const Address4& address()
const;
337 inline const Port& port()
const;
344 inline bool setChannelId(
const ChannelId channelId);
358 inline bool setPort(
const Port& port);
378 typedef std::unordered_map<TCPServer::ConnectionId, Connection>
ConnectionMap;
436 inline bool isEnabled()
const;
486 inline size_t channels()
const;
604 bool isEnabled_ =
false;
639 return tcpConnectionId_;
644 return udpClient_.address();
649 return udpClient_.port();
685 return channelStreamId_;
705 channelId_ = channelId;
716 channelStreamId_ = streamId;
This class implements a recursive lock object.
Definition: Lock.h:31
This class wraps an address number with 32 bits.
Definition: Address4.h:26
unsigned int ConnectionId
Definition of a connection id.
Definition: ConnectionOrientedServer.h:34
static constexpr ConnectionId invalidConnectionId()
Returns an invalid connection id.
Definition: ConnectionOrientedServer.h:231
This class implements a message queue.
Definition: MessageQueue.h:29
This class implements a UDP client able to send larger messages as normally restricted by the UDP pro...
Definition: PackagedUDPClient.h:25
This class wraps a port number with 16 bits.
Definition: Port.h:26
bool isNull() const
Returns whether this port holds a zero value.
Definition: Port.h:136
This class is the base class for all streaming objects.
Definition: Streaming.h:25
std::string name_
Name of this streaming object.
Definition: Streaming.h:241
MessageQueue::Id SessionId
Definition of a session id.
Definition: Streaming.h:46
This class implements a stream.
Definition: StreamingServer.h:76
Stream(const Stream &stream)=delete
Disabled copy constructor.
bool stream(const void *data, const size_t size)
Streams new data using the given UDP connections.
Port port_
Stream receiver port.
Definition: StreamingServer.h:171
Port senderPort() const
Returns the port the used sender UDP client.
Definition: StreamingServer.h:647
bool isStreaming() const
Returns whether this stream is currently streaming.
Definition: StreamingServer.h:632
const Address4 & receiverAddress() const
Returns the address of the receiver.
Definition: StreamingServer.h:652
const Port & receiverPort() const
Returns the port of the receiver.
Definition: StreamingServer.h:657
TCPServer::ConnectionId tcpConnectionId() const
Returns the id of the TCP configuration connection associated with this stream.
Definition: StreamingServer.h:637
bool pause()
Pauses the stream.
Stream & operator=(const Stream &stream)=delete
Disabled copy operator.
Address4 address_
Stream receiver address.
Definition: StreamingServer.h:168
Stream(const TCPServer::ConnectionId tcpConnectionId, const Address4 &receiverAddress, const Port &receiverPort)
Creates a new stream object.
Address4 senderAddress() const
Returns the address of the used sender UDP client.
Definition: StreamingServer.h:642
bool start()
(Re-)Starts the stream.
PackagedUDPClient udpClient_
UDP client used for stream data transfer.
Definition: StreamingServer.h:165
This class implements a channel.
Definition: StreamingServer.h:56
Channel()=default
Creates a new default channel.
StreamId addStream(const TCPServer::ConnectionId tcpConnectionId, const Address4 &address, const Port &port)
Adds a new stream to this channel.
bool startStream(const StreamId streamId)
(Re-)starts a stream of this channel.
bool removeStream(const StreamId streamId)
Removes a stream from this channel.
unsigned int StreamId
Definition of a stream id.
Definition: StreamingServer.h:62
bool stream(const void *data, const size_t size)
Streams new data using the given UDP connections.
const std::string & dataType() const
Returns the data type of this channel.
Definition: StreamingServer.h:667
ChannelCallback channelCallback_
Channel request callback function.
Definition: StreamingServer.h:288
static constexpr StreamId invalidStreamId()
Returns an invalid stream id.
Definition: StreamingServer.h:627
std::string name_
Unique Channel name.
Definition: StreamingServer.h:273
Channel(const std::string &name, const std::string &dataType, const ChannelCallback &callback)
Creates a new channel.
bool pauseStream(const StreamId streamId)
Pauses a stream.
const std::string & name() const
Returns the name of this channel.
Definition: StreamingServer.h:662
bool stopStream(const StreamId streamId)
Stops and removes a stream of this channel.
StreamMap streamMap_
Streams used for this channel.
Definition: StreamingServer.h:282
Port streamSenderPort(const StreamId streamId) const
Returns the UDP client sender port of a given stream.
std::string dataType_
Data type of the channel.
Definition: StreamingServer.h:276
bool setDataType(TCPServer &configurationTCPServer, MessageQueue &messageQueue, const std::string &dataType)
Sets or changes the data type of this channel.
std::map< StreamId, std::shared_ptr< Stream > > StreamMap
Definition of a map mapping stream ids to streams.
Definition: StreamingServer.h:180
This class holds some information connected with a TCP connection.
Definition: StreamingServer.h:301
ChannelId channelId() const
Returns the channel id.
Definition: StreamingServer.h:678
bool setPort(const Port &port)
Sets the port of the stream data.
Definition: StreamingServer.h:720
bool setChannelStreamId(const Channel::StreamId streamId)
Sets the channel stream id of this connection.
Definition: StreamingServer.h:709
Address4 address_
Receiver address of the streaming data.
Definition: StreamingServer.h:369
Connection()=default
Creates an empty connection object.
Port port_
Receiver port of the streaming data.
Definition: StreamingServer.h:372
const Port & port() const
Returns the stream receiver port of this connection.
Definition: StreamingServer.h:693
Channel::StreamId channelStreamId() const
Returns the stream id inside the channel.
Definition: StreamingServer.h:683
bool setChannelId(const ChannelId channelId)
Sets the channel id of this connection.
Definition: StreamingServer.h:698
const Address4 & address() const
Returns the stream receiver address of this connection.
Definition: StreamingServer.h:688
This class implements a streaming server.
Definition: StreamingServer.h:31
std::map< ChannelId, Channel > ChannelMap
Definition of a map mapping channel ids to channels.
Definition: StreamingServer.h:294
static constexpr ChannelId invalidChannelId()
Returns an invalid channel id.
Definition: StreamingServer.h:622
bool disable()
Disables the streaming server.
void onClientPort(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling client port commands.
ChannelId registerChannel(const std::string &channel, const std::string &dataType, const ChannelCallback &callback)
Registers a new channel.
void onTCPReceive(const TCPServer::ConnectionId tcpConnectionId, const void *data, const size_t size)
Callback function for TCP receive message.
void onStart(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling start commands.
bool setPort(const Port &port)
Sets the server port.
Lock lock_
Server lock.
Definition: StreamingServer.h:619
TCPServer tcpServer_
TCP server used for configuration tasks.
Definition: StreamingServer.h:607
ConnectionMap connectionMap_
Map mapping TCP connection ids to subscribed channels.
Definition: StreamingServer.h:616
void release()
Releases all channels.
~StreamingServer() override
Destructs a streaming server.
void onCommand(const TCPServer::ConnectionId tcpConnectionId, const std::string &command, const std::string &value, const SessionId sessionId)
New command function.
void onConnect(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling connect commands.
ChannelMap channelMap_
Registered channels.
Definition: StreamingServer.h:610
void onChannelRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling channel commands.
bool isEnabled_
Determines whether the server is enabled.
Definition: StreamingServer.h:604
Port port() const
Returns the server port.
void onServerPort(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling server port commands.
bool hasChannel(const std::string &channel) const
Returns whether this server holds a specified channel.
unsigned int ChannelId
Definition of a channel id.
Definition: StreamingServer.h:42
bool setAddress(const Address4 &address)
Sets the server address.
bool stream(const ChannelId channelId, const void *data, const size_t size)
Sets new streaming data for a specified channel.
std::string generateUniqueChannel() const
Returns a generated but unique channel name.
Callback< void, const State > ChannelCallback
Definition of a callback function on channel start, stop or pause requests.
Definition: StreamingServer.h:37
bool unregisterChannel(const ChannelId channelId)
Unregister a channel.
void onDataTypeRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling data type commands.
Address4 address() const
Returns the server address.
StreamingServer()
Creates a new streaming server.
void onStop(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling stop commands.
bool isEnabled() const
Returns whether the server is enabled.
Definition: StreamingServer.h:731
bool enable()
Enables the streaming server.
void onDisconnect(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling disconnect commands.
std::unordered_map< TCPServer::ConnectionId, Connection > ConnectionMap
Definition of a map mapping TCP connection ids to server stream connections.
Definition: StreamingServer.h:378
void onChannelSelect(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling channel select commands.
bool changeDataType(const ChannelId channelId, const std::string &dataType)
Changes the data type of a channel.
size_t channels() const
Returns the number of registered channels.
Definition: StreamingServer.h:736
bool onTCPConnection(const Address4 &address, const Port &port, const TCPServer::ConnectionId connectionId)
New TCP connection request function.
void onPause(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling pause commands.
This class implements a TCP server.
Definition: TCPServer.h:25
This class implements a scoped lock object for recursive lock objects.
Definition: Lock.h:135
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15