Ocean
Loading...
Searching...
No Matches
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
12#include "ocean/network/Port.h"
16
17#include "ocean/base/Callback.h"
18#include "ocean/base/Lock.h"
19
20namespace Ocean
21{
22
23namespace Network
24{
25
26/**
27 * This class implements a streaming server.
28 * @ingroup network
29 */
30class 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 using ChannelId = unsigned int;
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 using StreamId = unsigned int;
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.
162 TCPServer::ConnectionId tcpConnectionId_ = TCPServer::invalidConnectionId();
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 using StreamMap = std::map<StreamId, std::shared_ptr<Stream>>;
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 extraData Optional extra data of the channel (e.g., codec configuration)
194 * @param callback Channel callback function.
195 */
196 Channel(const std::string& name, const std::string& dataType, const Buffer& extraData, const ChannelCallback& callback);
197
198 /**
199 * Adds a new stream to this channel.
200 * @param tcpConnectionId The id of the TCP configuration connection
201 * @param address Address4 of the stream receiver
202 * @param port Port of the stream receiver
203 * @return A valid stream id, if succeeded
204 */
205 StreamId addStream(const TCPServer::ConnectionId tcpConnectionId, const Address4& address, const Port& port);
206
207 /**
208 * Removes a stream from this channel.
209 * @param streamId Id of the stream to remove
210 * @return True, if the stream existed
211 */
212 bool removeStream(const StreamId streamId);
213
214 /**
215 * (Re-)starts a stream of this channel.
216 * @param streamId Id of the stream to start
217 * @return True, if succeeded
218 */
219 bool startStream(const StreamId streamId);
220
221 /**
222 * Pauses a stream.
223 * @param streamId Id of the stream to pause
224 * @return True, if succeeded
225 */
226 bool pauseStream(const StreamId streamId);
227
228 /**
229 * Stops and removes a stream of this channel.
230 * @param streamId Id of the stream to stop
231 * @return True, if succeeded
232 */
233 bool stopStream(const StreamId streamId);
234
235 /**
236 * Returns the name of this channel.
237 * @return Unique channel name
238 */
239 inline const std::string& name() const;
240
241 /**
242 * Returns the data type of this channel.
243 * @return Channel data type
244 */
245 inline const std::string& dataType() const;
246
247 /**
248 * Returns the extra data of this channel.
249 * @return Channel extra data
250 */
251 inline const Buffer& extraData() const;
252
253 /**
254 * Returns the UDP client sender port of a given stream.
255 * @param streamId Id of the stream to return the UDP sender port for
256 * @return UDP server sender port
257 */
258 Port streamSenderPort(const StreamId streamId) const;
259
260 /**
261 * Sets or changes the data type and extra data of this channel.
262 * @param configurationTCPServer TCP server of the streaming server used for stream configurations
263 * @param messageQueue Message queue of the streaming server used for message identification
264 * @param dataType New data type to set
265 * @param extraData New extra data to set (empty to clear/remove extra data)
266 * @return True, if succeeded
267 */
268 bool setDataType(TCPServer& configurationTCPServer, MessageQueue& messageQueue, const std::string& dataType, const Buffer& extraData = Buffer());
269
270 /**
271 * Streams new data using the given UDP connections.
272 * @param data Data to stream
273 * @param size Size of the data to stream in bytes
274 * @return True, if succeeded
275 */
276 bool stream(const void* data, const size_t size);
277
278 protected:
279
280 /// Unique Channel name.
281 std::string name_;
282
283 /// Data type of the channel.
284 std::string dataType_;
285
286 /// Extra data of the channel (e.g., codec configuration).
288
289 /// Determines the number of active streaming streams.
290 unsigned int activeStreams_ = 0u;
291
292 /// Streams used for this channel.
294
295 /// Stream id counter.
296 StreamId streamIdCounter_ = StreamId(0);
297
298 /// Channel request callback function.
300 };
301
302 /**
303 * Definition of a map mapping channel ids to channels.
304 */
305 using ChannelMap = std::map<ChannelId, Channel>;
306
307 /**
308 * This class holds some information connected with a TCP connection.
309 * @ingroup network
310 */
312 {
313 public:
314
315 /**
316 * Creates an empty connection object.
317 */
318 inline Connection() = default;
319
320 /**
321 * Creates a new connection object.
322 * @param receiver The receiver address of the stream data
323 */
324 inline Connection(const Address4& receiver);
325
326 /**
327 * Returns the channel id.
328 * @return Channel id
329 */
330 inline ChannelId channelId() const;
331
332 /**
333 * Returns the stream id inside the channel.
334 * @return Channel stream id
335 */
336 inline Channel::StreamId channelStreamId() const;
337
338 /**
339 * Returns the stream receiver address of this connection.
340 * @return Receiver address
341 */
342 inline const Address4& address() const;
343
344 /**
345 * Returns the stream receiver port of this connection.
346 * @return Receiver port
347 */
348 inline const Port& port() const;
349
350 /**
351 * Sets the channel id of this connection.
352 * @param channelId Channel id to set
353 * @return True, if succeeded
354 */
355 inline bool setChannelId(const ChannelId channelId);
356
357 /**
358 * Sets the channel stream id of this connection.
359 * @param streamId Stream id to set
360 * @return True, if succeeded
361 */
362 inline bool setChannelStreamId(const Channel::StreamId streamId);
363
364 /**
365 * Sets the port of the stream data.
366 * @param port Port to set
367 * @return True, if succeeded
368 */
369 inline bool setPort(const Port& port);
370
371 private:
372
373 /// Id of the channel.
374 ChannelId channelId_ = invalidChannelId();
375
376 /// Id of the stream.
377 Channel::StreamId channelStreamId_ = Channel::invalidStreamId();
378
379 /// Receiver address of the streaming data.
381
382 /// Receiver port of the streaming data.
384 };
385
386 /**
387 * Definition of a map mapping TCP connection ids to server stream connections.
388 */
389 using ConnectionMap = std::unordered_map<TCPServer::ConnectionId, Connection>;
390
391 public:
392
393 /**
394 * Creates a new streaming server.
395 */
397
398 /**
399 * Destructs a streaming server.
400 */
402
403 /**
404 * Sets the server address.
405 * If the systems supports more than one network address use this function to define which address to use for this server.<br>
406 * However, normally is not necessary to define the local address.
407 * @param address Address to use for this streaming server
408 * @return True, if succeeded
409 */
410 bool setAddress(const Address4& address);
411
412 /**
413 * Sets the server port.
414 * @param port Server port to set
415 * @return True, if succeeded
416 */
417 bool setPort(const Port& port);
418
419 /**
420 * Returns the server address.
421 * @return Server address
422 */
424
425 /**
426 * Returns the server port.
427 * @return Server port
428 */
429 Port port() const;
430
431 /**
432 * Enables the streaming server.
433 * @return True, if succeeded
434 */
435 bool enable();
436
437 /**
438 * Disables the streaming server.
439 * @return True, if succeeded
440 */
441 bool disable();
442
443 /**
444 * Returns whether the server is enabled.
445 * @return True, if so
446 */
447 inline bool isEnabled() const;
448
449 /**
450 * Registers a new channel.
451 * @param channel Unique name of the new channel to register
452 * @param dataType Data type provides by the channel
453 * @param extraData Optional extra data for the channel (e.g., codec configuration)
454 * @param callback Channel request callback
455 * @return Valid channel id if succeeded
456 */
457 ChannelId registerChannel(const std::string& channel, const std::string& dataType, const Buffer& extraData, const ChannelCallback& callback);
458
459 /**
460 * Changes the data type and extra data of a channel.
461 * @param channelId SessionId of the channel to change
462 * @param dataType New data type to set
463 * @param extraData New extra data to set (empty to clear/remove extra data)
464 * @return True, if succeeded
465 */
466 bool changeDataType(const ChannelId channelId, const std::string& dataType, const Buffer& extraData = Buffer());
467
468 /**
469 * Unregister a channel.
470 * @param channelId SessionId of the channel to unregister
471 * @return True, if succeeded
472 */
473 bool unregisterChannel(const ChannelId channelId);
474
475 /**
476 * Returns whether this server holds a specified channel.
477 * @return True, if the channel exists already
478 */
479 bool hasChannel(const std::string& channel) const;
480
481 /**
482 * Releases all channels.
483 */
484 void release();
485
486 /**
487 * Sets new streaming data for a specified channel.
488 * @param channelId SessionId of the streaming channel
489 * @param data Streaming data
490 * @param size Streaming data size in bytes
491 * @return True, if the data was accepted
492 */
493 bool stream(const ChannelId channelId, const void* data, const size_t size);
494
495 /**
496 * Returns the number of registered channels.
497 * @return Channels
498 */
499 inline size_t channels() const;
500
501 /**
502 * Returns a generated but unique channel name.
503 * @return Unique channel name
504 */
505 std::string generateUniqueChannel() const;
506
507 protected:
508
509 /**
510 * New TCP connection request function.
511 * @param address Sender address
512 * @param port Sender port
513 * @param connectionId TCP server specific connection id
514 */
515 bool onTCPConnection(const Address4& address, const Port& port, const TCPServer::ConnectionId connectionId);
516
517 /**
518 * Callback function for TCP disconnect.
519 * @param tcpConnectionId TCP server connection id that was disconnected
520 */
521 void onTCPDisconnect(const TCPServer::ConnectionId tcpConnectionId);
522
523 /**
524 * New command function.
525 * @param tcpConnectionId TCP server connection id
526 * @param command New command to handle
527 * @param value Command value
528 * @param sessionId Unique id of the server which is not unique on the client side
529 */
530 void onCommand(const TCPServer::ConnectionId tcpConnectionId, const std::string& command, const std::string& value, const SessionId sessionId);
531
532 /**
533 * Function handling connect commands.
534 * @param tcpConnectionId TCP server connection id
535 * @param value Command value
536 * @param sessionId Unique id of the server which is not unique on the client side
537 */
538 void onConnect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
539
540 /**
541 * Function handling disconnect commands.
542 * @param tcpConnectionId TCP server connection id
543 * @param value Command value
544 * @param sessionId Unique id of the server which is not unique on the client side
545 */
546 void onDisconnect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
547
548 /**
549 * Function handling client port commands.
550 * @param tcpConnectionId TCP server connection id
551 * @param value Command value
552 * @param sessionId Unique id of the server which is not unique on the client side
553 */
554 void onClientPort(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
555
556 /**
557 * Function handling server port commands.
558 * @param tcpConnectionId TCP server connection id
559 * @param value Command value
560 * @param sessionId Unique id of the server which is not unique on the client side
561 */
562 void onServerPort(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
563
564 /**
565 * Function handling channel select commands.
566 * @param tcpConnectionId TCP server connection id
567 * @param value Command value
568 * @param sessionId Unique id of the server which is not unique on the client side
569 */
570 void onChannelSelect(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
571
572 /**
573 * Function handling start commands.
574 * @param tcpConnectionId TCP server connection id
575 * @param value Command value
576 * @param sessionId Unique id of the server which is not unique on the client side
577 */
578 void onStart(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
579
580 /**
581 * Function handling pause commands.
582 * @param tcpConnectionId TCP server connection id
583 * @param value Command value
584 * @param sessionId Unique id of the server which is not unique on the client side
585 */
586 void onPause(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
587
588 /**
589 * Function handling stop commands.
590 * @param tcpConnectionId TCP server connection id
591 * @param value Command value
592 * @param sessionId Unique id of the server which is not unique on the client side
593 */
594 void onStop(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
595
596 /**
597 * Function handling channel commands.
598 * @param tcpConnectionId TCP server connection id
599 * @param value Command value
600 * @param sessionId Unique id of the server which is not unique on the client side
601 */
602 void onChannelRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
603
604 /**
605 * Function handling data type commands.
606 * @param tcpConnectionId TCP server connection id
607 * @param value Command value
608 * @param sessionId Unique id of the server which is not unique on the client side
609 */
610 void onDataTypeRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
611
612 /**
613 * Function handling extra data commands.
614 * @param tcpConnectionId TCP server connection id
615 * @param value Command value
616 * @param sessionId Unique id of the server which is not unique on the client side
617 */
618 void onExtraDataRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string& value, const SessionId sessionId);
619
620 /**
621 * Callback function for TCP receive message.
622 * @param tcpConnectionId TCP server connection id
623 * @param data Received data
624 * @param size The size of the received data
625 */
626 void onTCPReceive(const TCPServer::ConnectionId tcpConnectionId, const void* data, const size_t size);
627
628 protected:
629
630 /// Determines whether the server is enabled.
631 bool isEnabled_ = false;
632
633 /// TCP server used for configuration tasks.
635
636 /// Registered channels.
638
639 /// Channel id counter.
640 ChannelId channelIdCounter_ = ChannelId(0);
641
642 /// Map mapping TCP connection ids to subscribed channels.
644
645 /// Server lock.
646 mutable Lock lock_;
647};
648
653
658
660{
661 return isStreaming_;
662}
663
665{
666 return tcpConnectionId_;
667}
668
670{
671 return udpClient_.address();
672}
673
675{
676 return udpClient_.port();
677}
678
680{
681 return address_;
682}
683
685{
686 return port_;
687}
688
689inline const std::string& StreamingServer::Channel::name() const
690{
691 return name_;
692}
693
694inline const std::string& StreamingServer::Channel::dataType() const
695{
696 return dataType_;
697}
698
700{
701 return extraData_;
702}
703
705 address_(receiver)
706{
707 // nothing to do here
708}
709
711{
712 return channelId_;
713}
714
716{
717 return channelStreamId_;
718}
719
721{
722 return address_;
723}
724
726{
727 return port_;
728}
729
731{
732 if (channelId_ != invalidChannelId())
733 {
734 return false;
735 }
736
737 channelId_ = channelId;
738 return true;
739}
740
742{
743 if (channelStreamId_ != Channel::invalidStreamId())
744 {
745 return false;
746 }
747
748 channelStreamId_ = streamId;
749 return true;
750}
751
753{
754 if (port_.isNull() == false || port.isNull())
755 {
756 return false;
757 }
758
759 port_ = port;
760 return true;
761}
762
763inline bool StreamingServer::isEnabled() const
764{
765 return isEnabled_;
766}
767
768inline size_t StreamingServer::channels() const
769{
770 const ScopedLock scopedLock(lock_);
771
772 return channelMap_.size();
773}
774
775}
776
777}
778
779#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
This class implements a message queue.
Definition MessageQueue.h:28
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
MessageQueue::Id SessionId
Definition of a session id.
Definition Streaming.h:51
std::string name_
Name of this streaming object.
Definition Streaming.h:260
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition Streaming.h:31
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:674
bool isStreaming() const
Returns whether this stream is currently streaming.
Definition StreamingServer.h:659
const Address4 & receiverAddress() const
Returns the address of the receiver.
Definition StreamingServer.h:679
const Port & receiverPort() const
Returns the port of the receiver.
Definition StreamingServer.h:684
TCPServer::ConnectionId tcpConnectionId() const
Returns the id of the TCP configuration connection associated with this stream.
Definition StreamingServer.h:664
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:669
PackagedUDPClient udpClient_
UDP client used for stream data transfer.
Definition StreamingServer.h:165
This class implements a channel.
Definition StreamingServer.h:56
Buffer extraData_
Extra data of the channel (e.g., codec configuration).
Definition StreamingServer.h:287
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 setDataType(TCPServer &configurationTCPServer, MessageQueue &messageQueue, const std::string &dataType, const Buffer &extraData=Buffer())
Sets or changes the data type and extra data of this channel.
bool removeStream(const StreamId streamId)
Removes a stream from this channel.
const Buffer & extraData() const
Returns the extra data of this channel.
Definition StreamingServer.h:699
Channel(const std::string &name, const std::string &dataType, const Buffer &extraData, const ChannelCallback &callback)
Creates a new channel.
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:694
std::map< StreamId, std::shared_ptr< Stream > > StreamMap
Definition of a map mapping stream ids to streams.
Definition StreamingServer.h:180
unsigned int StreamId
Definition of a stream id.
Definition StreamingServer.h:62
ChannelCallback channelCallback_
Channel request callback function.
Definition StreamingServer.h:299
static constexpr StreamId invalidStreamId()
Returns an invalid stream id.
Definition StreamingServer.h:654
std::string name_
Unique Channel name.
Definition StreamingServer.h:281
bool pauseStream(const StreamId streamId)
Pauses a stream.
const std::string & name() const
Returns the name of this channel.
Definition StreamingServer.h:689
bool stopStream(const StreamId streamId)
Stops and removes a stream of this channel.
StreamMap streamMap_
Streams used for this channel.
Definition StreamingServer.h:293
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:284
This class holds some information connected with a TCP connection.
Definition StreamingServer.h:312
ChannelId channelId() const
Returns the channel id.
Definition StreamingServer.h:710
bool setPort(const Port &port)
Sets the port of the stream data.
Definition StreamingServer.h:752
bool setChannelStreamId(const Channel::StreamId streamId)
Sets the channel stream id of this connection.
Definition StreamingServer.h:741
Address4 address_
Receiver address of the streaming data.
Definition StreamingServer.h:380
Connection()=default
Creates an empty connection object.
Port port_
Receiver port of the streaming data.
Definition StreamingServer.h:383
const Port & port() const
Returns the stream receiver port of this connection.
Definition StreamingServer.h:725
Channel::StreamId channelStreamId() const
Returns the stream id inside the channel.
Definition StreamingServer.h:715
bool setChannelId(const ChannelId channelId)
Sets the channel id of this connection.
Definition StreamingServer.h:730
const Address4 & address() const
Returns the stream receiver address of this connection.
Definition StreamingServer.h:720
This class implements a streaming server.
Definition StreamingServer.h:31
static constexpr ChannelId invalidChannelId()
Returns an invalid channel id.
Definition StreamingServer.h:649
bool changeDataType(const ChannelId channelId, const std::string &dataType, const Buffer &extraData=Buffer())
Changes the data type and extra data of a channel.
bool disable()
Disables the streaming server.
void onClientPort(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling client port commands.
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:646
TCPServer tcpServer_
TCP server used for configuration tasks.
Definition StreamingServer.h:634
ConnectionMap connectionMap_
Map mapping TCP connection ids to subscribed channels.
Definition StreamingServer.h:643
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:637
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:631
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.
void onExtraDataRequest(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling extra data commands.
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.
unsigned int ChannelId
Definition of a channel id.
Definition StreamingServer.h:42
std::string generateUniqueChannel() const
Returns a generated but unique channel name.
void onTCPDisconnect(const TCPServer::ConnectionId tcpConnectionId)
Callback function for TCP disconnect.
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.
ChannelId registerChannel(const std::string &channel, const std::string &dataType, const Buffer &extraData, const ChannelCallback &callback)
Registers a new channel.
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:763
bool enable()
Enables the streaming server.
std::unordered_map< TCPServer::ConnectionId, Connection > ConnectionMap
Definition of a map mapping TCP connection ids to server stream connections.
Definition StreamingServer.h:389
void onDisconnect(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling disconnect commands.
void onChannelSelect(const TCPServer::ConnectionId tcpConnectionId, const std::string &value, const SessionId sessionId)
Function handling channel select commands.
size_t channels() const
Returns the number of registered channels.
Definition StreamingServer.h:768
std::map< ChannelId, Channel > ChannelMap
Definition of a map mapping channel ids to channels.
Definition StreamingServer.h:305
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:147
The namespace covering the entire Ocean framework.
Definition Accessor.h:15