ComposedSkillLibrarySegment.cpp
Go to the documentation of this file.
2
3#include <optional>
4
5#include <SimoxUtility/algorithm/string.h>
6
8
14#include <RobotAPI/libraries/armem_skills/aron/Skill.aron.generated.h>
18#include <RobotAPI/libraries/skills/core/aron/FluxioSkill.aron.generated.h>
19
21{
27
28 void
30 const std::string& prefix)
31 {
32 this->setDefaultMaxHistorySize(maxHistorySize);
33 Base::defineProperties(defs, prefix);
34 }
35
36 void
41
42 void
43 ComposedSkillLibraryCoreSegment::addSkill(const skills::manager::arondto::FluxioSkill& skill)
44 {
45 // add skills
46 armem::MemoryID provId = id().withProviderSegmentName(skill.skillProviderId.id);
47
48 armem::Commit commit;
49 armem::EntityUpdate& entityUpdate = commit.add();
50 entityUpdate.confidence = 1.0;
51 entityUpdate.referencedTime = armem::Time::Now();
52 entityUpdate.sentTime = armem::Time::Now();
53 entityUpdate.arrivedTime = armem::Time::Now();
54 entityUpdate.instancesData = {skill.toAron()};
55 entityUpdate.entityID = provId.withEntityName(skill.id);
56
57 // Commit data to memory with locking to prevent race conditions with concurrent queries.
58 iceMemory.commitLocking(commit);
59 }
60
61 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
63 {
64 std::vector<skills::manager::arondto::FluxioSkill> ret;
68 if (!qresult.success)
69 {
70 ARMARX_WARNING << "Query failed: " << qresult.errorMessage;
71 return std::nullopt;
72 }
73
74 const armem::wm::Memory& data = qresult.memory;
75
76 data.forEachInstance(
77 [&ret, this](const armem::wm::EntityInstance& instance)
78 {
79 // dataAs<>() throws on type mismatch / corrupted aron data.
80 // Skip the bad entry instead of crashing getSkills().
81 skills::manager::arondto::FluxioSkill skill;
82 try
83 {
84 skill = instance.dataAs<skills::manager::arondto::FluxioSkill>();
85 }
86 catch (const std::exception& e)
87 {
88 ARMARX_WARNING << "Skipping malformed FluxioSkill instance: "
89 << e.what();
90 return;
91 }
92 if (skill.deleted)
93 {
94 return;
95 }
96 ret.push_back(skill);
97 });
98
99 return ret;
100 }
101
102 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
103 ComposedSkillLibraryCoreSegment::getSkillsOfProvider(const std::string& providerId) const
104 {
105 std::vector<skills::manager::arondto::FluxioSkill> ret;
107 qb.allLatestInProviderSegment(id().withProviderSegmentName(providerId));
109 if (!qresult.success)
110 {
111 ARMARX_WARNING << "Query failed: " << qresult.errorMessage;
112 return std::nullopt;
113 }
114
115 const armem::wm::Memory& data = qresult.memory;
116
117 data.forEachInstance(
118 [&ret, this](const armem::wm::EntityInstance& instance)
119 {
120 // dataAs<>() throws on type mismatch / corrupted aron data.
121 // Skip the bad entry instead of crashing getSkillsOfProvider().
122 skills::manager::arondto::FluxioSkill skill;
123 try
124 {
125 skill = instance.dataAs<skills::manager::arondto::FluxioSkill>();
126 }
127 catch (const std::exception& e)
128 {
129 ARMARX_WARNING << "Skipping malformed FluxioSkill instance: "
130 << e.what();
131 return;
132 }
133 if (skill.deleted)
134 {
135 return;
136 }
137 ret.push_back(skill);
138 });
139
140 return ret;
141 }
142} // namespace armarx::skills::segment
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
AronDtoT dataAs() const
Get the data converted to a generated Aron DTO class.
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition Builder.h:22
void allLatestInProviderSegment(const MemoryID &providerSegmentID)
Get latest snapshots from all entities in a provider segment.
Definition Builder.cpp:105
void allLatestInCoreSegment(const MemoryID &coreSegmentID)
Get latest snapshots from all entities in all provider segments in a core segment.
Definition Builder.cpp:79
Helps connecting a Memory server to the Ice interface.
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Client-side working entity instance.
Client-side working memory.
static DateTime Now()
Definition DateTime.cpp:51
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > getSkillsOfProvider(const std::string &providerId) const
ComposedSkillLibraryCoreSegment(armem::server::MemoryToIceAdapter &iceMemory)
void addSkill(const skills::manager::arondto::FluxioSkill &skill)
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > getSkills() const
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
This file is part of ArmarX.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
An update of an entity for a specific point in time.
Definition Commit.h:26
float confidence
An optional confidence, may be used for things like decay.
Definition Commit.h:43
MemoryID entityID
The entity's ID.
Definition Commit.h:28
Time arrivedTime
Time when this update arrived at the memory server.
Definition Commit.h:60
Time referencedTime
Time when this entity update was created (e.g.
Definition Commit.h:37
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition Commit.h:31
Time sentTime
Time when this update was sent to the memory server.
Definition Commit.h:53
Result of a QueryInput.
Definition Query.h:51
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58