CARLA
 
载入中...
搜索中...
未找到
secondary.h
浏览该文件的文档.
1// Copyright (c) 2022 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/Buffer.h" // 引入 Buffer 相关头文件
10#include "carla/NonCopyable.h" // 引入不可拷贝类的头文件
11#include "carla/TypeTraits.h" // 引入类型特征相关头文件
12#include "carla/profiler/LifetimeProfiled.h" // 引入生命周期分析相关头文件
13#include "carla/multigpu/secondaryCommands.h" //引入Carla多GPU处理框架中用于管理和执行次级GPU命令的头文件
14#include "carla/streaming/detail/tcp/Message.h" // 引入 TCP 消息的详细实现头文件
15#include "carla/streaming/detail/Token.h" // 引入 Token 的详细实现头文件
16#include "carla/streaming/detail/Types.h" // 引入流相关类型的头文件
17#include "carla/ThreadPool.h" // 引入线程池的头文件
18
19#include <boost/asio/deadline_timer.hpp> // 引入 Boost ASIO 的定时器头文件
20#include <boost/asio/io_context.hpp> // 引入Boost ASIO库中用于管理异步操作和回调函数的IO上下文(也称为事件循环)的头文件
21#include <boost/asio/ip/tcp.hpp> // 引入 Boost ASIO 的 TCP 头文件
22#include <boost/asio/strand.hpp> // 引入Boost ASIO库中用于保证异步操作顺序执行的Strand类的头文件
23
24#include <atomic> // 引入原子类型支持
25#include <functional> // 引入函数对象和绑定支持
26#include <memory> // 引入智能指针支持
27
28namespace carla { // 定义 carla 命名空间
29
30 class BufferPool; // 前向声明 BufferPool 类
31
32namespace multigpu { // 定义 multigpu 命名空间
33
34 class Secondary // 定义 Secondary 类
35 : public std::enable_shared_from_this<Secondary>, // 允许共享自身的智能指针
36 private profiler::LifetimeProfiled, // 继承生命周期分析特性
37 private NonCopyable { // 禁止拷贝
38 public:
39
40 using endpoint = boost::asio::ip::tcp::endpoint; // 定义 endpoint 类型
41 using protocol_type = endpoint::protocol_type; // 定义协议类型
42
43 // 构造函数:接受 TCP 端点和回调函数
44 Secondary(boost::asio::ip::tcp::endpoint ep, SecondaryCommands::callback_type callback);
45 // 构造函数:接受 IP 地址和端口号以及回调函数
46 Secondary(std::string ip, uint16_t port, SecondaryCommands::callback_type callback);
47 ~Secondary(); // 析构函数
48
49 void Connect(); // 连接到指定的 TCP 端点
50
51 void Stop(); // 停止操作
52
53 void AsyncRun(size_t worker_threads); // 异步运行,启动指定数量的工作线程
54
55 void Write(std::shared_ptr<const carla::streaming::detail::tcp::Message> message); // 写入消息
56 void Write(Buffer buffer); // 写入 Buffer
57 void Write(std::string text); // 写入字符串
58
59 SecondaryCommands &GetCommander() { // 获取命令器的引用
60 return _commander;
61 }
62
63 // 静态成员函数:创建消息
64 template <typename... Buffers>
65 static auto MakeMessage(Buffers... buffers) {
66 static_assert(
67 are_same<SharedBufferView, Buffers...>::value,
68 "This function only accepts arguments of type BufferView."); // 检查参数类型
69 return std::make_shared<const carla::streaming::detail::tcp::Message>(buffers...); // 创建并返回消息
70 }
71
72 private:
73
74 void Reconnect(); // 重新连接
75
76 void ReadData(); // 读取数据
77
78 ThreadPool _pool; // 线程池
79 boost::asio::ip::tcp::socket _socket; // TCP socket
80 boost::asio::ip::tcp::endpoint _endpoint; // TCP 端点
81 boost::asio::io_context::strand _strand; // ASIO 的 Strand 用于同步
82 boost::asio::deadline_timer _connection_timer; // 连接定时器
83 std::shared_ptr<BufferPool> _buffer_pool; // Buffer 池的智能指针
84 std::atomic_bool _done {false}; // 原子布尔值,表示是否完成
85 SecondaryCommands _commander; // 次级命令处理器
86 };
87
88} // namespace multigpu
89} // namespace carla
包含 Carla 框架中与网络流相关的类和函数的声明。
包含与Carla流处理相关的底层细节的头文件。
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
这个类用于禁止拷贝和移动构造函数及赋值操作
基于Boost.Asio的上下文
Definition ThreadPool.h:24
std::function< void(MultiGPUCommand, carla::Buffer)> callback_type
boost::asio::ip::tcp::endpoint _endpoint
Definition secondary.h:80
boost::asio::ip::tcp::endpoint endpoint
Definition secondary.h:40
std::shared_ptr< BufferPool > _buffer_pool
Definition secondary.h:83
Secondary(boost::asio::ip::tcp::endpoint ep, SecondaryCommands::callback_type callback)
Definition secondary.cpp:48
boost::asio::io_context::strand _strand
Definition secondary.h:81
SecondaryCommands _commander
Definition secondary.h:85
boost::asio::ip::tcp::socket _socket
Definition secondary.h:79
SecondaryCommands & GetCommander()
Definition secondary.h:59
void AsyncRun(size_t worker_threads)
std::atomic_bool _done
Definition secondary.h:84
boost::asio::deadline_timer _connection_timer
Definition secondary.h:82
static auto MakeMessage(Buffers... buffers)
Definition secondary.h:65
void Write(std::shared_ptr< const carla::streaming::detail::tcp::Message > message)
endpoint::protocol_type protocol_type
Definition secondary.h:41
包含CARLA流处理相关头文件和Boost.Asio网络库头文件。 包含CARLA的调试功能相关定义。 包含CARLA流处理的端点(EndPoint)类定义。 包含CARLA流处理的令牌(Token)类...
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
std::shared_ptr< BufferView > SharedBufferView
Definition BufferView.h:163