CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
multigpu
primary.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/NonCopyable.h
"
10
#include "
carla/Time.h
"
11
#include "
carla/TypeTraits.h
"
12
#include "
carla/profiler/LifetimeProfiled.h
"
13
#include "
carla/streaming/detail/Types.h
"
14
#include "
carla/streaming/detail/tcp/Message.h
"
15
#include "
carla/multigpu/listener.h
"
16
17
#include <boost/asio/io_context.hpp>
18
#include <boost/asio/ip/tcp.hpp>
19
#include <boost/asio/steady_timer.hpp>
20
#include <boost/asio/strand.hpp>
21
22
#include <deque>
23
#include <functional>
24
#include <memory>
25
26
namespace
carla
{
27
namespace
multigpu
{
28
29
/// A TCP server session. When a session opens, it reads from the socket a
30
/// stream id object and passes itself to the callback functor. The session
31
/// closes itself after @a timeout of inactivity is met.
32
class
Primary
33
:
public
std::enable_shared_from_this<Primary>,
34
private
profiler::LifetimeProfiled
,
35
private
NonCopyable
{
36
public
:
37
38
using
socket_type
= boost::asio::ip::tcp::socket;
39
40
explicit
Primary
(
41
boost::asio::io_context &io_context,
42
time_duration
timeout,
43
Listener
&server);
44
45
~Primary
();
46
47
/// Starts the session and calls @a on_opened after successfully reading the
48
/// stream id, and @a on_closed once the session is closed.
49
void
Open
(
50
Listener::callback_function_type
on_opened,
51
Listener::callback_function_type
on_closed,
52
Listener::callback_function_type_response
on_response);
53
54
template
<
typename
... Buffers>
55
static
auto
MakeMessage
(Buffers... buffers) {
56
static_assert
(
57
are_same
<
SharedBufferView
, Buffers...>::value,
58
"This function only accepts arguments of type BufferView."
);
59
return
std::make_shared<const carla::streaming::detail::tcp::Message>(buffers...);
60
}
61
62
/// Writes some data to the socket.
63
void
Write
(std::shared_ptr<const carla::streaming::detail::tcp::Message> message);
64
65
/// Writes a string
66
void
Write
(std::string text);
67
68
/// read data
69
void
ReadData
();
70
71
/// Writes some data to the socket.
72
template
<
typename
... Buffers>
73
void
Write
(Buffers... buffers) {
74
Write
(
MakeMessage
(buffers...));
75
}
76
77
/// Post a job to close the session.
78
void
Close
();
79
80
private
:
81
82
using
message_type
= std::shared_ptr<const carla::streaming::detail::tcp::Message>;
83
84
/// Starts writing the front of the write queue. Strand only.
85
void
WriteNext
();
86
87
void
StartTimer
();
88
89
void
CloseNow
(boost::system::error_code ec = boost::system::error_code());
90
91
friend
class
Listener
;
92
93
Listener
&
_server
;
94
95
const
size_t
_session_id
;
96
97
socket_type
_socket
;
98
99
time_duration
_timeout
;
100
101
boost::asio::steady_timer
_deadline
;
102
103
boost::asio::io_context::strand
_strand
;
104
105
Listener::callback_function_type
_on_closed
;
106
107
Listener::callback_function_type_response
_on_response
;
108
109
std::shared_ptr<BufferPool>
_buffer_pool
;
110
111
/// Messages waiting to be written, oldest first, and whether one is being
112
/// written. Strand only: a single write is ever in flight, so two large
113
/// frames can never interleave on the socket.
114
std::deque<message_type>
_write_queue
;
115
116
bool
_is_writing
=
false
;
117
118
};
119
120
}
// namespace multigpu
121
}
// namespace carla
NonCopyable.h
LifetimeProfiled.h
Message.h
Time.h
TypeTraits.h
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::multigpu::Listener::callback_function_type
std::function< void(std::shared_ptr< Primary >)> callback_function_type
Definition
listener.h:32
carla::multigpu::Listener::callback_function_type_response
std::function< void(std::shared_ptr< Primary >, carla::Buffer)> callback_function_type_response
Definition
listener.h:33
carla::multigpu::Primary::_session_id
const size_t _session_id
Definition
primary.h:95
carla::multigpu::Primary::StartTimer
void StartTimer()
Definition
primary.cpp:197
carla::multigpu::Primary::_write_queue
std::deque< message_type > _write_queue
Messages waiting to be written, oldest first, and whether one is being written.
Definition
primary.h:114
carla::multigpu::Primary::WriteNext
void WriteNext()
Starts writing the front of the write queue. Strand only.
Definition
primary.cpp:89
carla::multigpu::Primary::message_type
std::shared_ptr< const carla::streaming::detail::tcp::Message > message_type
Definition
primary.h:82
carla::multigpu::Primary::_socket
socket_type _socket
Definition
primary.h:97
carla::multigpu::Primary::_timeout
time_duration _timeout
Definition
primary.h:99
carla::multigpu::Primary::Write
void Write(Buffers... buffers)
Writes some data to the socket.
Definition
primary.h:73
carla::multigpu::Primary::Open
void Open(Listener::callback_function_type on_opened, Listener::callback_function_type on_closed, Listener::callback_function_type_response on_response)
Starts the session and calls on_opened after successfully reading the stream id, and on_closed once t...
Definition
primary.cpp:52
carla::multigpu::Primary::_is_writing
bool _is_writing
Definition
primary.h:116
carla::multigpu::Primary::Listener
friend class Listener
Definition
primary.h:91
carla::multigpu::Primary::_buffer_pool
std::shared_ptr< BufferPool > _buffer_pool
Definition
primary.h:109
carla::multigpu::Primary::_on_closed
Listener::callback_function_type _on_closed
Definition
primary.h:105
carla::multigpu::Primary::Primary
Primary(boost::asio::io_context &io_context, time_duration timeout, Listener &server)
Definition
primary.cpp:30
carla::multigpu::Primary::_server
Listener & _server
Definition
primary.h:93
carla::multigpu::Primary::_strand
boost::asio::io_context::strand _strand
Definition
primary.h:103
carla::multigpu::Primary::MakeMessage
static auto MakeMessage(Buffers... buffers)
Definition
primary.h:55
carla::multigpu::Primary::socket_type
boost::asio::ip::tcp::socket socket_type
Definition
primary.h:38
carla::multigpu::Primary::_on_response
Listener::callback_function_type_response _on_response
Definition
primary.h:107
carla::multigpu::Primary::_deadline
boost::asio::steady_timer _deadline
Definition
primary.h:101
carla::multigpu::Primary::Write
void Write(std::shared_ptr< const carla::streaming::detail::tcp::Message > message)
Writes some data to the socket.
Definition
primary.cpp:72
carla::multigpu::Primary::CloseNow
void CloseNow(boost::system::error_code ec=boost::system::error_code())
Definition
primary.cpp:215
carla::multigpu::Primary::Close
void Close()
Post a job to close the session.
Definition
primary.cpp:188
carla::multigpu::Primary::ReadData
void ReadData()
read data
Definition
primary.cpp:130
carla::profiler::LifetimeProfiled
Definition
LifetimeProfiled.h:14
carla::time_duration
Positive time duration up to milliseconds resolution.
Definition
Time.h:20
listener.h
carla::multigpu
Definition
commands.h:17
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::SharedBufferView
std::shared_ptr< BufferView > SharedBufferView
Definition
BufferView.h:151
Types.h
carla::are_same
Definition
TypeTraits.h:14
Generated by
1.18.0