DDS(Data Distribution Service)————PublisherLinstener(2)

DDS(Data Distribution Service)————PublisherListener(2)

4.PublisherListener

​ 在 DDS(Data Distribution Service)中,PublisherListener 是一个接口类,允许应用程序对与发布者相关的事件进行响应。通过实现并注册一个 PublisherListener,你可以处理发布者的各种状态变化和事件,例如数据写入、匹配的 DataReader 发生变化等。

4.1 创建Linstener(使用Qos实例)

 DomainParticipant* particioant = DomainParticipantFactory::get_instance()->create_participant(0,PARTICIPANT_QOS_DEFAULT);

    CustomPublisherListener cusListener;

	/* 创建含有PublisherLinster(监听器) 的 publisher */
    Publisher* pub1 = particioant->create_publisher(PUBLISHER_QOS_DEFAULT,&cusListener);

4.2 创建 Linstener(使用XML File)

DomainParticipantFactory::get_instance()->load_XML_profiles_file("profiles.xml");
DomainParticipant* participant =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);


/* Create a Publisher using a profile and no Listener */
Publisher* publisher_with_profile =
        participant->create_publisher_with_profile("publisher_profile");

/* 创建含有linstener的publisher */
CustomPublisherListener custom_listener;
Publisher* publisher_with_profile_and_custom_listener =
        participant->create_publisher_with_profile("publisher_profile", &custom_listener);

4.3 删除所属的实例,防止内存泄露

  • 先删除Publisher所创建的实例
  • 再删除对应的Publisher
// Delete the entities the Publisher created.
if (publisher->delete_contained_entities() != ReturnCode_t::RETCODE_OK)
{
    // Publisher failed to delete the entities it created.
    return;
}

// Delete the Publisher
if (participant->delete_publisher(publisher) != ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值