Ocean
StreamingServer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef FACEBOOK_NETWORK_STREAMING_SERVER_H
9 #define FACEBOOK_NETWORK_STREAMING_SERVER_H
10 
11 #include "ocean/network/Network.h"
12 #include "ocean/network/Port.h"
16 
17 #include "ocean/base/Callback.h"
18 #include "ocean/base/Lock.h"
19 
20 namespace Ocean
21 {
22 
23 namespace Network
24 {
25 
26 /**
27  * This class implements a streaming server.
28  * @ingroup network
29  */
30 class OCEAN_NETWORK_EXPORT StreamingServer : public Streaming
31 {
32  public:
33 
34  /**
35  * Definition of a callback function on channel start, stop or pause requests.
36  */
38 
39  /**
40  * Definition of a channel id.
41  */
42  typedef unsigned int ChannelId;
43 
44  /**
45  * Returns an invalid channel id.
46  * @return Invalid channel id
47  */
48  static constexpr ChannelId invalidChannelId();
49 
50  protected:
51 
52  /**
53  * This class implements a channel.
54  */
55  class Channel
56  {
57  public:
58 
59  /**
60  * Definition of a stream id.
61  */
62  typedef unsigned int StreamId;
63 
64  /**
65  * Returns an invalid stream id.
66  * @return Invalid stream id
67  */
68  static constexpr StreamId invalidStreamId();
69 
70  public:
71 
72  /**
73  * This class implements a stream.
74  */
75  class Stream
76  {
77  public:
78 
79  /**
80  * Creates a new stream object.<br>
81  * A stream is in stopped mode by default.
82  * @param tcpConnectionId The id of the TCP configuration
83  * @param receiverAddress Address4 of the stream receiver
84  * @param receiverPort Port of the stream receiver
85  */
86  Stream(const TCPServer::ConnectionId tcpConnectionId, const Address4& receiverAddress, const Port& receiverPort);
87 
88  /**
89  * (Re-)Starts the stream.
90  * @return True, if succeeded
91  */
92  bool start();
93 
94  /**
95  * Pauses the stream.
96  * @return True, if succeeded
97  */
98  bool pause();
99 
100  /**
101  * Returns whether this stream is currently streaming.
102  * @return True, if so
103  */
104  inline bool isStreaming() const;
105 
106  /**
107  * Returns the id of the TCP configuration connection associated with this stream.
108  * @return Configuration connection
109  */
110  inline TCPServer::ConnectionId tcpConnectionId() const;
111 
112  /**
113  * Returns the address of the used sender UDP client.
114  * @return Sender address
115  */
116  inline Address4 senderAddress() const;
117 
118  /**
119  * Returns the port the used sender UDP client.
120  * @return Sender port
121  */
122  inline Port senderPort() const;
123 
124  /**
125  * Returns the address of the receiver.
126  * @return Receiver address
127  */
128  inline const Address4& receiverAddress() const;
129 
130  /**
131  * Returns the port of the receiver.
132  * @return Receiver port
133  */
134  inline const Port& receiverPort() const;
135 
136  /**
137  * Streams new data using the given UDP connections.
138  * @param data The data to stream
139  * @param size The size of the data to stream in bytes
140  * @return True, if succeeded
141  */
142  bool stream(const void* data, const size_t size);
143 
144  protected:
145 
146  /**
147  * Disabled copy constructor.
148  * @param stream Object which would be copied
149  */
150  Stream(const Stream& stream) = delete;
151 
152  /**
153  * Disabled copy operator.
154  * @param stream Object which would be copied
155  * @return Reference to this object
156  */
157  Stream& operator=(const Stream& stream) = delete;
158 
159  protected:
160 
161  /// The id of the TCP configuration connection.
163 
164  /// UDP client used for stream data transfer.
166 
167  /// Stream receiver address.
169 
170  /// Stream receiver port.
172 
173  /// Determines whether data should be streamed.
174  bool isStreaming_ = false;
175  };
176 
177  /**
178  * Definition of a map mapping stream ids to streams.
179  */
180  typedef std::map<StreamId, std::shared_ptr<Stream>> StreamMap;
181 
182  public:
183 
184  /**
185  * Creates a new default channel.
186  */
187  Channel() = default;
188 
189  /**
190  * Creates a new channel.
191  * @param name Unique channel name
192  * @param dataType Data type of the channel
193  * @param callback Channel callback function.
194  */
195  Channel(const std::string& name, const std::string& dataType, const ChannelCallback& callback);
196 
197  /**
198  * Adds a new stream to this channel.
199  * @param tcpConnectionId The id of the TCP configuration connection
200  * @param address Address4 of the stream receiver
201  * @param port Port of the stream receiver
202  * @return A valid stream id, if succeeded
203  */
204  StreamId addStream(const TCPServer::ConnectionId tcpConnectionId, const Address4& address, const Port& port);
205 
206  /**
207  * Removes a stream from this channel.
208  * @param streamId Id of the stream to remove
209  * @return True, if the stream existed
210  */
211  bool removeStream(const StreamId streamId);
212 
213  /**
214  * (Re-)starts a stream of this channel.
215  * @param streamId Id of the stream to start
216  * @return True, if succeeded
217  */
218  bool startStream(const StreamId streamId);
219 
220  /**
221  * Pauses a stream.
222  * @param streamId Id of the stream to pause
223  * @return True, if succeeded
224  */
225  bool pauseStream(const StreamId streamId);
226 
227  /**
228  * Stops and removes a stream of this channel.
229  * @param streamId Id of the stream to stop
230  * @return True, if succeeded
231  */
232  bool stopStream(const StreamId streamId);
233 
234  /**
235  * Returns the name of this channel.
236  * @return Unique channel name
237  */
238  inline const std::string& name() const;
239 
240  /**
241  * Returns the data type of this channel.
242  * @return Channel data type
243  */
244  inline const std::string& dataType() const;
245 
246  /**
247  * Returns the UDP client sender port of a given stream.
248  * @param streamId Id of the stream to return the UDP sender port for
249  * @return UDP server sender port
250  */
251  Port streamSenderPort(const StreamId streamId) const;
252 
253  /**
254  * Sets or changes the data type of this channel.
255  * @param configurationTCPServer TCP server of the streaming server used for stream configurations
256  * @param messageQueue Message queue of the streaming server used for message identification
257  * @param dataType New data type to set
258  * @return True, if succeeded
259  */
260  bool setDataType(TCPServer& configurationTCPServer, MessageQueue& messageQueue, const std::string& dataType);
261 
262  /**
263  * Streams new data using the given UDP connections.
264  * @param data Data to stream
265  * @param size Size of the data to stream in bytes
266  * @return True, if succeeded
267  */
268  bool stream(const void* data, const size_t size);
269 
270  protected:
271 
272  /// Unique Channel name.
273  std::string name_;
274 
275  /// Data type of the channel.
276  std::string dataType_;
277 
278  /// Determines the number of active streaming streams.
279  unsigned int activeStreams_ = 0u;
280 
281  /// Streams used for this channel.
283 
284  /// Stream id counter.
285  StreamId streamIdCounter_ = StreamId(0);
286 
287  /// Channel request callback function.
289  };
290 
291  /**
292  * Definition of a map mapping channel ids to channels.
293  */
294  typedef std::map<ChannelId, Channel> ChannelMap;
295 
296  /**
297  * This class holds some information connected with a TCP connection.
298  * @ingroup network
299  */
301  {
302  public:
303 
304  /**
305  * Creates an empty connection object.
306  */
307  inline Connection() = default;
308 
309  /**
310  * Creates a new connection object.
311  * @param receiver The receiver address of the stream data
312  */
313  inline Connection(const Address4& receiver);
314 
315  /**
316  * Returns the channel id.
317  * @return Channel id
318  */
319  inline ChannelId channelId() const;
320 
321  /**
322  * Returns the stream id inside the channel.
323  * @return Channel stream id
324  */
325  inline Channel::StreamId channelStreamId() const;
326 
327  /**
328  * Returns the stream receiver address of this connection.
329  * @return Receiver address
330  */
331  inline const Address4& address() const;
332 
333  /**
334  * Returns the stream receiver port of this connection.
335  * @return Receiver port
336  */
337  inline const Port& port() const;
338 
339  /**
340  * Sets the channel id of this connection.
341  * @param channelId Channel id to set
342  * @return True, if succeeded
343  */
344  inline bool setChannelId(const ChannelId channelId);
345 
346  /**
347  * Sets the channel stream id of this connection.
348  * @param streamId Stream id to set
349  * @return True, if succeeded
350  */
351  inline bool setChannelStreamId(const Channel::StreamId streamId);
352 
353  /**
354  * Sets the port of the stream data.
355  * @param port Port to set
356  * @return True, if succeeded
357  */
358  inline bool setPort(const Port& port);
359 
360  private:
361 
362  /// Id of the channel.
363  ChannelId channelId_ = invalidChannelId();
364 
365  /// Id of the stream.
366  Channel::StreamId channelStreamId_ = Channel::invalidStreamId();
367 
368  /// Receiver address of the streaming data.
370 
371  /// Receiver port of the streaming data.
373  };
374 
375  /**
376  * Definition of a map mapping TCP connection ids to server stream connections.
377  */
378  typedef std::unordered_map<TCPServer::ConnectionId, Connection> ConnectionMap;
379 
380  public:
381 
382  /**
383  * Creates a new streaming server.
384  */
386 
387  /**
388  * Destructs a streaming server.
389  */
390  ~StreamingServer() override;
391 
392  /**
393  * Sets the server address.
394  * If the systems supports more than one network address use this function to define which address to use for this server.<br>
395  * However, normally is not necessary to define the local address.
396  * @param address Address to use for this streaming server
397  * @return True, if succeeded
398  */
399  bool setAddress(const Address4& address);
400 
401  /**
402  * Sets the server port.
403  * @param port Server port to set
404  * @return True, if succeeded
405  */
406  bool setPort(const Port& port);
407 
408  /**
409  * Returns the server address.
410  * @return Server address
411  */
412  Address4 address() const;
413 
414  /**
415  * Returns the server port.
416  * @return Server port
417  */
418  Port port() const;
419 
420  /**
421  * Enables the streaming server.
422  * @return True, if succeeded
423  */
424  bool enable();
425 
426  /**
427  * Disables the streaming server.
428  * @return True, if succeeded
429  */
430  bool disable();
431 
432  /**
433  * Returns whether the server is enabled.
434  * @return True, if so
435  */
436  inline bool isEnabled() const;
437 
438  /**
439  * Registers a new channel.
440  * @param channel Unique name of the new channel to register
441  * @param dataType Data type provides by the channel
442  * @param callback Channel request callback
443  * @return Valid channel id if succeeded
444  */
445  ChannelId registerChannel(const std::string& channel, const std::string& dataType, const ChannelCallback& callback);
446 
447  /**
448  * Changes the data type of a channel.
449  * @param channelId SessionId of the channel to change the data type for
450  * @param dataType New data type to set
451  * @return True, if succeeded
452  */
453  bool changeDataType(const ChannelId channelId, const std::string& dataType);
454 
455  /**
456  * Unregister a channel.
457  * @param channelId SessionId of the channel to unregister
458  * @return True, if succeeded
459  */
460  bool unregisterChannel(const ChannelId channelId);
461 
462  /**
463  * Returns whether this server holds a specified channel.
464  * @return True, if the channel exists already
465  */
466  bool hasChannel(const std::string& channel) const;
467 
468  /**
469  * Releases all channels.
470  */
471  void release();
472 
473  /**
474  * Sets new streaming data for a specified channel.
475  * @param channelId SessionId of the streaming channel
476  * @param data Streaming data
477  * @param size Streaming data size in bytes
478  * @return True, if the data was accepted
479  */
480  bool stream(const ChannelId channelId, const void* data, const size_t size);
481 
482  /**
483  * Returns the number of registered channels.
484  * @return Channels
485  */
486  inline size_t channels() const;
487 
488  /**
489  * Returns a generated but unique channel name.
490  * @return Unique channel name
491  */
492  std::string generateUniqueChannel() const;
493 
494  protected:
495 
496  /**
497  * New TCP connection request function.
498  * @param address Sender address
499  * @param port Sender port
500  * @param connectionId TCP server specific connection id
501  */
502  bool onTCPConnection(const Address4& address, const Port& port, const TCPServer::ConnectionId connectionId);
503 
504  /**
505  * New command function.
506  * @param tcpConnectionId TCP server connection id
507  * @param command New command to handle
508  * @param value Command value
509  * @param sessionId Unique id of the server which is not unique on the client side
510  */
511  void onCommand(const TCPServer::ConnectionId tcpConnectionId, const std::string& command, const std::string& value, const SessionId sessionId);
512 
513  /**
514  * Function handling connect commands.
515  * @param tcpConnectionId TCP server connection id
516  * @param value Command value
517  * @param sessionId Unique id of the server which is not unique on the client side
518  */
519  void onConnect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
520 
521  /**
522  * Function handling disconnect commands.
523  * @param tcpConnectionId TCP server connection id
524  * @param value Command value
525  * @param sessionId Unique id of the server which is not unique on the client side
526  */
527  void onDisconnect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
528 
529  /**
530  * Function handling client port commands.
531  * @param tcpConnectionId TCP server connection id
532  * @param value Command value
533  * @param sessionId Unique id of the server which is not unique on the client side
534  */
535  void onClientPort(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
536 
537  /**
538  * Function handling server port commands.
539  * @param tcpConnectionId TCP server connection id
540  * @param value Command value
541  * @param sessionId Unique id of the server which is not unique on the client side
542  */
543  void onServerPort(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
544 
545  /**
546  * Function handling channel select commands.
547  * @param tcpConnectionId TCP server connection id
548  * @param value Command value
549  * @param sessionId Unique id of the server which is not unique on the client side
550  */
551  void onChannelSelect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
552 
553  /**
554  * Function handling start commands.
555  * @param tcpConnectionId TCP server connection id
556  * @param value Command value
557  * @param sessionId Unique id of the server which is not unique on the client side
558  */
559  void onStart(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
560 
561  /**
562  * Function handling pause commands.
563  * @param tcpConnectionId TCP server connection id
564  * @param value Command value
565  * @param sessionId Unique id of the server which is not unique on the client side
566  */
567  void onPause(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
568 
569  /**
570  * Function handling stop commands.
571  * @param tcpConnectionId TCP server connection id
572  * @param value Command value
573  * @param sessionId Unique id of the server which is not unique on the client side
574  */
575  void onStop(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
576 
577  /**
578  * Function handling channel commands.
579  * @param tcpConnectionId TCP server connection id
580  * @param value Command value
581  * @param sessionId Unique id of the server which is not unique on the client side
582  */
583  void onChannelRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
584 
585  /**
586  * Function handling data type commands.
587  * @param tcpConnectionId TCP server connection id
588  * @param value Command value
589  * @param sessionId Unique id of the server which is not unique on the client side
590  */
591  void onDataTypeRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
592 
593  /**
594  * Callback function for TCP receive message.
595  * @param tcpConnectionId TCP server connection id
596  * @param data Received data
597  * @param size The size of the received data
598  */
599  void onTCPReceive(const TCPServer::ConnectionId tcpConnectionId, const void* data, const size_t size);
600 
601  protected:
602 
603  /// Determines whether the server is enabled.
604  bool isEnabled_ = false;
605 
606  /// TCP server used for configuration tasks.
608 
609  /// Registered channels.
611 
612  /// Channel id counter.
613  ChannelId channelIdCounter_ = ChannelId(0);
614 
615  /// Map mapping TCP connection ids to subscribed channels.
617 
618  /// Server lock.
619  mutable Lock lock_;
620 };
621 
623 {
624  return ChannelId(-1);
625 }
626 
628 {
629  return StreamId(-1);
630 }
631 
633 {
634  return isStreaming_;
635 }
636 
638 {
639  return tcpConnectionId_;
640 }
641 
643 {
644  return udpClient_.address();
645 }
646 
648 {
649  return udpClient_.port();
650 }
651 
653 {
654  return address_;
655 }
656 
658 {
659  return port_;
660 }
661 
662 inline const std::string& StreamingServer::Channel::name() const
663 {
664  return name_;
665 }
666 
667 inline const std::string& StreamingServer::Channel::dataType() const
668 {
669  return dataType_;
670 }
671 
673  address_(receiver)
674 {
675  // nothing to do here
676 }
677 
679 {
680  return channelId_;
681 }
682 
684 {
685  return channelStreamId_;
686 }
687 
689 {
690  return address_;
691 }
692 
694 {
695  return port_;
696 }
697 
699 {
700  if (channelId_ != invalidChannelId())
701  {
702  return false;
703  }
704 
705  channelId_ = channelId;
706  return true;
707 }
708 
710 {
711  if (channelStreamId_ != Channel::invalidStreamId())
712  {
713  return false;
714  }
715 
716  channelStreamId_ = streamId;
717  return true;
718 }
719 
721 {
722  if (port_.isNull() == false || port.isNull())
723  {
724  return false;
725  }
726 
727  port_ = port;
728  return true;
729 }
730 
731 inline bool StreamingServer::isEnabled() const
732 {
733  return isEnabled_;
734 }
735 
736 inline size_t StreamingServer::channels() const
737 {
738  const ScopedLock scopedLock(lock_);
739 
740  return channelMap_.size();
741 }
742 
743 }
744 
745 }
746 
747 #endif // FACEBOOK_NETWORK_STREAMING_SERVER_H
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
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
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