Using RSB to Receive and Publish Data » History » Version 5

« Previous - Version 5/12 (diff) - Next » - Current version
J. Wienke, 06/30/2011 03:41 PM


Using RSB to Receive and Publish Data

This wiki page describes the first steps to integrate an existing component with RSB. We assume that this component requires data for processing, which is already available in RSB and wants to provide processed data for other components via RSB.

Receiving Data

To receive data in RSB made available by other components you need to know the Scope under which the data are available, e.g. /example/informer for example dummy data. Furthermore, you need to know how the data is represented. As data is transmitted over the network and should be available in multiple programming languages, this includes two aspects:

  1. which class/type represent the data in your programming language, e.g. std::string is used for textual content in C++
  2. how is the data transmitted over the network, i.e. how is your programming language class serialized into bytes and deserialized back to a class

While knowledge about the first item is essential to use RSB, the second point is only important slightly advanced use cases, where programming language classes will be used, which are not directly known to the RSB framework. Support for primary data types like strings is already built in (see Types).

In RSB terms the programming language representation is called data type and the serialized representation is called wire schema.

So, assuming a simple component that works with a processing loop (see pseudo-code below), what are the required steps to receive data from RSB?

while (true) {

    // receive new data

    // do some heavy processing with the data to generate new results

    // inform the world about the newly generated data

}

Receiving data in RSB means listening for new data published by other components, hence the Listener class is used for this purpose. Creating client objects in RSB is the responsibility of a dedicated factory, hence we use this code to get a new listener:

Factory &factory = Factory::getInstance();
ListenerPtr listener = factory.createListener(Scope("/example/informer"));

The Listener itself notifies interested clients asynchronously each time it receives new data in the bus. To synchronize the asynchronous reception with the main loop of our component we use a SynchronizedQueue available in Robotics Systems Commons.