SkillStatusReader.cpp
Go to the documentation of this file.
1#include "SkillStatusReader.h"
2
4
6#include <RobotAPI/libraries/armem_skills/aron/Skill.aron.generated.h>
7
9{
10
12
13 std::optional<armarx::core::time::DateTime>
15 const std::string& providerName,
16 const std::string& skillName) const
17 {
19
20 qb.coreSegments()
21 .withName(properties().coreSegmentName)
23 .withName(providerName)
24 .entities()
25 .withName(skillName)
26 .snapshots()
27 .latest();
28
29 const auto qResult = memoryReader().query(qb.buildQueryInput());
30
31 if (!qResult.success)
32 {
33 ARMARX_WARNING << "[SkillStatusReader] Query failed: " << qResult.errorMessage;
34 return std::nullopt;
35 }
36
37 if (!qResult.memory.hasCoreSegment(properties().coreSegmentName))
38 {
39 return std::nullopt;
40 }
41
42 const auto& coreSegment =
43 qResult.memory.getCoreSegment(properties().coreSegmentName);
44
45 if (!coreSegment.hasProviderSegment(providerName))
46 {
47 return std::nullopt;
48 }
49
50 const auto& providerSegment = coreSegment.getProviderSegment(providerName);
51
52 if (!providerSegment.hasEntity(skillName))
53 {
54 return std::nullopt;
55 }
56
57 const auto& entity = providerSegment.getEntity(skillName);
58
59 if (entity.empty())
60 {
61 return std::nullopt;
62 }
63
64 const auto& latestSnapshot = entity.getLatestSnapshot();
65
66 std::optional<armarx::core::time::DateTime> result;
67
68 latestSnapshot.forEachInstance(
69 [&result](const auto& instance)
70 {
71 try
72 {
73 const auto dto =
74 armarx::skills::arondto::SkillStatusUpdate::FromAron(
75 instance.data());
76 result = dto.executionStartedTimestamp;
77 }
78 catch (...)
79 {
80 }
81 });
82
83 return result;
84 }
85
86 std::string
88 {
89 return "mem.skill_status.";
90 }
91
94 {
95 return {.memoryName = "Skill", .coreSegmentName = "SkillEvent"};
96 }
97
98} // namespace armarx::armem::skills::client
CoreSegmentT & getCoreSegment(const std::string &name)
Definition MemoryBase.h:134
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.
EntitySelector & withName(const std::string &name) override
SnapshotSelector & snapshots()
Start specifying entity snapshots.
Definition selectors.cpp:92
ProviderSegmentSelector & withName(const std::string &name) override
EntitySelector & entities()
Start specifying entities.
const armem::client::Reader & memoryReader() const
std::optional< armarx::core::time::DateTime > queryLatestExecutionStartedTimestamp(const std::string &providerName, const std::string &skillName) const
Query the Skill memory for the most recent executionStartedTimestamp of the given skill (by provider ...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58