ProfileLibrarySegment.cpp
Go to the documentation of this file.
2#include <vector>
3
4#include <SimoxUtility/algorithm/string.h>
5
7
15#include <RobotAPI/libraries/skills/core/aron/FluxioProfile.aron.generated.h>
16
18{
24
25 void
27 const std::string& prefix)
28 {
30 Base::defineProperties(defs, prefix);
31 }
32
33 void
38
39 void
40 ProfileLibraryCoreSegment::addProfile(const skills::manager::arondto::FluxioProfile& profile)
41 {
42 // add profile
43 armem::MemoryID provId = id().withProviderSegmentName("FluxioProfile");
44
45 armem::Commit commit;
46 armem::EntityUpdate& entityUpdate = commit.add();
47 entityUpdate.confidence = 1.0;
48 entityUpdate.referencedTime = armem::Time::Now();
49 entityUpdate.sentTime = armem::Time::Now();
50 entityUpdate.arrivedTime = armem::Time::Now();
51 entityUpdate.instancesData = {profile.toAron()};
52 entityUpdate.entityID = provId.withEntityName(profile.name);
53
54 // Commit data to memory with locking to prevent race conditions with concurrent queries.
55 iceMemory.commitLocking(commit);
56 }
57
58 std::optional<std::vector<skills::manager::arondto::FluxioProfile>> ProfileLibraryCoreSegment::getProfiles() const {
59 std::vector<skills::manager::arondto::FluxioProfile> ret;
63 if (!qresult.success)
64 {
65 ARMARX_WARNING << "Query failed: " << qresult.errorMessage;
66 return std::nullopt;
67 }
68
69 const armem::wm::Memory& data = qresult.memory;
70
71 data.forEachInstance(
72 [&ret, this](const armem::wm::EntityInstance& instance)
73 {
74 // dataAs<>() throws on type mismatch / corrupted aron data.
75 // Skip the bad entry instead of crashing getProfiles().
76 skills::manager::arondto::FluxioProfile profile;
77 try
78 {
79 profile = instance.dataAs<skills::manager::arondto::FluxioProfile>();
80 }
81 catch (const std::exception& e)
82 {
83 ARMARX_WARNING << "Skipping malformed FluxioProfile instance: "
84 << e.what();
85 return;
86 }
87 if (profile.deleted)
88 {
89 return;
90 }
91 ret.push_back(profile);
92 });
93
94 return ret;
95 }
96} // 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 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
void addProfile(const skills::manager::arondto::FluxioProfile &profile)
ProfileLibraryCoreSegment(armem::server::MemoryToIceAdapter &iceMemory)
std::optional< std::vector< skills::manager::arondto::FluxioProfile > > getProfiles() const
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
#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