CARLA
DataStream.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
10 
12 #include <carla/streaming/Stream.h>
13 #include <boost/optional.hpp>
15 
16 // =============================================================================
17 // -- FDataStreamTmpl ----------------------------------------------------------
18 // =============================================================================
19 
20 /// A streaming channel for sending sensor data to clients. Each sensor has its
21 /// own FDataStream. Note however that this class does not provide a send
22 /// function. In order to send data, a FAsyncDataStream needs to be created
23 /// using "MakeAsyncDataStream" function. FAsyncDataStream allows sending data
24 /// from any thread.
25 template <typename T>
26 class FDataStreamTmpl
27 {
28 public:
29 
30  using StreamType = T;
31 
32  FDataStreamTmpl() = default;
33 
34  FDataStreamTmpl(StreamType InStream) : Stream(std::move(InStream)) {}
35 
36  /// Create a FAsyncDataStream object.
37  ///
38  /// @pre This functions needs to be called in the game-thread.
39  template <typename SensorT>
40  auto MakeAsyncDataStream(const SensorT &Sensor, double Timestamp)
41  {
42  check(Stream.has_value());
43  return FAsyncDataStreamTmpl<T>{Sensor, Timestamp, *Stream};
44  }
45 
46  /// Return the token that allows subscribing to this stream.
47  auto GetToken() const
48  {
49  check(Stream.has_value());
50  return (*Stream).token();
51  }
52 
54  {
55  check(Stream.has_value());
56  return Stream ? Stream->AreClientsListening() : false;
57  }
58 
59 private:
60 
61  boost::optional<StreamType> Stream;
62 };
63 
64 // =============================================================================
65 // -- FDataStream and FDataMultiStream -----------------------------------------
66 // =============================================================================
67 
69 
boost::optional< StreamType > Stream
Definition: DataStream.h:61
A streaming channel for sending sensor data to clients.
bool AreClientsListening()
Definition: DataStream.h:53
auto MakeAsyncDataStream(const SensorT &Sensor, double Timestamp)
Create a FAsyncDataStream object.
Definition: DataStream.h:40
FDataStreamTmpl(StreamType InStream)
Definition: DataStream.h:34
auto GetToken() const
Return the token that allows subscribing to this stream.
Definition: DataStream.h:47
FDataStreamTmpl()=default
A streaming channel for sending sensor data to clients, supports sending data asynchronously.