Repository navigation
Expand file tree
/
Copy pathlifecycle.cpp
More file actions
45 lines (39 loc) · 1.65 KB
/
Copy pathlifecycle.cpp
File metadata and controls
45 lines (39 loc) · 1.65 KB
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
#include <iostream>
#include <gen/TempControl_DCPS.hpp>
using namespace dds::core;
using namespace dds::domain;
using namespace dds::pub;
int main(int, char**) {
dds::domain::DomainParticipant dp(0);
dds::topic::Topic<tutorial::TempSensorType> topic(dp, "TempSensorTopic");
dds::pub::Publisher pub(dp);
//[NOTE #1]: Avoid topic-instance dispose on unregister
dds::pub::qos::DataWriterQos dwqos = pub.default_datawriter_qos()
<< dds::core::policy::WriterDataLifecycle::ManuallyDisposeUnregisteredInstances();
//[NOTE #2]: Creating DataWriter with custom QoS.
// QoS will be covered in detail in article #4.
dds::pub::DataWriter<tutorial::TempSensorType> dw(pub, topic, dwqos);
tutorial::TempSensorType data(0, 24.3F, 0.5F, tutorial::TemperatureScale::CELSIUS);
dw.write(data);
tutorial::TempSensorType key;
short id = 1;
key.id(id);
//[NOTE #3] Registering topic-instance explicitly
dds::core::InstanceHandle h1 = dw.register_instance(key);
id = 2;
key.id(id);
dds::core::InstanceHandle h2 = dw.register_instance(key);
id = 3;
key.id(id);
dds::core::InstanceHandle h3 = dw.register_instance(key);
dw << tutorial::TempSensorType(1, 24.3F, 0.5F, tutorial::TemperatureScale::CELSIUS);
dw << tutorial::TempSensorType(2, 23.5F, 0.6F, tutorial::TemperatureScale::CELSIUS);
dw << tutorial::TempSensorType(3, 21.7F, 0.5F, tutorial::TemperatureScale::CELSIUS);
// [NOTE #4]: unregister topic-instance with id=1
dw.unregister_instance(h1);
// [NOTE #5]: dispose topic-instance with id=2
dw.dispose_instance(h2);
//[NOTE #6]:topic-instance with id=3 will be unregistered as
// result of the dw object destruction
return 0;
}