SimpleStatusHandler.cpp
Go to the documentation of this file.
2
3#include <mutex>
4#include <vector>
5
9
11
13{
14
15 void
17 {
18 const std::scoped_lock lock(callbackMutex);
19 subscriptions.requested.push_back(callback);
20 }
21
22 void
24 {
25 const std::scoped_lock lock(callbackMutex);
26 subscriptions.scheduled.push_back(callback);
27 }
28
29 void
31 {
32 const std::scoped_lock lock(callbackMutex);
33 subscriptions.reached.push_back(callback);
34 }
35
36 void
38 {
39 const std::scoped_lock lock(callbackMutex);
40 subscriptions.preempted.push_back(callback);
41 }
42
43 void
45 {
46 const std::scoped_lock lock(callbackMutex);
47 subscriptions.released.push_back(callback);
48 }
49
50 void
52 {
53 const std::scoped_lock lock(callbackMutex);
54 subscriptions.aborted.push_back(callback);
55 }
56
57 void
59 {
60 const std::scoped_lock lock(callbackMutex);
61 subscriptions.any.push_back(callback);
62 }
63
64 void
66 {
67 // ARMARX_INFO (not DEBUG) on purpose, and here rather than in each skill: paired with the
68 // publish-side log in the scheduler's status writer, the combined log shows the memory
69 // round trip for every transition, for both delivery modes and every client.
70 ARMARX_INFO << "Received gaze target status "
71 << QUOTED(gaze_targets::TargetStatusNames.to_name(status.status)) << " for "
72 << QUOTED(status.gazeTargetID.str()) << " at " << armarx::Clock::Now() << ".";
73
74 const std::vector<Callback> callbacks = [&]()
75 {
76 const std::scoped_lock lock(callbackMutex);
77
78 std::vector<Callback> matching = subscriptions.any;
79
80 const std::vector<Callback>& specific = [&]() -> const std::vector<Callback>&
81 {
82 switch (status.status)
83 {
85 return subscriptions.requested;
87 return subscriptions.scheduled;
89 return subscriptions.reached;
91 return subscriptions.preempted;
93 return subscriptions.released;
95 return subscriptions.aborted;
96 }
97
98 return subscriptions.any;
99 }();
100
101 matching.insert(matching.end(), specific.begin(), specific.end());
102
103 return matching;
104 }();
105
106 // Called without the lock: a callback may well register another one, or block.
107 for (const auto& callback : callbacks)
108 {
109 callback(status);
110 }
111 }
112
113} // namespace armarx::view_selection::client
#define QUOTED(x)
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
void onReleased(const Callback &callback) override
void onAny(const Callback &callback) override
Called for every update, whatever its status.
void handleStatus(const gaze_targets::GazeTargetStatus &status)
Logs the update and hands it to the matching callbacks.
void onScheduled(const Callback &callback) override
void onAborted(const Callback &callback) override
void onRequested(const Callback &callback) override
void onReached(const Callback &callback) override
void onPreempted(const Callback &callback) override
std::function< void(const gaze_targets::GazeTargetStatus &)> Callback
Business Object (BO) class of GazeTargetStatus: the lifecycle of one gaze target request,...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:179
const simox::meta::EnumNames< TargetStatus > TargetStatusNames
@ Scheduled
submitted to the low-level controller
@ Aborted
left the queue without ever being reached, or the target is out of reach
@ Reached
the gaze residual settled below the threshold
@ Released
left the queue having been reached (duration elapsed, or superseded afterwards)
@ Preempted
lost the active slot but stays in the queue and may be scheduled again
@ Requested
admitted to the scheduler's queue, waiting for scheduling