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.
- Define the topicStruct:
- 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
- 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
- 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:
- Open the Features window for the attribute by clicking the Invoke
Feature Dialog icon

- Clear the Use existing type check box
- 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.
- Close the Features window for the topicStruct.
- Add a key attribute:
Note: Although a key can
be a combination of several attributes, this tutorial uses only one
key attribute.
- In the browser, right-click the MyTopicStruct topicStruct
and click
- 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.