< Previous | Next >

Lesson 3: Define the topicStruct and add a key attribute

Because Data Distribution Service for Real-Time Systems (DDS) applications share data, you must define the shared data for your application. In addition, you must set the key attribute for your DDS application. This attribute indicates that topics that declare topicStruct as their type might contain multiple data. The key attribute, or attributes, distinguish between different instances. In this lesson, you define the topicStruct element and then add the key attribute.
A topicStruct is a group of fields, or a struct, that defines a single instance in a topic. In a condition where its topicStruct has a key, a topic can consist of multiple instances. A key can be one field, or attribute, in the topicStruct or a combination of multiple fields. When you create a standard topic, you must add the name of the topic type. For the purposes of this tutorial, the type is a struct.
  1. Define the topicStruct:
    1. For the TopicDiagram diagram that you created in lesson 2, create a topicStruct element: Click the topicStruct icon on the Drawing toolbar, and then click the drawing area for the diagram
    2. Open the Features window for the topicStruct element. On the General tab, enter the following information:
      • Name the element MyTopicStruct
      • In the Kind field, select Structure
    3. On the Attributes tab, click <New> to add each of the following attributes. Select the corresponding type from the Type field when possible.
      • myBooleanAttribute, with a type of boolean
        For this attribute, you have to set the type manually:
        1. Open the Features window for the attribute by clicking the Invoke Feature Dialog icon
        2. Clear the Use existing type check box
        3. In the C++ Declaration field, type boolean, and then click OK
      • myLongAttribute, with a type of long
      • myStringAttribute, with a type of string. To set the type, use the same method as you used for myBooleanAttribute.
      • myDoubleAttribute, with a type of double
      • myLongSequenceAttribute, with a type of long and with multiplicity set to *. To set the multiplicity, open the Features window for this attribute; in the Multiplicity field, select *; and then click OK

      Your Attributes tab resembles the following figure.

    4. Close the Features window for the topicStruct.
  2. Add a key attribute:
    Note: Although a key can be a combination of several attributes, this tutorial uses only one key attribute.
    1. In the browser, right-click the MyTopicStruct topicStruct and click Add New > DDS > key
    2. Open the Features window for the key attribute. On the General tab, enter the following information:
      • Name the attribute myKeyAttribute
      • Set the type to long, and click OK

    In the browser, MyTopicStruct resembles the following figure.

Lesson checkpoint

In this lesson, you learned how to define the MyTopicStruct topicStruct and to add a key attribute.
In the next lesson, you will create a topic.
< Previous | Next >

Feedback