CARLA
载入中...
搜索中...
未找到
LibCarla
source
carla
ros2
listeners
CarlaListener.cpp
浏览该文件的文档.
1
#define _GLIBCXX_USE_CXX11_ABI 0
2
3
#include "
CarlaListener.h
"
4
#include <iostream>
// 包含标准输入输出库,用于标准输出流操作
5
6
#include <fastdds/dds/publisher/DataWriterListener.hpp>
// 包含fastdds库中DataWriterListener的头文件
7
#include <fastdds/dds/core/status/PublicationMatchedStatus.hpp>
// 包含fastdds库中PublicationMatchedStatus的头文件,这个类包含了与发布匹配状态相关的信息
8
9
namespace
carla
{
10
namespace
ros2
{
// 定义一个嵌套命名空间carla::ros2,用于组织代码
11
12
namespace
efd
= eprosima::fastdds::dds;
// 使用eprosima::fastdds::dds命名空间,并简化为efd
13
14
class
CarlaListenerImpl
:
public
efd::DataWriterListener
{
// 定义CarlaListenerImpl类,继承自efd::DataWriterListener
15
public
:
16
void
on_publication_matched
(
// 重写DataWriterListener中的on_publication_matched方法
17
efd::DataWriter* writer,
// 数据写入对象的指针
18
const
efd::PublicationMatchedStatus& info)
override
;
// 包含匹配状态信息的对象
19
20
21
int
_matched
{0};
// 成员变量_matched,用于记录当前匹配的订阅者数量
22
bool
_first_connected
{
false
};
// 成员变量_first_connected,用于标记是否是第一次有订阅者连接
23
};
24
25
void
CarlaListenerImpl::on_publication_matched
(efd::DataWriter* writer,
const
efd::PublicationMatchedStatus& info)
// 实现CarlaListenerImpl类的on_publication_matched方法
26
{
27
if
(info.current_count_change == 1) {
// 如果当前计数变化为1,表示有新的订阅者连接
28
_matched
= info.total_count;
// 更新匹配的订阅者数量
29
_first_connected
=
true
;
// 标记为第一次连接
30
}
else
if
(info.current_count_change == -1) {
// 如果当前计数变化为-1,表示有订阅者断开连接
31
_matched
= info.total_count;
// 更新匹配的订阅者数量
32
}
else
{
// 如果当前计数变化不是1或-1,输出错误信息
33
std::cerr << info.current_count_change
34
<<
" is not a valid value for PublicationMatchedStatus current count change"
<< std::endl;
35
}
36
}
37
38
CarlaListener::CarlaListener() :
// 定义CarlaListener类,它包含CarlaListenerImpl类的实例
39
_impl(
std
::make_unique<
CarlaListenerImpl
>()) { }
// 构造函数,初始化_impl成员,使用std::make_unique创建CarlaListenerImpl的实例
40
41
CarlaListener::~CarlaListener() {}
// CarlaListener类的析构函数,用于在对象销毁时进行清理
42
43
}}
CarlaListener.h
carla::ros2::CarlaListenerImpl
Definition
CarlaListener.cpp:14
carla::ros2::CarlaListenerImpl::_matched
int _matched
Definition
CarlaListener.cpp:21
carla::ros2::CarlaListenerImpl::on_publication_matched
void on_publication_matched(efd::DataWriter *writer, const efd::PublicationMatchedStatus &info) override
Definition
CarlaListener.cpp:25
carla::ros2::CarlaListenerImpl::_first_connected
bool _first_connected
Definition
CarlaListener.cpp:22
eprosima::fastdds::dds::DataWriterListener
carla::ros2::efd
efd
Definition
CarlaMapSensorPublisher.cpp:27
carla
CARLA模拟器的主命名空间。
Definition
Carla.cpp:139
ros2
std
Definition
CarlaRecorderCollision.h:31
制作者
1.10.0