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. More...
 

Public Member Functions

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

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().

Definition at line 31 of file ReadStream.h.

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.

Definition at line 39 of file ReadStream.h.

Constructor & Destructor Documentation

◆ ReadStream() [1/2]

Inizialize a ReadStream which does not represent a stream.

Definition at line 9 of file ReadStream.cpp.

+ Here is the call graph for this function:

◆ 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.

Definition at line 13 of file ReadStream.cpp.

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.

Definition at line 37 of file ReadStream.cpp.

◆ 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.

Definition at line 22 of file ReadStream.cpp.

◆ 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.

Definition at line 74 of file ReadStream.cpp.

◆ stop()

void stop ( )

Stop a running polling loop.

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

Definition at line 63 of file ReadStream.cpp.


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