CARLA
 
载入中...
搜索中...
未找到
streaming/low_level/Server.h
浏览该文件的文档.
1// Copyright (c) 2017 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
12
13#include <boost/asio/io_context.hpp>
14
15namespace carla {
16namespace streaming {
17namespace low_level {
18
19 /// A low-level streaming server. Each new stream has a token associated, this
20 /// token can be used by a client to subscribe to the stream. This server
21 /// requires an external io_context running.
22 ///
23 /// @warning This server cannot be destructed before its @a io_context is
24 /// stopped.
25 template <typename T>
26 class Server {
27 public:
28
30
31 using protocol_type = typename underlying_server::protocol_type;
32
34
36
37 template <typename InternalEPType, typename ExternalEPType>
38 explicit Server(
39 boost::asio::io_context &io_context,
42 : _server(io_context, std::move(internal_ep)),
43 _dispatcher(std::move(external_ep)) {
45 }
46
47 template <typename InternalEPType>
48 explicit Server(
49 boost::asio::io_context &io_context,
51 : _server(io_context, std::move(internal_ep)),
54 }
55
56 template <typename... EPArgs>
57 explicit Server(boost::asio::io_context &io_context, EPArgs &&... args)
58 : Server(io_context, make_endpoint<protocol_type>(std::forward<EPArgs>(args)...)) {}
59
60 typename underlying_server::endpoint GetLocalEndpoint() const {
61 return _server.GetLocalEndpoint();
62 }
63
64 void SetTimeout(time_duration timeout) {
65 _server.SetTimeout(timeout);
66 }
67
69 return _dispatcher.MakeStream();
70 }
71
75
76 void SetSynchronousMode(bool is_synchro) {
77 _server.SetSynchronousMode(is_synchro);
78 }
79
81 return _dispatcher.GetToken(sensor_id);
82 }
83
84 void EnableForROS(stream_id sensor_id) {
85 _dispatcher.EnableForROS(sensor_id);
86 }
87
88 void DisableForROS(stream_id sensor_id) {
89 _dispatcher.DisableForROS(sensor_id);
90 }
91
92 bool IsEnabledForROS(stream_id sensor_id) {
93 return _dispatcher.IsEnabledForROS(sensor_id);
94 }
95
96 private:
97
98 void StartServer() {
99 auto on_session_opened = [this](auto session) {
100 if (!_dispatcher.RegisterSession(session)) {
101 session->Close();
102 }
103 };
104 auto on_session_closed = [this](auto session) {
105 log_debug("on_session_closed called");
107 };
108 _server.Listen(on_session_opened, on_session_closed);
109 }
110
112
114 };
115
116} // namespace low_level
117} // namespace streaming
118} // namespace carla
Keeps the mapping between streams and sessions.
Definition Dispatcher.h:27
void DeregisterSession(std::shared_ptr< Session > session)
carla::streaming::Stream MakeStream()
bool RegisterSession(std::shared_ptr< Session > session)
void DisableForROS(stream_id_type sensor_id)
Definition Dispatcher.h:53
bool IsEnabledForROS(stream_id_type sensor_id)
Definition Dispatcher.h:60
void CloseStream(carla::streaming::detail::stream_id_type id)
void EnableForROS(stream_id_type sensor_id)
Definition Dispatcher.h:46
token_type GetToken(stream_id_type sensor_id)
Serializes a stream endpoint.
Server(boost::asio::io_context &io_context, detail::EndPoint< protocol_type, InternalEPType > internal_ep, detail::EndPoint< protocol_type, ExternalEPType > external_ep)
void CloseStream(carla::streaming::detail::stream_id_type id)
carla::streaming::detail::stream_id_type stream_id
typename underlying_server::protocol_type protocol_type
token_type GetToken(stream_id sensor_id)
Server(boost::asio::io_context &io_context, EPArgs &&... args)
Server(boost::asio::io_context &io_context, detail::EndPoint< protocol_type, InternalEPType > internal_ep)
underlying_server::endpoint GetLocalEndpoint() const
Positive time duration up to milliseconds resolution.
Definition Time.h:19
uint32_t stream_id_type
Definition Types.h:18
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition EndPoint.h:90
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
static void log_debug(Args &&... args)
Definition Logging.h:68