CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
streaming
detail
detail/Stream.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
9
#include "
carla/Buffer.h
"
10
#include "
carla/Debug.h
"
11
#include "
carla/streaming/Token.h
"
12
13
#include <memory>
14
15
namespace
carla
{
16
namespace
streaming
{
17
namespace
detail
{
18
19
class
Dispatcher
;
20
21
template
<
typename
StreamStateT>
22
class
Stream
{
23
public
:
24
25
Stream
() =
delete
;
26
27
Stream
(
const
Stream
&) =
default
;
28
Stream
(
Stream
&&) =
default
;
29
30
Stream
&
operator=
(
const
Stream
&) =
default
;
31
Stream
&
operator=
(
Stream
&&) =
default
;
32
33
/// Token associated with this stream. This token can be used by a client to
34
/// subscribe to this stream.
35
Token
token
()
const
{
36
return
_shared_state
->token();
37
}
38
39
/// Pull a buffer from the buffer pool associated to this stream. Discarded
40
/// buffers are re-used to avoid memory allocations.
41
///
42
/// @note Re-using buffers is optimized for the use case in which all the
43
/// messages sent through the stream are big and have (approximately) the
44
/// same size.
45
Buffer
MakeBuffer
() {
46
auto
state =
_shared_state
;
47
return
state->MakeBuffer();
48
}
49
50
/// Flush @a buffers down the stream. No copies are made.
51
template
<
typename
... Buffers>
52
void
Write
(Buffers &&... buffers) {
53
_shared_state
->Write(std::move(buffers)...);
54
}
55
56
/// Make a copy of @a data and flush it down the stream.
57
template
<
typename
T>
58
Stream
&
operator<<
(
const
T &data) {
59
auto
buffer =
MakeBuffer
();
60
buffer.copy_from(data);
61
Write
(std::move(buffer));
62
return
*
this
;
63
}
64
65
bool
AreClientsListening
()
66
{
67
return
_shared_state
?
_shared_state
->AreClientsListening() :
false
;
68
}
69
70
private
:
71
72
friend
class
detail::Dispatcher
;
73
74
Stream
(std::shared_ptr<StreamStateT> state)
75
:
_shared_state
(
std
::move(state)) {
76
DEBUG_ASSERT
(
_shared_state
!=
nullptr
);
77
}
78
79
std::shared_ptr<StreamStateT>
_shared_state
;
80
};
81
82
}
// namespace detail
83
}
// namespace streaming
84
}
// namespace carla
Debug.h
DEBUG_ASSERT
#define DEBUG_ASSERT(predicate)
Definition
Debug.h:66
Token.h
Buffer.h
carla::Buffer
A piece of raw data.
Definition
carla/Buffer.h:42
carla::streaming::Token
A token that uniquely identify a stream.
Definition
Token.h:17
carla::streaming::detail::Dispatcher
Keeps the mapping between streams and sessions.
Definition
Dispatcher.h:28
carla::streaming::detail::Stream::operator<<
Stream & operator<<(const T &data)
Make a copy of data and flush it down the stream.
Definition
detail/Stream.h:58
carla::streaming::detail::Stream::token
Token token() const
Token associated with this stream.
Definition
detail/Stream.h:35
carla::streaming::detail::Stream::operator=
Stream & operator=(const Stream &)=default
carla::streaming::detail::Stream::Stream
Stream(std::shared_ptr< StreamStateT > state)
Definition
detail/Stream.h:74
carla::streaming::detail::Stream::AreClientsListening
bool AreClientsListening()
Definition
detail/Stream.h:65
carla::streaming::detail::Stream< detail::MultiStreamState >::_shared_state
std::shared_ptr< detail::MultiStreamState > _shared_state
Definition
detail/Stream.h:79
carla::streaming::detail::Stream::Stream
Stream()=delete
carla::streaming::detail::Stream::Write
void Write(Buffers &&... buffers)
Flush buffers down the stream. No copies are made.
Definition
detail/Stream.h:52
carla::streaming::detail::Stream::operator=
Stream & operator=(Stream &&)=default
carla::streaming::detail::Stream::MakeBuffer
Buffer MakeBuffer()
Pull a buffer from the buffer pool associated to this stream.
Definition
detail/Stream.h:45
carla::streaming::detail::Stream::Stream
Stream(Stream &&)=default
carla::streaming::detail::Stream::Stream
Stream(const Stream &)=default
carla::streaming::detail
Definition
Dispatcher.cpp:17
carla::streaming
Definition
client/detail/Client.h:61
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
Generated by
1.18.0