CARLA
Loading...
Searching...
No Matches
streaming/Server.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/ThreadPool.h"
13
14#include <boost/asio/io_context.hpp>
15
16#include <optional>
17
18namespace carla {
19namespace streaming {
20
21 /// A streaming server. Each new stream has a token associated, this token can
22 /// be used by a client to subscribe to the stream.
23 class Server {
28 public:
29
30 explicit Server(uint16_t port)
31 : _server(_pool.io_context(), make_endpoint<protocol_type>(port)) {}
32
33 explicit Server(const std::string &address, uint16_t port)
34 : _server(_pool.io_context(), make_endpoint<protocol_type>(address, port)) {}
35
36 explicit Server(
37 const std::string &address, uint16_t port,
38 const std::string &external_address, uint16_t external_port)
39 : _server(
40 _pool.io_context(),
41 make_endpoint<protocol_type>(address, port),
42 make_endpoint<protocol_type>(external_address, external_port)) {}
43
45 _pool.Stop();
46 }
47
48 auto GetLocalEndpoint() const {
50 }
51
52 void SetTimeout(time_duration timeout) {
53 _server.SetTimeout(timeout);
54 }
55
57 return _server.MakeStream();
58 }
59
63
64 void Run() {
65 _pool.Run();
66 }
67
68 void AsyncRun(size_t worker_threads) {
69 _pool.AsyncRun(worker_threads);
70 }
71
72 void SetSynchronousMode(bool is_synchro) {
73 _server.SetSynchronousMode(is_synchro);
74 }
75
77 return _server.GetToken(sensor_id);
78 }
79
80 /// Token of an existing stream, or std::nullopt if @a id is unknown.
81 [[nodiscard]]
82 std::optional<token_type> FindToken(stream_id id) {
83 return _server.FindToken(id);
84 }
85
86 void SetSessionsUseStreamAliases(bool enabled) {
88 }
89
90 void SetStreamAlias(stream_id alias, stream_id target) {
91 _server.SetStreamAlias(alias, target);
92 }
93
97
98 [[nodiscard]]
99 std::optional<stream_id> FindStreamAlias(stream_id alias) {
100 return _server.FindStreamAlias(alias);
101 }
102
106
107 void EnableForROS(stream_id sensor_id) {
108 _server.EnableForROS(sensor_id);
109 }
110
111 void DisableForROS(stream_id sensor_id) {
112 _server.DisableForROS(sensor_id);
113 }
114
115 bool IsEnabledForROS(stream_id sensor_id) {
116 return _server.IsEnabledForROS(sensor_id);
117 }
118
119 private:
120
121 // The order of these two arguments is very important.
122
124
126 };
127
128} // namespace streaming
129} // namespace carla
A thread pool based on Boost.Asio's io context.
Definition ThreadPool.h:25
void Stop()
Stop the ThreadPool and join all its threads.
Definition ThreadPool.h:79
void AsyncRun(size_t worker_threads)
Launch threads to run tasks asynchronously.
Definition ThreadPool.h:54
void Run()
Run tasks in this thread.
Definition ThreadPool.h:66
A streaming server.
std::optional< stream_id > FindStreamAlias(stream_id alias)
carla::streaming::detail::stream_id_type stream_id
token_type GetToken(stream_id sensor_id)
void RemoveStreamAlias(stream_id alias)
void SetTimeout(time_duration timeout)
Server(const std::string &address, uint16_t port)
bool IsEnabledForROS(stream_id sensor_id)
std::optional< token_type > FindToken(stream_id id)
Token of an existing stream, or std::nullopt if id is unknown.
void CloseStream(carla::streaming::detail::stream_id_type id)
void EnableForROS(stream_id sensor_id)
void SetStreamAlias(stream_id alias, stream_id target)
low_level::Server< detail::tcp::Server >::protocol_type protocol_type
void SetROS2TopicVisibilityDefaultEnabled(bool enabled)
Server(const std::string &address, uint16_t port, const std::string &external_address, uint16_t external_port)
void AsyncRun(size_t worker_threads)
void DisableForROS(stream_id sensor_id)
void SetSynchronousMode(bool is_synchro)
void SetSessionsUseStreamAliases(bool enabled)
Serializes a stream endpoint.
void CloseStream(carla::streaming::detail::stream_id_type id)
typename underlying_server::protocol_type protocol_type
token_type GetToken(stream_id sensor_id)
underlying_server::endpoint GetLocalEndpoint() const
std::optional< stream_id > FindStreamAlias(stream_id alias)
std::optional< token_type > FindToken(stream_id id)
void SetStreamAlias(stream_id alias, stream_id target)
Positive time duration up to milliseconds resolution.
Definition Time.h:20
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition EndPoint.h:89
This file contains definitions of common data structures used in traffic manager.