Lesson 11: Listen to Data Distribution Service for Real-Time
Systems events related to the dataReader entity
To receive an event when your MyTopic topic element is
updated, attach a listener to your MyDataReader dataReader. In this
lesson, you learn how to listen to DDS events that are related to
your dataReader.
Add a class in the SubscriberPkg package named MyDataReaderListener:
Right-click the package and select Add New > Class.
Add a generalization from this class to the DataReaderListener
interface that is in the DDS profile under the DDS package:
Right-click MyDataReaderListener and
select Add New > Relations > Generalization to open the Add
Generalization window
Select DataReaderListener in DDS::DDS,
and then click OK
Right-click MyDataReaderListener in the browser, and select Realize
Base Classes... from the pop-up menu.
When the Implement Base Classes window opens, select the
DataReaderListener interface, and click OK. All of
the operations from the interface should now appear as operations
of the MyDataReaderListener class.
In the SubscriberPkg package, create an object and on its
Features window, on the General tab, in the Type field,
select MyDataReaderListener in SubscriberPkg,
and click OK. If you are
asked if you want to continue, click Yes. The object is automatically
named itsMyDataReaderListener.
To indicate that itsMyDataReaderListener is the listener
of MyDataReader, add a listener dependency between MyDataReader and
itsMyDataReaderListener:
Right-click MyDataReader, select Add
New > DDS > listener to open the Add Listener window
Choose <<Select>>, and
select the itsMyDataReaderListener object in the SubscriberPkg package
Indicate which events to receive:
Open the Features window for the itsMyDataReaderListener
listener dependency
On the Tags tab, in the mask field,
click the ... button to open the Tag Value(s) window
Click ... to create a new row,
then click in the right column of the new row, select DATA_AVAILABLE_STATUS,
and then click OK
Click OK to close the Features
window
Lesson checkpoint
In this lesson, you learned how to listen to DDS events
related to your MyDataReader dataReader.
In the next lesson, you will add code to receive updates
on your MyTopic topic element.