Writer.cpp
Go to the documentation of this file.
1#include "Writer.h"
2
3#include <memory>
4#include <mutex>
5#include <string>
6#include <type_traits>
7
9
14
15#include <armarx/navigation/core/aron/Events.aron.generated.h>
19
21{
22
23 std::string
25 {
26 return "mem.nav.events.";
27 }
28
31 {
32 return Properties{
35 .providerName = "" // clientId
36 };
37 }
38
39 bool
40 Writer::store(const armem::Commit& commit)
41 {
42 std::lock_guard g{writeMutex};
43 armem::CommitResult updateResult = memoryWriter().commit(commit);
44
45 ARMARX_DEBUG << updateResult;
46
47 if (not updateResult.allSuccess())
48 {
49 ARMARX_WARNING << "Failed to commit to memory: " << updateResult.allErrorMessages();
50 }
51 return updateResult.allSuccess();
52 }
53
54 bool
56 {
57 std::lock_guard g{writeMutex};
58 const armem::EntityUpdateResult updateResult = memoryWriter().commit(commit);
59
60 ARMARX_DEBUG << updateResult;
61
62 if (not updateResult.success)
63 {
64 ARMARX_WARNING << "Failed to commit to memory: " << updateResult.errorMessage;
65 }
66 return updateResult.success;
67 }
68
69 bool
70 Writer::store(const core::GlobalTrajectoryUpdatedEvent& event, const std::string& clientID)
71 {
72 return storeImpl<core::arondto::GlobalTrajectoryUpdatedEvent>(
74 }
75
76 bool
77 Writer::store(const core::LocalTrajectoryUpdatedEvent& event, const std::string& clientID)
78 {
79 return storeImpl<core::arondto::LocalTrajectoryUpdatedEvent>(
81 }
82
83 bool
84 Writer::store(const core::GoalReachedEvent& event, const std::string& clientID)
85 {
86 return storeImpl<core::arondto::GoalReachedEvent>(
87 event, core::event_names::GoalReached, clientID);
88 }
89
90 bool
91 Writer::store(const core::WaypointReachedEvent& event, const std::string& clientID)
92 {
93 return storeImpl<core::arondto::WaypointReachedEvent>(
94 event, core::event_names::WaypointReached, clientID);
95 }
96
97 bool
98 Writer::store(const core::InternalErrorEvent& event, const std::string& clientID)
99 {
100 return storeImpl<core::arondto::InternalErrorEvent>(
101 event, core::event_names::InternalError, clientID);
102 }
103
104 bool
105 Writer::store(const core::GlobalPlanningFailedEvent& event, const std::string& clientID)
106 {
107 return storeImpl<core::arondto::GlobalPlanningFailedEvent>(
109 }
110
111 bool
112 Writer::store(const core::LocalPlanningFailedEvent& event, const std::string& clientID)
113 {
114 return storeImpl<core::arondto::LocalPlanningFailedEvent>(
116 }
117
118 bool
119 Writer::store(const core::MovementStartedEvent& event, const std::string& clientID)
120 {
121 return storeImpl<core::arondto::MovementStartedEvent>(
122 event, core::event_names::MovementStarted, clientID);
123 }
124
125 bool
126 Writer::store(const core::UserAbortTriggeredEvent& event, const std::string& clientID)
127 {
128 return storeImpl<core::arondto::UserAbortTriggeredEvent>(
130 }
131
132 bool
133 Writer::store(const core::SafetyThrottlingTriggeredEvent& event, const std::string& clientID)
134 {
135 return storeImpl<core::arondto::SafetyThrottlingTriggeredEvent>(
137 }
138
139 bool
140 Writer::store(const core::SafetyStopTriggeredEvent& event, const std::string& clientID)
141 {
142 return storeImpl<core::arondto::SafetyStopTriggeredEvent>(
144 }
145
146 template <typename AronEventT, typename EventT>
147 bool
148 Writer::storeImpl(const EventT& event,
149 const std::string& eventName,
150 const std::string& clientID)
151 {
152 static_assert(std::is_base_of<core::Event, EventT>::value, "Only events supported.");
153
154 ARMARX_VERBOSE << "Storing event " << QUOTED(eventName) << " in memory.";
155
156 const auto& timestamp = event.timestamp;
157
158 armem::EntityUpdate update;
159 update.entityID = armem::MemoryID()
160 .withMemoryName(properties().memoryName)
161 .withCoreSegmentName(properties().coreSegmentName)
162 .withProviderSegmentName(clientID)
163 .withEntityName(eventName)
165 update.referencedTime = timestamp;
166
167 const auto dto = core::toAron<AronEventT>(event);
168
170 element->setElementCopy("event", std::make_shared<aron::data::String>(eventName));
171 element->setElementCopy("data", dto.toAron());
172
173 update.instancesData = {element};
174
175 return store(update);
176 }
177} // namespace armarx::navigation::memory::client::events
std::string timestamp()
#define QUOTED(x)
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withCoreSegmentName(const std::string &name) const
Definition MemoryID.cpp:409
MemoryID withMemoryName(const std::string &name) const
Definition MemoryID.cpp:401
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
MemoryID withTimestamp(Time time) const
Definition MemoryID.cpp:433
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
std::string propertyPrefix() const override
Definition Writer.cpp:24
Properties defaultProperties() const override
Definition Writer.cpp:30
bool store(const core::GoalReachedEvent &event, const std::string &clientID)
Definition Writer.cpp:84
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
const std::string SafetyStopTriggered
Definition events.h:24
const std::string SafetyThrottlingTriggered
Definition events.h:23
const std::string UserAbortTriggered
Definition events.h:25
const std::string LocalTrajectoryUpdated
Definition events.h:17
const std::string MovementStarted
Definition events.h:20
const std::string WaypointReached
Definition events.h:22
const std::string GlobalTrajectoryUpdated
Definition events.h:16
const std::string GlobalPlanningFailed
Definition events.h:18
const std::string InternalError
Definition events.h:26
const std::string LocalPlanningFailed
Definition events.h:19
void toAron(arondto::GlobalTrajectoryPoint &dto, const GlobalTrajectoryPoint &bo)
This file is part of ArmarX.
Definition Writer.cpp:21
constexpr const char * EventsCoreSegmentName
Definition constants.h:33
constexpr const char * NavigationMemoryName
Definition constants.h:29
Result of a Commit.
Definition Commit.h:111
A bundle of updates to be sent to the memory.
Definition Commit.h:90
Result of an EntityUpdate.
Definition Commit.h:75
An update of an entity for a specific point in time.
Definition Commit.h:26
Event describing that the global trajectory was updated.
Definition events.h:114
Event describing that the targeted goal was successfully reached.
Definition events.h:53
Event describing the occurance of an internal unhandled error.
Definition events.h:105
Event describing that the local trajectory was updated.
Definition events.h:122
Event describing that for security reasons, the robot was stopped completely.
Definition events.h:88
Event desciribing that a significant safety throttling factor was reached.
Definition events.h:72
Event describing that the user aborted the current execution.
Definition events.h:97
Event describing that a user-defined waypoint was successfully reached.
Definition events.h:61