Writer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <RobotAPI/interface/armem/server/WritingMemoryInterface.h>
5 
6 namespace armarx::armem::client
7 {
8 
9  /**
10  * @brief Helps a memory client sending data to a memory.
11  *
12  * You can check whether the writer is ready using the bool operator:
13  * @code
14  * client::Writer writer(writingMemoryProxy);
15  * ...
16  * if (writer)
17  * {
18  * writer.commit(...);
19  * }
20  * @endcode
21  */
22  class Writer
23  {
24  public:
25  /**
26  * @brief Construct a memory writer.
27  * @param memory The memory proxy.
28  */
29  Writer(const Writer&) = default;
30  Writer(server::WritingMemoryInterfacePrx memory = nullptr);
31 
32 
33  data::AddSegmentResult addSegment(const std::string& coreSegmentName,
34  const std::string& providerSegmentName,
35  bool clearWhenExists = false) const;
36  data::AddSegmentResult addSegment(const MemoryID& providerSegmentID,
37  bool clearWhenExists = false) const;
38  data::AddSegmentResult addSegment(const std::pair<std::string, std::string>& names,
39  bool clearWhenExists = false) const;
40  data::AddSegmentResult addSegment(const data::AddSegmentInput& input) const;
41  data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input) const;
42 
43 
44  /**
45  * @brief Writes a `Commit` to the memory.
46  */
47  CommitResult commit(const Commit& commit) const;
48  /// Commit a single entity update.
50 
51  /**
52  * Commit a single entity update.
53  * @param origin Identifier of the instances source (e.g. LTM identifier)
54  */
55  EntityUpdateResult commit(const MemoryID& entityID,
56  const std::vector<aron::data::DictPtr>& instancesData,
57  Time referencedTime,
58  const std::string& origin) const;
59 
60  // with bare-ice types
61  data::CommitResult commit(const data::Commit& commit) const;
62 
63  /**
64  * @brief Clears the servers working memory (uses the WM-Clear feature)
65  */
66  void clearWorkingMemory();
67 
68 
69  void setWritingMemory(server::WritingMemoryInterfacePrx memory);
70 
71  operator bool() const
72  {
73  return bool(memory);
74  }
75 
76  private:
77  /// Sets `timeSent` on all entity updates and performs the commit,
78  data::CommitResult _commit(data::Commit& commit) const;
79 
80 
81  public:
82  server::WritingMemoryInterfacePrx memory;
83  };
84 
85 } // namespace armarx::armem::client
86 
88 {
89  std::ostream& operator<<(std::ostream& os, const AddSegmentInput& rhs);
90  std::ostream& operator<<(std::ostream& os, const AddSegmentsInput& rhs);
91  std::ostream& operator<<(std::ostream& os, const AddSegmentResult& rhs);
92  std::ostream& operator<<(std::ostream& os, const AddSegmentsResult& rhs);
93 } // namespace armarx::armem::data
armarx::armem::client::Writer::addSegment
data::AddSegmentResult addSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, bool clearWhenExists=false) const
Definition: Writer.cpp:16
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:74
armarx::armem::client::Writer::setWritingMemory
void setWritingMemory(server::WritingMemoryInterfacePrx memory)
Definition: Writer.cpp:112
armarx::armem::client
This file is part of ArmarX.
Definition: Configurator.cpp:5
armarx::memory
Brief description of class memory.
Definition: memory.h:38
armarx::armem::data::operator<<
std::ostream & operator<<(std::ostream &os, const AddSegmentInput &rhs)
Definition: Writer.cpp:171
armarx::armem::client::Writer::addSegments
data::AddSegmentsResult addSegments(const data::AddSegmentsInput &input) const
Definition: Writer.cpp:50
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:25
armarx::armem::CommitResult
Result of a Commit.
Definition: Commit.h:110
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
armarx::armem::client::Writer::Writer
Writer(const Writer &)=default
Construct a memory writer.
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
armarx::armem::client::Writer::clearWorkingMemory
void clearWorkingMemory()
Clears the servers working memory (uses the WM-Clear feature)
Definition: Writer.cpp:106
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:13
armarx::armem::data
Definition: Writer.h:87
ice_conversions.h
armarx::armem::client::Writer::memory
server::WritingMemoryInterfacePrx memory
Definition: Writer.h:82