Writer.cpp
Go to the documentation of this file.
1#include "Writer.h"
2
3#include <mutex>
4#include <string>
5#include <vector>
6
7#include <SimoxUtility/algorithm/string/string_tools.h>
8
11
16
18#include <armarx/navigation/algorithms/aron/Room.aron.generated.h>
21
23{
24 Writer::~Writer() = default;
25
26 bool
28 const std::string& providerName,
30 {
31 return store(
32 std::vector<armarx::navigation::algorithms::Room>{room}, providerName, timestamp);
33 }
34
35 bool
36 Writer::store(const std::vector<armarx::navigation::algorithms::Room>& rooms,
37 const std::string& providerName,
39 {
40 std::lock_guard g{writeMutex};
41
42 const auto result =
44
45 if (not result.success)
46 {
47 ARMARX_ERROR << result.errorMessage;
48 return false;
49 }
50
51 const auto providerId = armem::MemoryID(result.segmentID);
52
53 armem::Commit commit;
54
55 for (const auto& room : rooms)
56 {
57 ARMARX_CHECK(not room.name.empty())
58 << "A room must have a name as it is used as the entity name.";
59
60 navigation::algorithms::arondto::Room dto;
61 toAron(dto, room);
62
63 armem::EntityUpdate& update = commit.add();
64 update.entityID = providerId.withEntityName(room.name).withTimestamp(timestamp);
65 update.referencedTime = timestamp;
66 update.instancesData = {dto.toAron()};
67 }
68
69 ARMARX_DEBUG << "Committing " << commit << " at time " << timestamp;
70 const armem::CommitResult commitResult = memoryWriter().commit(commit);
71
72 if (not commitResult.allSuccess())
73 {
74 ARMARX_ERROR << simox::alg::join(commitResult.allErrorMessages(), "\n");
75 return false;
76 }
77
78 return true;
79 }
80
81 std::string
83 {
84 return "mem.nav.rooms.";
85 }
86
89 {
90 return {.memoryName = memory::constants::NavigationMemoryName,
92 .providerName = ""};
93 }
94
95} // namespace armarx::navigation::memory::client::rooms
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::algorithms::Room &room, const std::string &providerName, const armem::Time &timestamp)
Definition Writer.cpp:27
std::string propertyPrefix() const override
Definition Writer.cpp:82
Properties defaultProperties() const override
Definition Writer.cpp:88
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:194
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:182
armarx::core::time::DateTime Time
constexpr const char * RoomsCoreSegmentName
Definition constants.h:44
constexpr const char * NavigationMemoryName
Definition constants.h:29
void toAron(arondto::Circle &dto, const Circle &bo)
Result of a Commit.
Definition Commit.h:111
std::vector< std::string > allErrorMessages() const
Definition Commit.cpp:73
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
An update of an entity for a specific point in time.
Definition Commit.h:26