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
- 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, name the element
MyTopicStruct
- 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
- 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.