< Previous | Next >

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.
  1. Add a class in the SubscriberPkg package named MyDataReaderListener: Right-click the package and select Add New > Class.
  2. Add a generalization from this class to the DataReaderListener interface that is in the DDS profile under the DDS package:
    1. Right-click MyDataReaderListener and select Add New > Relations > Generalization to open the Add Generalization window
    2. Select DataReaderListener in DDS::DDS, and then click OK
  3. Right-click MyDataReaderListener in the browser, and select Realize Base Classes... from the pop-up menu.
  4. 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.
  5. 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.
  6. To indicate that itsMyDataReaderListener is the listener of MyDataReader, add a listener dependency between MyDataReader and itsMyDataReaderListener:
    1. Right-click MyDataReader, select Add New > DDS > listener to open the Add Listener window
    2. Choose <<Select>>, and select the itsMyDataReaderListener object in the SubscriberPkg package
  7. Indicate which events to receive:
    1. Open the Features window for the itsMyDataReaderListener listener dependency
    2. On the Tags tab, in the mask field, click the ... button to open the Tag Value(s) window
    3. Click ... to create a new row, then click in the right column of the new row, select DATA_AVAILABLE_STATUS, and then click OK
    4. 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.
< Previous | Next >

Feedback