CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
streaming
EndPoint.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 <boost/asio/io_context.hpp>
10
#include <boost/asio/ip/address.hpp>
11
#include <boost/asio/ip/tcp.hpp>
12
#include <boost/asio/ip/udp.hpp>
13
14
namespace
carla
{
15
namespace
streaming
{
16
namespace
detail
{
17
18
// When in doubt, V4 addresses are returned.
19
20
struct
FullyDefinedEndPoint
{};
21
struct
PartiallyDefinedEndPoint
{};
22
23
template
<
typename
Protocol,
typename
EndPo
int
Type>
24
class
EndPoint
;
25
26
template
<
typename
Protocol>
27
class
EndPoint
<Protocol,
FullyDefinedEndPoint
> {
28
public
:
29
30
explicit
EndPoint
(boost::asio::ip::basic_endpoint<Protocol> ep)
31
:
_endpoint
(
std
::move(ep)) {}
32
33
auto
address
()
const
{
34
return
_endpoint
.address();
35
}
36
37
uint16_t
port
()
const
{
38
return
_endpoint
.port();
39
}
40
41
operator
boost::asio::ip::basic_endpoint<Protocol>()
const
{
42
return
_endpoint
;
43
}
44
45
private
:
46
47
boost::asio::ip::basic_endpoint<Protocol>
_endpoint
;
48
};
49
50
template
<
typename
Protocol>
51
class
EndPoint
<Protocol,
PartiallyDefinedEndPoint
> {
52
public
:
53
54
explicit
EndPoint
(uint16_t
port
) :
_port
(
port
) {}
55
56
uint16_t
port
()
const
{
57
return
_port
;
58
}
59
60
operator
boost::asio::ip::basic_endpoint<Protocol>()
const
{
61
return
{Protocol::v4(),
_port
};
62
}
63
64
private
:
65
66
uint16_t
_port
;
67
};
68
69
}
// namespace detail
70
71
static
inline
auto
make_localhost_address
() {
72
return
boost::asio::ip::make_address(
"127.0.0.1"
);
73
}
74
75
static
inline
auto
make_address
(
const
std::string &address) {
76
boost::asio::io_context io_context;
77
boost::asio::ip::tcp::resolver resolver(io_context);
78
boost::system::error_code ec;
79
auto
results = resolver.resolve(boost::asio::ip::tcp::v4(), address,
""
, ec);
80
if
(!ec) {
81
for
(
const
auto
&entry : results) {
82
return
entry.endpoint().address();
83
}
84
}
85
return
boost::asio::ip::make_address(address);
86
}
87
88
template
<
typename
Protocol>
89
static
inline
auto
make_endpoint
(boost::asio::ip::basic_endpoint<Protocol> ep) {
90
return
detail::EndPoint<Protocol, detail::FullyDefinedEndPoint>
{std::move(ep)};
91
}
92
93
template
<
typename
Protocol>
94
static
inline
auto
make_endpoint
(
const
char
*address, uint16_t port) {
95
return
make_endpoint<Protocol>
({
make_address
(address), port});
96
}
97
98
template
<
typename
Protocol>
99
static
inline
auto
make_endpoint
(
const
std::string &address, uint16_t port) {
100
return
make_endpoint<Protocol>
(address.c_str(), port);
101
}
102
103
template
<
typename
Protocol>
104
static
inline
auto
make_endpoint
(uint16_t port) {
105
return
detail::EndPoint<Protocol, detail::PartiallyDefinedEndPoint>
{port};
106
}
107
108
}
// namespace streaming
109
}
// namespace carla
carla::streaming::detail::EndPoint< Protocol, FullyDefinedEndPoint >::address
auto address() const
Definition
EndPoint.h:33
carla::streaming::detail::EndPoint< Protocol, FullyDefinedEndPoint >::EndPoint
EndPoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition
EndPoint.h:30
carla::streaming::detail::EndPoint< Protocol, FullyDefinedEndPoint >::port
uint16_t port() const
Definition
EndPoint.h:37
carla::streaming::detail::EndPoint< Protocol, FullyDefinedEndPoint >::_endpoint
boost::asio::ip::basic_endpoint< Protocol > _endpoint
Definition
EndPoint.h:47
carla::streaming::detail::EndPoint< Protocol, PartiallyDefinedEndPoint >::EndPoint
EndPoint(uint16_t port)
Definition
EndPoint.h:54
carla::streaming::detail::EndPoint< Protocol, PartiallyDefinedEndPoint >::port
uint16_t port() const
Definition
EndPoint.h:56
carla::streaming::detail::EndPoint< Protocol, PartiallyDefinedEndPoint >::_port
uint16_t _port
Definition
EndPoint.h:66
carla::streaming::detail::EndPoint
Definition
EndPoint.h:24
carla::streaming::detail
Definition
Dispatcher.cpp:17
carla::streaming
Definition
client/detail/Client.h:61
carla::streaming::make_address
static auto make_address(const std::string &address)
Definition
EndPoint.h:75
carla::streaming::make_localhost_address
static auto make_localhost_address()
Definition
EndPoint.h:71
carla::streaming::make_endpoint
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition
EndPoint.h:89
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::streaming::detail::FullyDefinedEndPoint
Definition
EndPoint.h:20
carla::streaming::detail::PartiallyDefinedEndPoint
Definition
EndPoint.h:21
Generated by
1.18.0