Skip to content

Commit

Permalink
Improved Listening to Discovery Chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeMartin committed Nov 4, 2016
1 parent 8f05c9e commit ff4b992
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,40 @@ You can use this sample XML as a base for building your configuration files:
</participant>
</staticdiscovery>
Making the most out of the built-in protocols
---------------------------------------------
Subscribing to Discovery Topics
-------------------------------

As specified in the Built-In protocols section, the Participant or RTPS Participant has a series of meta-data endpoints
for use during the discovery process. It is possible to create a custom listener that listens
to the Endpoint Discovery Protocol meta-data. This allows you to create your own network analysis tools.

.. code-block:: c++

CustomReaderListener *my_readerListenerSub = new(CustomReaderListener); // Custom user ReaderListeners
/* Create Custom user ReaderListeners */
CustomReaderListener *my_readerListenerSub = new(CustomReaderListener);
CustomReaderListener *my_readerListenerPub = new(CustomReaderListener);
std::pair<StatefulReader*,StatefulReader*> EDPReaders = my_participant->getEDPReaders(); //Get access to the EDP endpoints
EDPReaders.first()->setListener(my_readerListenerSub); // Perform attachments
/* Get access to the EDP endpoints */
std::pair<StatefulReader*,StatefulReader*> EDPReaders = my_participant->getEDPReaders();
/* Install the listeners for Subscribers and Publishers Discovery Data*/
EDPReaders.first()->setListener(my_readerListenerSub);
EDPReaders.second()->setListener(my_readerListenerPub);
/* ... */
/* Custom Reader Listener onNewCacheChangeAdded*/
void onNewCacheChangeAdded(RTPSReader * reader, const CacheChange_t * const change)
{
(void)reader;
if (change->kind == ALIVE) {
WriterProxyData proxyData;
CDRMessage_t tempMsg;
tempMsg.msg_endian = change->serializedPayload.encapsulation ==
PL_CDR_BE ? BIGEND : LITTLEEND;
tempMsg.length = change->serializedPayload.length;
memcpy(tempMsg.buffer, change->serializedPayload.data, tempMsg.length);
if (proxyData.readFromCDRMessage(&tempMsg)) {
cout << proxyData.topicName();
cout << proxyData.typeName();
}
}

The callbacks defined in the ReaderListener you attach to the EDP will execute for each data message after
the built-in protocols have processed it.
Expand Down

0 comments on commit ff4b992

Please sign in to comment.