MemoryPolling.cpp
Go to the documentation of this file.
1#include "MemoryPolling.h"
2
3#include <string>
4
9
13
15
17{
18
19 namespace
20 {
21 constexpr int pollIntervalMs = 100;
22 }
23
24 MemoryPolling::MemoryPolling(const std::string& providerSegmentName,
26 providerSegmentName(providerSegmentName),
27 memoryNameSystem(mns),
28 lastPolled(armarx::Clock::Now())
29 {
30 memoryReader = memoryNameSystem.getReader(
32
33 ARMARX_INFO << "Polling gaze target status updates for provider segment "
34 << QUOTED(providerSegmentName) << " every " << pollIntervalMs << " ms.";
35
36 task = new armarx::PeriodicTask<MemoryPolling>(this, &MemoryPolling::poll, pollIntervalMs);
37 task->start();
38 }
39
41 {
42 if (task and task->isRunning())
43 {
44 task->stop();
45 }
46 }
47
48 void
49 MemoryPolling::poll()
50 {
52
54 qb.coreSegments()
57 .withName(providerSegmentName)
58 .entities()
59 .all()
60 .snapshots()
61 .timeRange(lastPolled, now);
62
63 const armem::client::QueryResult result = memoryReader.query(qb.buildQueryInput());
64
65 if (not result.success)
66 {
68 << "Failed to poll gaze target status updates: " << result.errorMessage;
69 return;
70 }
71
72 // Advance past the window we just consumed. The extra microsecond keeps a snapshot exactly
73 // on the boundary from being dispatched twice.
74 lastPolled = now + armarx::Duration::MicroSeconds(1);
75
76 handleMemory(result.memory);
77 }
78
79} // namespace armarx::view_selection::client
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
#define QUOTED(x)
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
The periodic task executes one thread method repeatedly using the time period specified in the constr...
The memory name system (MNS) client.
QueryResult query(const QueryInput &input) const
Perform a query on the WM.
Definition Reader.cpp:119
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition Builder.h:22
CoreSegmentSelector & coreSegments()
Start specifying core segments.
Definition Builder.cpp:42
CoreSegmentSelector & withName(const std::string &name) override
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition selectors.cpp:92
ProviderSegmentSelector & withName(const std::string &name) override
EntitySelector & entities()
Start specifying entities.
SnapshotSelector & timeRange(Time min, Time max)
Definition selectors.cpp:46
Clock to get date/time from a specific clock type or wait for certain durations or until certain date...
Definition Clock.h:26
Represents a point in time.
Definition DateTime.h:25
MemoryPolling(const std::string &providerSegmentName, armem::client::MemoryNameSystem &mns)
void handleMemory(const armem::wm::Memory &memory)
Dispatches every GazeTargetStatus instance found, oldest first.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:179
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:191
const std::string GazeTargetStatusCoreSegmentName
Lifecycle of the requests in GazeTarget.
Definition constants.h:35
This file offers overloads of toIce() and fromIce() functions for STL container types.
Result of a QueryInput.
Definition Query.h:51
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58