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. Data structs that will have multiple instances should have a key attribute or attributes. The key attribute, or attributes, distinguishes between different instances. In this lesson, you define the topicStruct element and then add a key attribute.

About this task

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.
Note: Elements of type topicStruct should be used in this context rather than elements of type idlType because when you set the type for a topic, Rhapsody® only allows you to select from among the topicStruct elements that are defined in your model.

Procedure

  1. Define the topicStruct:
    1. For the TopicDiagram diagram that you created in lesson 2, create a topicStruct element: Click the topicStruct icon 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, name the element MyTopicStruct
    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 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.
      Attributes tab
    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 > Attribute.
    2. Open the Features window for the key attribute. On the General tab, enter the following information:
      • Name the attribute myKeyAttribute
      • From the list of stereotypes, select the key stereotype.
      • Set the type to Int32, and click OK
    In the browser, MyTopicStruct resembles the following figure.
    browser window with TopicsPkg and myKeyAttribute

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.