CARLA
 
载入中...
搜索中...
未找到
streaming/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// 引入所需的头文件
9#include "carla/ThreadPool.h"
13
14#include <boost/asio/io_context.hpp>
15// 定义命名空间
16namespace carla {
17namespace streaming {
18
19 /// A streaming server. Each new stream has a token associated, this token can
20 /// be used by a client to subscribe to the stream.
21 class Server {
22 // 使用低级服务器的特定类型别名
27 public:
28// 构造函数,接受端口号作为参数,初始化服务器并关联到指定端口的 IO 上下文。
29 explicit Server(uint16_t port)
30 : _server(_pool.io_context(), make_endpoint<protocol_type>(port)) {}
31// 构造函数,接受地址和端口号作为参数,初始化服务器并关联到指定地址和端口的 IO 上下文。
32 explicit Server(const std::string &address, uint16_t port)
33 : _server(_pool.io_context(), make_endpoint<protocol_type>(address, port)) {}
34// 构造函数,接受内部地址、内部端口、外部地址和外部端口作为参数,初始化服务器并关联到指定的内外部地址和端口的 IO 上下文。
35 explicit Server(
36 const std::string &address, uint16_t port,
37 const std::string &external_address, uint16_t external_port)
38 : _server(
39 _pool.io_context(),
40 make_endpoint<protocol_type>(address, port),
41 make_endpoint<protocol_type>(external_address, external_port)) {}
42// 析构函数,停止线程池。
44 _pool.Stop();
45 }
46// 获取服务器的本地端点
47 auto GetLocalEndpoint() const {
49 }
50 // 设置服务器的超时时间。
51 void SetTimeout(time_duration timeout) {
52 _server.SetTimeout(timeout);
53 }
54 // 创建一个新的流。
56 return _server.MakeStream();
57 }
58 // 关闭指定 ID 的流。
62 // 启动线程池,运行服务器。
63 void Run() {
64 _pool.Run();
65 }
66// 异步启动线程池,指定工作线程数量运行服务器。
67 void AsyncRun(size_t worker_threads) {
68 _pool.AsyncRun(worker_threads);
69 }
70// 设置服务器为同步模式或异步模式。
71 void SetSynchronousMode(bool is_synchro) {
72 _server.SetSynchronousMode(is_synchro);
73 }
74// 获取指定流 ID 的令牌。
76 return _server.GetToken(sensor_id);
77 }
78// 为指定流 ID 的传感器启用 ROS 支持。
79 void EnableForROS(stream_id sensor_id) {
80 _server.EnableForROS(sensor_id);
81 }
82
83 void DisableForROS(stream_id sensor_id) {
84 _server.DisableForROS(sensor_id);
85 }
86 // 检查指定流 ID 的传感器是否启用了 ROS 支持。
87 bool IsEnabledForROS(stream_id sensor_id) {
88 return _server.IsEnabledForROS(sensor_id);
89 }
90
91 private:
92
93 // 这两个参数的顺序非常重要。
94
96
98 };
99
100} // namespace streaming
101} // namespace carla
包含与Carla流处理相关的底层细节的头文件。
基于Boost.Asio的上下文
Definition ThreadPool.h:24
void AsyncRun(size_t worker_threads)
Definition ThreadPool.h:62
A streaming server.
carla::streaming::detail::stream_id_type stream_id
token_type GetToken(stream_id sensor_id)
void SetTimeout(time_duration timeout)
Server(const std::string &address, uint16_t port)
bool IsEnabledForROS(stream_id sensor_id)
void CloseStream(carla::streaming::detail::stream_id_type id)
void EnableForROS(stream_id sensor_id)
low_level::Server< detail::tcp::Server >::protocol_type protocol_type
underlying_server _server
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)
静态断言,用于确保token_data结构体的大小与Token::data的大小相同。
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
Positive time duration up to milliseconds resolution.
Definition Time.h:19
uint32_t stream_id_type
流ID的类型定义。
Definition Types.h:33
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
Definition EndPoint.h:102
CARLA模拟器的主命名空间。
Definition Carla.cpp:139