DDS(Data Distribution Service)——Domain

DDS(Data Distribution Service)——Domain

1.什么是Domain

一个Domain代表一个数据平台,它们共享一个通信基础设施但不同实体之间又被逻辑分离,这个就像是Vlan一样,每个Vlan有自己的域,不会互相干扰。

每一个Domain都有唯一的标识符——domainId,是用uint32实现的,当应用程序使用相同domainId的Domain时才能相互通信。

当应用想加入到一个Domain中时,首先就要通过单例工厂 DomainParticipantFactory 创建一个拥有特定domainId 的DomainParticipant ,进而创建相应的Topic、Publisher、Subscriber等。

在这里插入图片描述

2.DomainParticipant介绍

一个DomainParticipant是一个Domain的进入点,只有通过DomainParticipant应用程序才可以通讯,作为DDS的实体他可以被DomainParticipantQos所配置,与DomainParticipantListener监听。

3.DomainParticipantQos使用

简单的来说DomainParticipantQos就是一个DomainParticipant的配置项,在创建一个新的DomainParticipant需要一并传入DomainParticipantQos。可以使用默认的DomainParticipantQos,可以从DomainParticipant的实例中获取,也可以使用特殊值:PARTICIPANT_QOS_DEFAULT

// Create a DomainParticipant with default DomainParticipantQos
DomainParticipant* participant =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
    // Error
    return;
}

// Get the current QoS or create a new one from scratch
DomainParticipantQos qos = participant->get_qos();

// Modify QoS attributes
qos.entity_factory().autoenable_created_entities = false;

// Assign the new Qos to the object
participant->set_qos(qos);

使用Default DomainParticipantQos,修改默认的DomainParticipantQos不会影响已经实例化的DomainParticipant中的Qos

// Get the current QoS or create a new one from scratch
DomainParticipantQos qos_type1 = DomainParticipantFactory::get_instance()->get_default_participant_qos();

// Modify QoS attributes
// (...)

// Set as the new default TopicQos
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(qos_type1) !=
        ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}

// Create a DomainParticipant with the new default DomainParticipantQos.
DomainParticipant* participant_with_qos_type1 =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant_with_qos_type1)
{
    // Error
    return;
}

// Get the current QoS or create a new one from scratch
DomainParticipantQos qos_type2;

// Modify QoS attributes
// (...)

// Set as the new default TopicQos
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(qos_type2) !=
        ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}

// Create a Topic with the new default TopicQos.
DomainParticipant* participant_with_qos_type2 =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant_with_qos_type2)
{
    // Error
    return;
}

// Resetting the default DomainParticipantQos to the original default constructed values
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(PARTICIPANT_QOS_DEFAULT)
        != ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}

// The previous instruction is equivalent to the following
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(DomainParticipantQos())
        != ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值