< Previous | Next >

Lesson 7: Add a domain participant for your publisher entity

In this lesson, you add a domain participant for your MyPublisher publisher entity.
  1. Right-click the PublisherPkg package and select Add New > DDS > domainParticipant.
  2. Open the Features window for the domain participant element and enter the following information:
    1. On the General tab, name the element MyPublishingApplication. Notice that by default the same name has also been entered in the Directory field, and Executable has been selected in the Type area.
    2. On the Scope tab, select PublisherPkg. If other check boxes are selected, clear them. Click OK.
  3. Specify the configuration for the MyPublishingApplication domain participant:
    1. Open the Features window for the DefaultConfig configuration under MyPublishingApplication
    2. On the Initialization tab, expand PublisherPkg and select MyPublisher
    3. On the Settings tab, select the MSVC9 or Linux environment, and then click OK
  4. Add a dependency from the MyPublishingApplication domain participant to the MyTopicStructLib domain participant:
    1. Right-click MyPublishingApplication and select Add New > Relations > Dependency
    2. On the Add Dependency window, select MyTopicStructLib in TopicsPkg
  5. From the browser, open the Features window for the dependency and enter the following information:
    1. On the General tab, in the Stereotype field, select Usage in PredefinedTypes
    2. Make sure that the Usage field is set to Specification, and then click OK. This dependency allows the functions of MyTopicStructLib to be used while MyTopicStruct is registered and MyTopic is created. The dependency also provides functions from MyTopicStructLib to create MyDataWriter.
  6. Generate code: Select Code > Generate > DefaultConfig.
    Note: Because you created the PublisherPkg package in this lesson, the DefaultConfig configuration is already set as the active configuration.
  7. Under the MyPublishingApplication domain participant, right-click the DefaultConfig configuration and select Edit Configuration Main File. Notice that code generation created a singleton class called MyPublishingApplicationDP. This class is a wrapper to the DDS::DomainParticipant entity. It supplies the following API:
    • DDS::DomainParticipant* getDomainParticipant(): Gets the DDS::DomainParticipant member of this class
    • DDS::TopicDescription* lookupTopicDescription(char* topicName): A wrapper to DDS standard API call DDS::DomainParticipant::lookup_topicdescription
    • static MyPublishingApplicationDP* instance(): The singleton operation that allows the singleton instance of this class to be received
In the implementation main file, you can see the following actions in the constructor of MyPublishingApplicationDP:

The last two elements are a result of the notation that MyDataWriter, which is in the scope of the domain participant component, updates MyTopic.

As the diagram shape of the publisher entity implies, the generated code for publisher entity is a class. This class contains the attribute of a DDS::Publisher pointer that is initialized during the construction of a new class instance. It also contains a MyTopicStructDataWriter pointer named MyDataWriter that represents the dataWriter element that you created. The MyTopicStructDataWriter pointer is defined in the files that are generated from the DDSMyTopicStructLib.idl file in the domain participant component named MyTopicStructLib.

If you edit the code of MyPublisher, you see that during its construction, MyPublishingApplicationDP is called to retrieve its DDS::DomainParticipant member so that the DDS::Publisher element can be created. You also find this operation: DDS::ReturnCode_t publishMyDataWriter(const MyTopicStruct& data);

This operation is a wrapper to MyTopicStructDataWriter::write. This function was generated from the DDSMyTopicStructLib.idl file that was generated.

Lesson checkpoint

In this lesson, you learned how to add a domain participant to your MyPublisher publisher entity.
In the next lesson, you will add some code in order to publish data to your MyTopic topic element.
< Previous | Next >

Feedback