Writer.cpp
Go to the documentation of this file.
1#include "Writer.h"
2
3#include <algorithm>
4#include <iterator>
5#include <mutex>
6#include <string>
7
9
15
16#include <armarx/navigation/human/aron/Human.aron.generated.h>
20
22{
23 Writer::~Writer() = default;
24
25 bool
27 // const std::string& name,
28 const std::string& providerName,
30 {
31 std::lock_guard g{writeMutex};
32
33 const auto result =
35
36 if (not result.success)
37 {
38 ARMARX_ERROR << result.errorMessage;
39
40 // TODO(fabian.reister): message
41 return false;
42 }
43
44 const auto providerId = armem::MemoryID(result.segmentID);
45 const auto entityID = providerId.withEntityName("humans").withTimestamp(timestamp);
46
48 update.entityID = entityID;
49
50 std::transform(humans.begin(),
51 humans.end(),
52 std::back_inserter(update.instancesData),
54 {
55 navigation::human::arondto::Human dto;
56 toAron(dto, human);
57
58 return dto.toAron();
59 });
60
61
62 update.referencedTime = timestamp;
63
64 ARMARX_DEBUG << "Committing " << update << " at time " << timestamp;
65 armem::EntityUpdateResult updateResult = memoryWriter().commit(update);
66
67 ARMARX_DEBUG << updateResult;
68
69 if (not updateResult.success)
70 {
71 ARMARX_ERROR << updateResult.errorMessage;
72 }
73
74 return updateResult.success;
75 }
76
77 bool
79 // const std::string& name,
80 const std::string& providerName,
82 {
83 std::lock_guard g{writeMutex};
84
85 const auto result =
87
88 if (not result.success)
89 {
90 ARMARX_ERROR << result.errorMessage;
91
92 // TODO(fabian.reister): message
93 return false;
94 }
95
96 const auto providerId = armem::MemoryID(result.segmentID);
97 const auto entityID = providerId.withEntityName("groups").withTimestamp(timestamp);
98
100 update.entityID = entityID;
101
102 std::transform(groups.begin(),
103 groups.end(),
104 std::back_inserter(update.instancesData),
106 {
107 navigation::human::arondto::HumanGroup dto;
108 toAron(dto, group);
109
110 return dto.toAron();
111 });
112
113
114 update.referencedTime = timestamp;
115
116 ARMARX_DEBUG << "Committing " << update << " at time " << timestamp;
117 armem::EntityUpdateResult updateResult = memoryWriter().commit(update);
118
119 ARMARX_DEBUG << updateResult;
120
121 if (not updateResult.success)
122 {
123 ARMARX_ERROR << updateResult.errorMessage;
124 }
125
126 return updateResult.success;
127 }
128
129 std::string
131 {
132 return "mem.nav.human.";
133 }
134
135 armarx::armem::client::util::SimpleWriterBase::SimpleWriterBase::Properties
137 {
138 return SimpleWriterBase::Properties{.memoryName = memory::constants::NavigationMemoryName,
139 .coreSegmentName =
141 }
142
143} // namespace armarx::navigation::memory::client::human
std::string timestamp()
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition Writer.cpp:25
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
bool store(const armarx::navigation::human::Humans &humans, const std::string &providerName, const armem::Time &timestamp)
Definition Writer.cpp:26
Properties defaultProperties() const override
Definition Writer.cpp:136
std::string propertyPrefix() const override
Definition Writer.cpp:130
#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
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::vector< Human > Humans
Definition types.h:48
std::vector< HumanGroup > HumanGroups
Definition types.h:60
constexpr const char * HumanCoreSegmentName
Definition constants.h:38
constexpr const char * NavigationMemoryName
Definition constants.h:29
Result of an EntityUpdate.
Definition Commit.h:75
An update of an entity for a specific point in time.
Definition Commit.h:26