转载于:https://blog.csdn.net/u010378559/article/details/132617041
谢谢分享!!!
目录
- EntityID
- Qos policy
- Listener
- Status
-
- Status和StatusMask的关系
- InconsistentTopicStatus
- OfferedDeadlineMissedStatus
- RequestedDeadlineMissedStatus
- OfferedIncompatibleQosStatus
- RequestedIncompatibleQosStatus
- SampleLostStatus
- SampleRejectedStatus
- DataOnReaders
- DataAvailable
- LivelinessLostStatus
- LivelinessChangedStatus
- PublicationMatchedStatus
- SubscriptionMatchedStatus
- StatusCondition
- Enabling Entities
本文主要记录Entity的概念和每个Entity的共有特性
Entity是DDS实体的抽象基类。实体的概念表示,这个对象支持Qos,有listener,有statuses。DDS中有以下实体:
在Fast DDS中,每个实体(Entity)都有一个全局唯一标识符(GUID),它是由前缀和实体ID(EntityId)组成的:
struct RTPS_DllAPI GUID_t
{
//!Guid prefix
GuidPrefix_t guidPrefix;
//!Entity id
EntityId_t entityId;
...
}
前缀通常用于标识特定的参与者(Participant),而实体ID用于标识特定的参与者下的实体,例如发布者(Publisher)、订阅者(Subscriber)、主题(Topic)等。guid生成代码:
void DomainParticipantImpl::create_instance_handle( InstanceHandle_t& handle) { using eprosima::fastrtps::rtps::octet;
<span class="token keyword">uint32_t</span> id <span class="token operator">=</span> <span class="token operator">++</span>next_instance_id_<span class="token punctuation">;</span> handle <span class="token operator">=</span> guid_<span class="token punctuation">;</span> handle<span class="token punctuation">.</span>value<span class="token punctuation">[</span><span class="token number">15</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">0x01</span><span class="token punctuation">;</span> <span class="token comment">// Vendor specific;</span> handle<span class="token punctuation">.</span>value<span class="token punctuation">[</span><span class="token number">14</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token generic-function"><span class="token function">static_cast</span><span class="token generic class-name"><span class="token operator"><</span>octet<span class="token operator">></span></span></span><span class="token punctuation">(</span>id <span class="token operator">&</span> <span class="token number">0xFF</span><span class="token punctuation">)</span><span class="token punctuation">;</span> handle<span class="token punctuation">.</span>value<span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token generic-function"><span class="token function">static_cast</span><span class="token generic class-name"><span class="token operator"><</span>octet<span class="token operator">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">(</span>id <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">)</span> <span class="token operator">&</span> <span class="token number">0xFF</span><span class="token punctuation">)</span><span class="token punctuation">;</span> handle<span class="token punctuation">.</span>value<span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token generic-function"><span class="token function">static_cast</span><span class="token generic class-name"><span class="token operator"><</span>octet<span class="token operator">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">(</span>id <span class="token operator">>></span> <span class="token number">16</span><span class="token punctuation">)</span> <span class="token operator">&</span> <span class="token number">0xFF</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
}
下面描述所有的实体都有以下特征
EntityID
每个DDS实体(如果存在RTPS实体的话则共享)都有一个唯一id,存在InstanceHandle_t对象中,作为GUID的后四个字节,可以通过API get_instance_handle()
函数获取
Qos policy
每个实体都有一个对应的Qos配置,在实体创建或之后可以通过set_qos()
函数来设置(DomainParticipant::set_qos(), Publisher::set_qos(), Subscriber::set_qos(), Topic::set_qos(), DataWriter::set_qos(), DataReader::set_qos()
)。
Listener
listener用于通知entity的状态改变。当Status改变时用于异步通知(需要通过StatusMask使能)。所有的实体都定义了抽象的listener接口,包含entity的status改变后的回调函数。用户可以从这些抽象listener中继承自己的listener,并按自己的需要实现接口。
- 有两种方式可以将实体和listener关联:
- 在创建阶段作为参数传入;
- 创建完后使用每个实体的set_listener()函数 (
DomainParticipant::set_listener(), Publisher::set_listener(), Subscriber::set_listener(), Topic::set_listener(), DataWriter::set_listener(), DataReader::set_listener()
)关联到自定义的listener。
- 每个监听器会创建一个线程
以下为类图:
使用StatusMask::none()会禁止的callback | 一直不会被禁的callback |
---|---|
on_sample_rejected() | on_participant_discovery() |
on_liveliness_changed() | onParticipantAuthentication() |
on_requested_deadline_missed() | on_subscriber_discovery() |
on_requested_incompatible_qos() | on_publisher_discovery() |
on_data_available() | on_type_discovery() |
on_subscription_matched() | on_type_dependencies_reply() |
on_sample_lost() | on_type_information_received() |
on_offered_incompatible_qos() | on_unacknowledged_sample_removed() |
on_offered_deadline_missed() | |
on_liveliness_lost() | |
on_publication_matched() | |
on_inconsistent_topic() | |
on_data_on_readers() |
Status
每个实体对象都会关联一组Status对象,这些状态值代表了entity的通信状态,如收到新的数据,发现一个新的participants或一个远端端点丢失等。Status状态的改变触发对应的listener的callback。每个entity提供一个接口用以访问它的status。
Status和StatusMask的关系
- Status是对DDS实体(如发布者、订阅者、读者或写者)当前状态的表示。例如,一个状态可以表示是否有新的数据可供读取,或者是否错过了设定的期限。
- StatusMask是一个位掩码,用于指明应用程序对哪些状态感兴趣并希望接收通知。这样,即使Status发生变化,但如果这个变化并不包括在StatusMask中,应用程序就不会收到通知。
所以,Status表示实体的当前状态,而StatusMask确定哪些状态变化会触发通知。它们是共同工作的,让程序可以灵活地管理和响应DDS通信的状态变化。
InconsistentTopicStatus
- 关注的实体:Topic
- Listener回调:on_inconsistent_topic()
- 访问接口:get_inconsistent_topic_status()
- 状态位值:0
- 用法:
OfferedDeadlineMissedStatus
RequestedDeadlineMissedStatus
OfferedIncompatibleQosStatus
RequestedIncompatibleQosStatus
SampleLostStatus
SampleRejectedStatus
DataOnReaders
DataAvailable
StatusMask中,通过使能:
inline static StatusMask data_available()
{
return StatusMask(0x00000001 << 10u);
}
用于触发on_data_available()函数,表示有数据可读。
LivelinessLostStatus
LivelinessChangedStatus
PublicationMatchedStatus
SubscriptionMatchedStatus
StatusCondition
每个实体对象都会有一个StatusCondition对象,当Status状态变化时,StatusCondition会被通知,这个功能主要是针对实体对象和Wait-set机制。
Enabling Entities
每个实体在创建时都可以使能或者不使能。这通过EntityFactoryQosPolicy。一个不使能的factory创建不使能的实体对象。一个不使能的实体对象有以下限制:
- Set/Get the entity QoS Policy.
- Set/Get the entity Listener.
- Create/Delete subentities.
- Get the Status of the entity, even if they will not change.
- Lookup operations.