Jump to content
OpenSplice DDS Forum
Jonnn

iso library object creation

Recommended Posts

Hello,

I want to have an class that wraps isocpp dds objects, to encapsulate the actual DDS interface away from my code.

The only way I can find of doing this with the isocpp libraries is to do it in the constructor list of my class; e.g:

 

in hpp:

dds::domain::DomainParticipant myparticipant

dds::sub::Subscriber mysubscriber

dds::topic::Topic<...> mytopic

dds::sub::DataReader<...> myreader

 

in cpp:

MyWrapperClass::MyWrapperClass() :

    myparticipant(org::opensplice::domain::default_id(), dds::domain::DomainParticipant::default_participant_qos),

    mysubscriber(myparticipant)

    mytopic(myparticipant, "topicname")

    myreader(mysubscriber, mytopic)

{

}

 

 

So, this is workable, but not very nice. In particular

    - it gets cumbersome as the number of topics increases and become more complicated

    - the functions throw exceptions. In a constructor, this is never a good thing and creates new nightmares.

 

You don't appear to be able to do

mytopic = new dds::topic::Topic<...>(...)

or

mytopic = tmpTopic

because the operators appear to have been made private.

 

Is there a better way of doing this encapsulating?

 

Kind Regards,

Jon

 

 

 

 

 

Share this post


Link to post
Share on other sites

Hello Jon,

 

Yes, new is made private. However, you can still create dds objects at a later point in time.

 

dds::topic::topic<...> mytopic(dds::core::null);

...

mytopic = dds::topic::topic<...>(...);

 

It acts a bit like a shared pointer, which means that the created topic will be destroyed when mytopic goes out of scope or is assigned a new topic.

 

Hope this helps.

Share this post


Link to post
Share on other sites

Thanks. I'll give that a whirl.

It might help me catch some of my other problems, if I can get it out of the constructor list.

Jon.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×