CARLA
Loading...
Searching...
No Matches
DataStream.h
Go to the documentation of this file.
1// Copyright (c) 2026 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
14
15#include <optional>
16
17// =============================================================================
18// -- FDataStreamTmpl ----------------------------------------------------------
19// =============================================================================
20
21/// A streaming channel for sending sensor data to clients. Each sensor has its
22/// own FDataStream. Note however that this class does not provide a send
23/// function. In order to send data, a FAsyncDataStream needs to be created
24/// using "MakeAsyncDataStream" function. FAsyncDataStream allows sending data
25/// from any thread.
26template <typename T>
28{
29public:
30
31 using StreamType = T;
32
33 FDataStreamTmpl() = default;
34
35 FDataStreamTmpl(StreamType InStream) : Stream(std::move(InStream)) {}
36
37 /// Create a FAsyncDataStream object.
38 ///
39 /// @pre This functions needs to be called in the game-thread.
40 template <typename SensorT>
41 FAsyncDataStreamTmpl<T> MakeAsyncDataStream(const SensorT &Sensor, double Timestamp)
42 {
43 check(Stream.has_value());
44 return FAsyncDataStreamTmpl<T>{Sensor, Timestamp, *Stream};
45 }
46
48 {
49 return Stream.has_value();
50 }
51
52 /// Return the token that allows subscribing to this stream.
53 auto GetToken() const
54 {
55 check(Stream.has_value());
56 return Stream->token();
57 }
58
59 uint64_t GetSensorType()
60 {
61 check(Stream.has_value());
62 return Stream->get_stream_id();
63 }
64
66 {
67 check(Stream.has_value());
68 return Stream->AreClientsListening();
69 }
70
71private:
72
73 std::optional<StreamType> Stream;
74};
75
76// =============================================================================
77// -- FDataStream and FDataMultiStream -----------------------------------------
78// =============================================================================
79
81
A streaming channel for sending sensor data to clients, supports sending data asynchronously.
A streaming channel for sending sensor data to clients.
Definition DataStream.h:28
std::optional< StreamType > Stream
Definition DataStream.h:73
FDataStreamTmpl()=default
bool IsStreamReady()
Definition DataStream.h:47
auto GetToken() const
Return the token that allows subscribing to this stream.
Definition DataStream.h:53
uint64_t GetSensorType()
Definition DataStream.h:59
FDataStreamTmpl(StreamType InStream)
Definition DataStream.h:35
bool AreClientsListening()
Definition DataStream.h:65
FAsyncDataStreamTmpl< T > MakeAsyncDataStream(const SensorT &Sensor, double Timestamp)
Create a FAsyncDataStream object.
Definition DataStream.h:41