Writer.cpp
Go to the documentation of this file.
1 #include "Writer.h"
2 
3 #include <type_traits>
4 
7 
9 #include <armarx/navigation/core/aron/Events.aron.generated.h>
13 
15 {
16 
17  std::string
19  {
20  return "mem.nav.events.";
21  }
22 
25  {
26  return Properties{
29  .providerName = "" // clientId
30  };
31  }
32 
33 
34  bool
35  Writer::store(const armem::Commit& commit)
36  {
37  std::lock_guard g{writeMutex};
38  armem::CommitResult updateResult = memoryWriter().commit(commit);
39 
40  ARMARX_DEBUG << updateResult;
41 
42  if (not updateResult.allSuccess())
43  {
44  ARMARX_WARNING << "Failed to commit to memory: " << updateResult.allErrorMessages();
45  }
46  return updateResult.allSuccess();
47  }
48 
49  bool
50  Writer::store(const armem::EntityUpdate& commit)
51  {
52  std::lock_guard g{writeMutex};
53  const armem::EntityUpdateResult updateResult = memoryWriter().commit(commit);
54 
55  ARMARX_DEBUG << updateResult;
56 
57  if (not updateResult.success)
58  {
59  ARMARX_WARNING << "Failed to commit to memory: " << updateResult.errorMessage;
60  }
61  return updateResult.success;
62  }
63 
64  bool
65  Writer::store(const core::GoalReachedEvent& event, const std::string& clientID)
66  {
67  return storeImpl<core::arondto::GoalReachedEvent>(
68  event, core::event_names::GoalReached, clientID);
69  }
70 
71  bool
72  Writer::store(const core::WaypointReachedEvent& event, const std::string& clientID)
73  {
74  return storeImpl<core::arondto::WaypointReachedEvent>(
75  event, core::event_names::WaypointReached, clientID);
76  }
77 
78  bool
79  Writer::store(const core::InternalErrorEvent& event, const std::string& clientID)
80  {
81  return storeImpl<core::arondto::InternalErrorEvent>(
82  event, core::event_names::InternalError, clientID);
83  }
84 
85  bool
86  Writer::store(const core::GlobalPlanningFailedEvent& event, const std::string& clientID)
87  {
88  return storeImpl<core::arondto::GlobalPlanningFailedEvent>(
90  }
91 
92  bool
93  Writer::store(const core::LocalPlanningFailedEvent& event, const std::string& clientID)
94  {
95  return storeImpl<core::arondto::LocalPlanningFailedEvent>(
97  }
98 
99 
100  bool
101  Writer::store(const core::MovementStartedEvent& event, const std::string& clientID)
102  {
103  return storeImpl<core::arondto::MovementStartedEvent>(
104  event, core::event_names::MovementStarted, clientID);
105  }
106 
107  bool
108  Writer::store(const core::UserAbortTriggeredEvent& event, const std::string& clientID)
109  {
110  return storeImpl<core::arondto::UserAbortTriggeredEvent>(
111  event, core::event_names::UserAbortTriggered, clientID);
112  }
113 
114  bool
115  Writer::store(const core::SafetyThrottlingTriggeredEvent& event, const std::string& clientID)
116  {
117  return storeImpl<core::arondto::SafetyThrottlingTriggeredEvent>(
119  }
120 
121  bool
122  Writer::store(const core::SafetyStopTriggeredEvent& event, const std::string& clientID)
123  {
124  return storeImpl<core::arondto::SafetyStopTriggeredEvent>(
125  event, core::event_names::SafetyStopTriggered, clientID);
126  }
127 
128 
129  template <typename AronEventT, typename EventT>
130  bool
131  Writer::storeImpl(const EventT& event,
132  const std::string& eventName,
133  const std::string& clientID)
134  {
135  static_assert(std::is_base_of<core::Event, EventT>::value, "Only events supported.");
136 
137  ARMARX_INFO << "Storing event `" << eventName << "` in memory.";
138 
139  const auto& timestamp = event.timestamp;
140 
142  update.entityID = armem::MemoryID()
144  .withCoreSegmentName(properties().coreSegmentName)
145  .withProviderSegmentName(clientID)
146  .withEntityName(eventName)
147  .withTimestamp(timestamp);
148  update.referencedTime = timestamp;
149 
150  const auto dto = core::toAron<AronEventT>(event);
151 
153  element->setElementCopy("event", std::make_shared<aron::data::String>(eventName));
154  element->setElementCopy("data", dto.toAron());
155 
156  update.instancesData = {element};
157 
158  return store(update);
159  }
160 } // namespace armarx::navigation::memory::client::events
armarx::navigation::core::event_names::MovementStarted
const std::string MovementStarted
Definition: events.h:17
Writer.h
armarx::armem::MemoryID::withMemoryName
MemoryID withMemoryName(const std::string &name) const
Definition: MemoryID.cpp:396
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::EntityUpdateResult
Result of an EntityUpdate.
Definition: Commit.h:72
armarx::navigation::core::InternalErrorEvent
Event describing the occurance of an internal unhandled error.
Definition: events.h:101
armarx::navigation::core::SafetyThrottlingTriggeredEvent
Event desciribing that a significant safety throttling factor was reached.
Definition: events.h:68
armarx::armem::client::util::SimpleWriterBase::Properties
Definition: SimpleWriterBase.h:49
armarx::navigation::core::event_names::UserAbortTriggered
const std::string UserAbortTriggered
Definition: events.h:22
armarx::navigation::memory::constants::NavigationMemoryName
const std::string NavigationMemoryName
Definition: constants.h:27
armarx::navigation::core::event_names::WaypointReached
const std::string WaypointReached
Definition: events.h:19
armarx::navigation::memory::client::events::Writer::store
bool store(const core::GoalReachedEvent &event, const std::string &clientID)
Definition: Writer.cpp:65
constants.h
events.h
armarx::navigation::core::event_names::SafetyStopTriggered
const std::string SafetyStopTriggered
Definition: events.h:21
armarx::navigation::core::event_names::SafetyThrottlingTriggered
const std::string SafetyThrottlingTriggered
Definition: events.h:20
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:412
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::navigation::core::event_names::GlobalPlanningFailed
const std::string GlobalPlanningFailed
Definition: events.h:15
armarx::armem::client::util::SimpleWriterBase::memoryWriter
armem::client::Writer & memoryWriter()
Definition: SimpleWriterBase.cpp:51
armarx::armem::MemoryID::withCoreSegmentName
MemoryID withCoreSegmentName(const std::string &name) const
Definition: MemoryID.cpp:404
armarx::navigation::core::SafetyStopTriggeredEvent
Event describing that for security reasons, the robot was stopped completely.
Definition: events.h:84
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
core.h
armarx::armem::client::util::SimpleWriterBase::Properties::memoryName
std::string memoryName
Definition: SimpleWriterBase.h:51
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::CommitResult
Result of a Commit.
Definition: Commit.h:110
armarx::navigation::core::UserAbortTriggeredEvent
Event describing that the user aborted the current execution.
Definition: events.h:93
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
armarx::navigation::core::GlobalPlanningFailedEvent
Definition: events.h:31
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::navigation::core::GoalReachedEvent
Event describing that the targeted goal was successfully reached.
Definition: events.h:49
armarx::navigation::memory::constants::EventsCoreSegmentName
const std::string EventsCoreSegmentName
Definition: constants.h:31
armarx::navigation::core::event_names::GoalReached
const std::string GoalReached
Definition: events.h:18
armarx::navigation::core::event_names::InternalError
const std::string InternalError
Definition: events.h:23
armarx::navigation::memory::client::events::Writer::defaultProperties
Properties defaultProperties() const override
Definition: Writer.cpp:24
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::navigation::memory::client::events::Writer::propertyPrefix
std::string propertyPrefix() const override
Definition: Writer.cpp:18
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:420
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
aron_conversions.h
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
armarx::armem::client::util::SimpleWriterBase::properties
const Properties & properties() const
Definition: SimpleWriterBase.cpp:57
armarx::armem::MemoryID::withTimestamp
MemoryID withTimestamp(Time time) const
Definition: MemoryID.cpp:428
constants.h
armarx::navigation::core::WaypointReachedEvent
Event describing that a user-defined waypoint was successfully reached.
Definition: events.h:57
armarx::navigation::memory::client::events
This file is part of ArmarX.
Definition: Writer.cpp:14
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
String.h
armarx::navigation::core::LocalPlanningFailedEvent
Definition: events.h:36
armarx::navigation::core::event_names::LocalPlanningFailed
const std::string LocalPlanningFailed
Definition: events.h:16
armarx::navigation::core::MovementStartedEvent
Definition: events.h:41
armarx::aron::data::Dict
Definition: Dict.h:44
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29