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;
}