MemoryStatusPublisher.h
Go to the documentation of this file.
1#pragma once
2
3#include <experimental/memory>
4#include <functional>
5#include <map>
6#include <mutex>
7#include <string>
8
10
14
16{
17
18 /**
19 * @brief Accumulates each target's lifecycle and commits it to View/GazeTargetStatus.
20 *
21 * Every transition publishes a snapshot carrying *all* timestamps seen so far. A client that
22 * only ever observes the final snapshot -- a poller, or anyone that was slow -- can therefore
23 * still tell whether the target was reached before it ended. A pure event stream would lose
24 * that.
25 */
27 {
28 public:
29 explicit MemoryStatusPublisher(
31
32 void requested(const armem::MemoryID& gazeTargetID,
33 const armarx::DateTime& creationTimestamp) override;
34 void scheduled(const armem::MemoryID& gazeTargetID) override;
35 void reached(const armem::MemoryID& gazeTargetID,
36 const gaze_controller::GazeResidual& residual) override;
37 void preempted(const armem::MemoryID& gazeTargetID, const std::string& reason) override;
38 void released(const armem::MemoryID& gazeTargetID, const std::string& reason) override;
39 void aborted(const armem::MemoryID& gazeTargetID, const std::string& reason) override;
40
41 bool wasReached(const armem::MemoryID& gazeTargetID) const override;
42
43 private:
44 /// Applies `mutate` to the target's accumulated lifecycle, then publishes the result.
45 /// Terminal states drop the accumulator entry so it cannot grow without bound.
46 void publish(const armem::MemoryID& gazeTargetID,
47 const std::function<void(gaze_targets::GazeTargetStatus&)>& mutate);
48
50
51 mutable std::mutex mutex;
52
53 std::map<armem::MemoryID, gaze_targets::GazeTargetStatus> lifecycles;
54 };
55
56} // namespace armarx::view_selection::gaze_scheduler
Represents a point in time.
Definition DateTime.h:25
void aborted(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Left the queue without ever being reached. Terminal, and a failure.
void preempted(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Lost the active slot but stays in the queue. Not terminal.
void requested(const armem::MemoryID &gazeTargetID, const armarx::DateTime &creationTimestamp) override
Admitted to the scheduler's queue.
void scheduled(const armem::MemoryID &gazeTargetID) override
Submitted to the low-level controller.
void released(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Left the queue having been reached. Terminal, and a success for whoever asked.
void reached(const armem::MemoryID &gazeTargetID, const gaze_controller::GazeResidual &residual) override
The gaze settled on the target.
bool wasReached(const armem::MemoryID &gazeTargetID) const override
Whether this target was reached at any point.
MemoryStatusPublisher(std::experimental::observer_ptr< memory::client::status::Writer > writer)
Business Object (BO) class of GazeTargetStatus: the lifecycle of one gaze target request,...
How far the gaze currently is from a target.