ObjectWriter.cpp
Go to the documentation of this file.
1#include "ObjectWriter.h"
2
3#include <mutex>
4#include <optional>
5
8
14#include <RobotAPI/libraries/armem_objects/aron/Attachment.aron.generated.h>
17
19{
21 {
22 }
23
24 void
26 {
27 ARMARX_DEBUG << "Writer: registerPropertyDefinitions";
28
29 const std::string prefix = propertyPrefix;
30
31 def->optional(properties.memoryName, prefix + "MemoryName");
32
33 def->optional(properties.coreSegmentName,
34 prefix + "CoreSegment",
35 "Name of the memory core segment to use for object instances.");
36 }
37
38 void
40 {
41 // Wait for the memory to become available and add it as dependency.
42 ARMARX_IMPORTANT << "Writer: Waiting for memory '" << properties.memoryName << "' ...";
43 try
44 {
45 memoryWriter = memoryNameSystem.useWriter(properties.memoryName);
46 ARMARX_IMPORTANT << "Writer: Connected to memory '" << properties.memoryName << "'";
47 }
49 {
50 ARMARX_ERROR << e.what();
51 return;
52 }
53 }
54
55 bool
56 Writer::commitObject(const armem::arondto::ObjectInstance& inst,
57 const std::string& provider,
58 const armem::Time& t)
59 {
61 auto& e = c.add();
62
63 e.entityID.memoryName = properties.memoryName;
64 e.entityID.coreSegmentName = properties.coreSegmentName;
65 e.entityID.providerSegmentName = provider;
66 e.entityID.entityName = inst.pose.objectID.dataset + "/" + inst.pose.objectID.className +
67 "/" + inst.pose.objectID.instanceName;
68 e.referencedTime = t;
69 e.sentTime = armem::Time::Now();
70 e.instancesData = {inst.toAron()};
71
72 e.confidence = inst.pose.confidence;
73
74 auto res = memoryWriter.commit(c);
75
76 if (!res.allSuccess())
77 {
78 ARMARX_ERROR << "Failed to commit an ObjectInstance to memory: "
79 << res.allErrorMessages();
80 return false;
81 }
82 return true;
83 }
84
85} // namespace armarx::armem::obj::instance
constexpr T c
The memory name system (MNS) client.
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool commitObject(const armem::arondto::ObjectInstance &inst, const std::string &provider, const armem::Time &)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
armarx::core::time::DateTime Time
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
Definition Commit.h:90