Aug 10, 2010

My take on the new DDS C++ PSM

It has been a while since we've started the standardization of a new C++ API for DDS (namely the ISO C++ PSM for DDS). Now we are getting close, on principle the standard should be voted during the September meeting, yet there are still a few points to resolve among submitters. If I look back at the IDL-derived C++ API and what will be the new, SimD-inspired, API I believe the result is great. In this and subsequent post, I'll share with you an outlook of what our current proposal for the final C++ API standard looks like. Your comments will be useful as they might be able to still influence how the API will look like.

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+

No comments: