ObjectWriter.cpp
Go to the documentation of this file.
1#include "ObjectWriter.h"
2
5
11#include <RobotAPI/libraries/armem_objects/aron/Attachment.aron.generated.h>
14
16{
17 Writer::Writer() = default;
18
19 void
21 {
22 ARMARX_DEBUG << "Writer: registerPropertyDefinitions";
23
24 const std::string prefix = propertyPrefix;
25
26 def->optional(properties.memoryName, prefix + "MemoryName");
27
28 def->optional(properties.coreSegmentName,
29 prefix + "CoreSegment",
30 "Name of the memory core segment to use for object instances.");
31 }
32
33 void
35 {
36 // Wait for the memory to become available and add it as dependency.
37 ARMARX_IMPORTANT << "Writer: Waiting for memory '" << properties.memoryName << "' ...";
38 try
39 {
40 memoryWriter = memoryNameSystem.useWriter(properties.memoryName);
41 ARMARX_IMPORTANT << "Writer: Connected to memory '" << properties.memoryName << "'";
42 }
44 {
45 ARMARX_ERROR << e.what();
46 return;
47 }
48 }
49
50 bool
51 Writer::commitObject(const armem::arondto::FamiliarObjectInstance& inst,
52 const std::string& provider,
53 const armem::Time& t)
54 {
56 auto& e = c.add();
57
58 e.entityID.memoryName = properties.memoryName;
59 e.entityID.coreSegmentName = properties.coreSegmentName;
60 e.entityID.providerSegmentName = provider;
61
62 e.entityID.entityName = inst.objectID.dataset + "/" + inst.objectID.className + "/" +
63 inst.objectID.instanceName;
64 e.referencedTime = t;
65 e.sentTime = armem::Time::Now();
66 e.instancesData = {inst.toAron()};
67
68 auto res = memoryWriter.commit(c);
69
70 if (!res.allSuccess())
71 {
72 ARMARX_ERROR << "Failed to commit a FamiliarObjectInstance to memory: "
73 << res.allErrorMessages();
74 return false;
75 }
76 return true;
77 }
78
79} // namespace armarx::armem::obj::familiar_object_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
bool commitObject(const armem::arondto::FamiliarObjectInstance &inst, const std::string &provider, const armem::Time &)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
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