|
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::EntitySnapshot > | pollBlocking (const SnapshotCallbackT &callback) |
Poll in this thread as long as callback returns true. More... | |
std::optional< wm::EntitySnapshot > | pollOnce (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... | |
A stream reading entity snapshots from the memory.
After constructing a ReadStream, polling can be started in three ways:
Definition at line 31 of file ReadStream.h.
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.
ReadStream | ( | ) |
Inizialize a ReadStream which does not represent a stream.
Definition at line 9 of file ReadStream.cpp.
ReadStream | ( | const Reader & | reader, |
const MemoryID & | queriedId, | ||
const armarx::core::time::Frequency & | maxPollFrequency = armarx::core::time::Frequency::Hertz(10) |
||
) |
Initialize a read stream.
reader | The reader to perform the queries. |
queriedId | The memory ID in which all snapshots should be processed by the stream. |
maxPollFrequency | The maximum frequency with which queries are performed. The real frequency might be lower. |
Definition at line 13 of file ReadStream.cpp.
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:
callback | Function to call on each entity snapshot. |
armarx::armem::error::ReadStreamAlreadyPolling | If the stream is already polling. |
Definition at line 37 of file ReadStream.cpp.
std::optional< wm::EntitySnapshot > pollBlocking | ( | const SnapshotCallbackT & | callback | ) |
Poll in this thread as long as callback returns true.
callback | Function to call on each entity snapshot. |
armarx::armem::error::ReadStreamAlreadyPolling | If the stream is already polling. |
Definition at line 22 of file ReadStream.cpp.
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:
callback | Function to call on each entity snapshot. |
armarx::armem::error::ReadStreamAlreadyPolling | If the stream is already polling. |
Definition at line 74 of file ReadStream.cpp.
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.