SkillExecutionRequestSegment.cpp
Go to the documentation of this file.
2
3#include <SimoxUtility/algorithm/string.h>
4
7#include <RobotAPI/libraries/armem_skills/aron/Skill.aron.generated.h>
10
12{
13
19
20 void
22 const std::string& prefix)
23 {
25 Base::defineProperties(defs, prefix);
26 }
27
28 void
33
36 {
37 // convert ice commitData to aron
38 auto commitDataAron = std::make_shared<aron::data::Dict>(commitData);
39
40 // we got a skill execution request
41 skills::arondto::SkillExecutionRequest request;
42 request.fromAron(commitDataAron);
43
45 .skillId = SkillID{.providerId = ProviderID{.providerName = ""}, .skillName = ""},
46 .executorName = ""};
47 armem::fromAron(request, info);
48 return info;
49 }
50
51 void
54 {
55 // override directly execution to add a request to the memory
56 armem::Commit comm;
57
58 skills::arondto::SkillExecutionRequest request;
59 armem::toAron(request, info);
60
61 auto aron = request.toAron();
62
63 {
64 auto& entityUpdate = comm.add();
65
66 armem::MemoryID skillExecutionMemID = id();
67 skillExecutionMemID.providerSegmentName = request.skillId.providerId.providerName;
68 skillExecutionMemID.entityName = request.skillId.skillName;
69
70 entityUpdate.entityID = skillExecutionMemID;
71 entityUpdate.instancesData = {aron};
72 entityUpdate.confidence = 1.0;
73 entityUpdate.referencedTime = armem::Time::Now();
74 }
75
76 {
77 auto& entityUpdate = comm.add();
78
79 armem::MemoryID skillExecutionMemID = id();
80 skillExecutionMemID.providerSegmentName = "All Skill Execution Requests";
81 skillExecutionMemID.entityName = "All Skill Execution Requests";
82
83 entityUpdate.entityID = skillExecutionMemID;
84 entityUpdate.instancesData = {aron};
85 entityUpdate.confidence = 1.0;
86 entityUpdate.referencedTime = armem::Time::Now();
87 }
88
89
90 iceMemory.commitLocking(comm);
91 }
92
93 std::size_t
95 const std::string& memoryName,
96 bool& consolidated)
97 {
98 consolidated = false;
99 std::size_t snapshotCount = 0;
100 auto coreSegment = this->segmentPtr;
101 ARMARX_CHECK(coreSegment);
102
103 coreSegment->doLockedExclusive(
104 [&]()
105 {
106 coreSegment->forEachSnapshot(
107 [&](const armem::wm::EntitySnapshot&) { ++snapshotCount; });
108
109 if (ltm.isRecording() && snapshotCount > 0)
110 {
111 armem::wm::Memory slice;
112 slice.setName(memoryName);
113 slice.update(armem::toCommit(*coreSegment), true);
114 ltm.directlyStore(slice);
115 consolidated = true;
116 }
117
118 coreSegment->clear();
119 });
120
121 return snapshotCount;
122 }
123} // namespace armarx::skills::segment
std::string entityName
Definition MemoryID.h:53
std::string providerSegmentName
Definition MemoryID.h:52
Helps connecting a Memory server to the Ice interface.
A memory storing data on the hard drive and in mongodb (needs 'armarx memory start' to start the mong...
Definition Memory.h:24
void directlyStore(const armem::wm::Memory &memory, bool simulatedVersion=false)
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Client-side working memory entity snapshot.
Client-side working memory.
static DateTime Now()
Definition DateTime.cpp:51
std::size_t clearAndConsolidate(armem::server::ltm::Memory &ltm, const std::string &memoryName, bool &consolidated)
Clear all snapshots from the working memory of this core segment, consolidating them into ltm first i...
skills::SkillExecutionRequest convertCommit(const aron::data::dto::DictPtr &commitData)
SkillExecutionRequestCoreSegment(armem::server::MemoryToIceAdapter &iceMemory)
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
void addSkillExecutionRequest(const skills::SkillExecutionRequest &info)
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Commit toCommit(const ContainerT &container)
Definition operations.h:23
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
::IceInternal::Handle< Dict > DictPtr
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