To start with, let's take a look at a simple writer:
int main(int, char**) {
int domainId = 0;
try {
// Create Domain + Topic + Pub
dds::domain::DomainParticipant dp(domainID);
dds::topic::Topic<MiB> topic("MessageInABottle", dp);
dds::pub::Publisher pub(dp);
// Create DataWriter
dds::pub::DataWriter<MiB> dw(pub);
// Write Sample
MiB sample(1, "Hello");
// You can write like this...
dw.write(sample);
// ...and like this (and there is more...)
dw << sample;
}
catch (const dds::core::Exception& e) {
std::cout << e << std::endl;
}
return 0;
}
Now we can look at a more "complex" example in which we set custom QoS on the Publisher and DataWriter:
int main(int, char**) {
int domainId = 0;
try {
// Create Domain + Topic + Pub
dds::domain::DomainParticipant dp(domainID);
dds::topic::Topic<MiB> topic("MessageInABottle", dp);
// Publisher
dds::qos::PublisherQos pubQos;
dds::qos::Partition partition("TheCoolAPI");
pubQos << partition;
dds::pub::Publisher pub(pubQos, dp);
// Subscriber
dds::qos::SubscriberQos subQos;
subQos << partition;
dds::sub::Subscriber sub(subQos, dp);
dds::qos::DataWriterQos dwQos;
dwQos << Reliable() << TransientDurability();
dds::pub::DataWriter<MiB> dw(topic, dwQos, pub);
MiB mib;
mib.msg() = "ciao";
// You can write like this...
dw.write(mib);
// ...and like this (and there is more...)
dw << mib;
}
catch (const dds::core::Exception& e) {
std::cout << e << std::endl;
}
return 0;
}
That's it for this post. I'll let you know digest the code and perhaps give some comments on how you like it. Next will be a post showing the reader side.
A+