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  auto res = memoryWriter.commit(c);
73 
74  if (!res.allSuccess())
75  {
76  ARMARX_ERROR << "Failed to commit an ObjectInstance to memory: "
77  << res.allErrorMessages();
78  return false;
79  }
80  return true;
81  }
82 
83 } // namespace armarx::armem::obj::instance
ObjectWriter.h
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::client::MemoryNameSystem::useWriter
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Definition: MemoryNameSystem.cpp:276
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::armem::obj::instance::Writer::commitObject
bool commitObject(const armem::arondto::ObjectInstance &inst, const std::string &provider, const armem::Time &)
Definition: ObjectWriter.cpp:56
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
error.h
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::armem::obj::instance::Writer::registerPropertyDefinitions
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Definition: ObjectWriter.cpp:25
armarx::armem::obj::instance::Writer::Writer
Writer()
Definition: ObjectWriter.cpp:20
memory_definitions.h
aron_conversions.h
armarx::armem::obj::instance::Writer::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: ObjectWriter.cpp:39
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
IceUtil::Handle< class PropertyDefinitionContainer >
Time.h
Builder.h
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::error::CouldNotResolveMemoryServer
Indicates that a query to the Memory Name System failed.
Definition: mns.h:26
util.h
Logging.h
armarx::armem::obj::instance
Definition: ObjectReader.cpp:22
aron_conversions.h
PackagePath.h