ReadStream Class Reference

A stream reading entity snapshots from the memory. More...

#include <RobotAPI/libraries/armem/client/ReadStream.h>

Public Types

using SnapshotCallbackT = std::function<bool(const wm::EntitySnapshot&)>
 Callback called on each entity snapshot in the queried ID.
 

Public Member Functions

void pollAsync (const SnapshotCallbackT &callback)
 Poll in a new thread as long as callback returns true.
 
std::optional< wm::EntitySnapshot > pollBlocking (const SnapshotCallbackT &callback)
 Poll in this thread as long as callback returns true.
 
std::optional< wm::EntitySnapshot > pollOnce (const SnapshotCallbackT &callback)
 Perform one query and call the callbacks on each snapshot.
 
 ReadStream ()
 Inizialize a ReadStream which does not represent a stream.
 
 ReadStream (const Reader &reader, const MemoryID &queriedId, const armarx::core::time::Frequency &maxPollFrequency=armarx::core::time::Frequency::Hertz(10))
 Initialize a read stream.
 
void stop ()
 Stop a running polling loop.
 

Detailed Description

A stream reading entity snapshots from the memory.

After constructing a ReadStream, polling can be started in three ways:

  1. Run a polling loop in this thread, blocking execution until terminated. See pollBlocking().
  2. Run a polling loop in a new, separate thread, until it is stopped via stop(). See pollAsync() and stop().
  3. Perform a single query and process the result, embedded in your own loop or other control flow logic. See pollOnce().

Member Typedef Documentation

◆ SnapshotCallbackT

using SnapshotCallbackT = std::function<bool(const wm::EntitySnapshot&)>

Callback called on each entity snapshot in the queried ID.

If it returns false, the stream is stopped.

Constructor & Destructor Documentation

◆ ReadStream() [1/2]

Inizialize a ReadStream which does not represent a stream.

◆ ReadStream() [2/2]

ReadStream ( const Reader & reader,
const MemoryID & queriedId,
const armarx::core::time::Frequency & maxPollFrequency = armarx::core::time::Frequency::Hertz(10) )

Initialize a read stream.

Parameters
readerThe reader to perform the queries.
queriedIdThe memory ID in which all snapshots should be processed by the stream.
maxPollFrequencyThe maximum frequency with which queries are performed. The real frequency might be lower.

Member Function Documentation

◆ pollAsync()

void pollAsync ( const SnapshotCallbackT & callback)

Poll in a new thread as long as callback returns true.

Note that callback will be called in a separate thread, so take care of synchronizing access to variables in the callback appropriately.

Roughly equivalent to:

std::thread thread([]() { stream.pollBlocking(); });
Parameters
callbackFunction to call on each entity snapshot.
Exceptions
armarx::armem::error::ReadStreamAlreadyPollingIf the stream is already polling.

◆ pollBlocking()

std::optional< wm::EntitySnapshot > pollBlocking ( const SnapshotCallbackT & callback)

Poll in this thread as long as callback returns true.

Parameters
callbackFunction to call on each entity snapshot.
Returns
The snapshot object that returns false.
Exceptions
armarx::armem::error::ReadStreamAlreadyPollingIf the stream is already polling.

◆ pollOnce()

std::optional< wm::EntitySnapshot > pollOnce ( const SnapshotCallbackT & callback)

Perform one query and call the callbacks on each snapshot.

This allows you to define your own loop, for example:

bool condition = true;
while (condition)
{
auto snapshot = stream.pollOnce(callback);
...
if (...)
{
condition = false;
}
}
Parameters
callbackFunction to call on each entity snapshot.
Exceptions
armarx::armem::error::ReadStreamAlreadyPollingIf the stream is already polling.

◆ stop()

void stop ( )

Stop a running polling loop.

If a polling thread has been started by pollAsync() before, joins the thread.


The documentation for this class was generated from the following files: