1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use super::domain_participant::DomainParticipant;
use crate::{
configuration::DustDdsConfiguration,
dds_async::domain_participant_factory::DomainParticipantFactoryAsync,
domain::domain_participant_listener::DomainParticipantListener,
infrastructure::{
domain::DomainId,
error::DdsResult,
qos::{DomainParticipantFactoryQos, DomainParticipantQos, QosKind},
status::StatusKind,
},
runtime::DdsRuntime,
std_runtime::executor::block_on,
};
use tracing::warn;
/// The sole purpose of this class is to allow the creation and destruction of [`DomainParticipant`] objects.
/// [`DomainParticipantFactory`] itself has no factory. It is a pre-existing singleton object that can be accessed by means of the
/// [`DomainParticipantFactory::get_instance`] operation.
pub struct DomainParticipantFactory<R: DdsRuntime> {
participant_factory_async: &'static DomainParticipantFactoryAsync<R>,
}
impl<R: DdsRuntime> DomainParticipantFactory<R> {
/// Construct a new ['DomainParticipantFactory'] from an existing ['DomainParticipantFactoryAsync'] static reference
pub fn new(participant_factory_async: &'static DomainParticipantFactoryAsync<R>) -> Self {
Self {
participant_factory_async,
}
}
/// This operation creates a new [`DomainParticipant`] object. The [`DomainParticipant`] signifies that the calling application intends
/// to join the Domain identified by the `domain_id` argument.
/// If the specified QoS policies are not consistent, the operation will fail and no [`DomainParticipant`] will be created.
/// The value [`QosKind::Default`] can be used to indicate that the [`DomainParticipant`] should be created
/// with the default DomainParticipant QoS set in the factory. The use of this value is equivalent to the application obtaining the
/// default DomainParticipant QoS by means of the operation [`DomainParticipantFactory::get_default_participant_qos`] and using the resulting
/// QoS to create the [`DomainParticipant`].
#[tracing::instrument(skip(self, a_listener))]
pub fn create_participant(
&self,
domain_id: DomainId,
qos: QosKind<DomainParticipantQos>,
a_listener: Option<impl DomainParticipantListener + Send + 'static>,
mask: &[StatusKind],
) -> DdsResult<DomainParticipant> {
block_on(
self.participant_factory_async
.create_participant(domain_id, qos, a_listener, mask),
)
.map(DomainParticipant::new)
}
/// This operation deletes an existing [`DomainParticipant`]. This operation can only be invoked if all domain entities belonging to
/// the participant have already been deleted otherwise the error [`DdsError::PreconditionNotMet`](crate::infrastructure::error::DdsError::PreconditionNotMet) is returned. If the
/// participant has been previously deleted this operation returns the error [`DdsError::AlreadyDeleted`](crate::infrastructure::error::DdsError::AlreadyDeleted).
#[tracing::instrument(skip(self, participant))]
pub fn delete_participant(&self, participant: &DomainParticipant) -> DdsResult<()> {
block_on(
self.participant_factory_async
.delete_participant(participant.participant_async()),
)
}
/// This operation retrieves a previously created [`DomainParticipant`] belonging to the specified domain_id. If no such
/// [`DomainParticipant`] exists, the operation will return a [`None`] value.
/// If multiple [`DomainParticipant`] entities belonging to that domain_id exist, then the operation will return one of them. It is not
/// specified which one.
#[tracing::instrument(skip(self))]
pub fn lookup_participant(&self, domain_id: DomainId) -> DdsResult<Option<DomainParticipant>> {
Ok(
block_on(self.participant_factory_async.lookup_participant(domain_id))?
.map(DomainParticipant::new),
)
}
/// This operation sets a default value of the [`DomainParticipantQos`] policies which will be used for newly created
/// [`DomainParticipant`] entities in the case where the QoS policies are defaulted in the [`DomainParticipantFactory::create_participant`] operation.
/// This operation will check that the resulting policies are self consistent; if they are not, the operation will have no effect and
/// return a [`DdsError::InconsistentPolicy`](crate::infrastructure::error::DdsError::InconsistentPolicy).
#[tracing::instrument(skip(self))]
pub fn set_default_participant_qos(&self, qos: QosKind<DomainParticipantQos>) -> DdsResult<()> {
block_on(
self.participant_factory_async
.set_default_participant_qos(qos),
)
}
/// This operation retrieves the default value of the [`DomainParticipantQos`], that is, the QoS policies which will be used for
/// newly created [`DomainParticipant`] entities in the case where the QoS policies are defaulted in the [`DomainParticipantFactory::create_participant`]
/// operation.
/// The values retrieved by [`DomainParticipantFactory::get_default_participant_qos`] will match the set of values specified on the last successful call to
/// [`DomainParticipantFactory::set_default_participant_qos`], or else, if the call was never made, the default value of [`DomainParticipantQos`].
#[tracing::instrument(skip(self))]
pub fn get_default_participant_qos(&self) -> DdsResult<DomainParticipantQos> {
block_on(self.participant_factory_async.get_default_participant_qos())
}
/// This operation sets the value of the [`DomainParticipantFactoryQos`] policies. These policies control the behavior of the object
/// a factory for entities.
/// Note that despite having QoS, the [`DomainParticipantFactory`] is not an Entity.
/// This operation will check that the resulting policies are self consistent; if they are not, the operation will have no effect and
/// return a [`DdsError::InconsistentPolicy`](crate::infrastructure::error::DdsError::InconsistentPolicy).
#[tracing::instrument(skip(self))]
pub fn set_qos(&self, qos: QosKind<DomainParticipantFactoryQos>) -> DdsResult<()> {
block_on(self.participant_factory_async.set_qos(qos))
}
/// This operation returns the value of the [`DomainParticipantFactoryQos`] policies.
#[tracing::instrument(skip(self))]
pub fn get_qos(&self) -> DdsResult<DomainParticipantFactoryQos> {
block_on(self.participant_factory_async.get_qos())
}
}
impl<R: DdsRuntime> DomainParticipantFactory<R> {
/// Set the configuration of the [`DomainParticipantFactory`] singleton
pub fn set_configuration(&self, configuration: DustDdsConfiguration) -> DdsResult<()> {
block_on(
self.participant_factory_async
.set_configuration(configuration),
)
}
/// Get the current configuration of the [`DomainParticipantFactory`] singleton
pub fn get_configuration(&self) -> DdsResult<DustDdsConfiguration> {
block_on(self.participant_factory_async.get_configuration())
}
}
#[cfg(feature = "std")]
impl DomainParticipantFactory<crate::std_runtime::StdRuntime> {
/// This operation returns the [`DomainParticipantFactory`] singleton. The operation is idempotent, that is, it can be called multiple
/// times without side-effects and it will return the same [`DomainParticipantFactory`] instance.
#[tracing::instrument]
pub fn get_instance() -> &'static Self {
static PARTICIPANT_FACTORY: std::sync::OnceLock<
DomainParticipantFactory<crate::std_runtime::StdRuntime>,
> = std::sync::OnceLock::new();
PARTICIPANT_FACTORY.get_or_init(|| DomainParticipantFactory {
participant_factory_async: DomainParticipantFactoryAsync::<
crate::std_runtime::StdRuntime,
>::get_instance(),
})
}
}