Writer.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <mutex>
25 #include <optional>
26 
28 
32 
33 #include "interfaces.h"
34 
36 {
37 
38  class Writer : virtual public WriterInterface
39  {
40  public:
41  Writer() = default;
42  ~Writer() override = default;
43 
45  void connect(armem::client::MemoryNameSystem& memoryNameSystem);
46 
47 
48  bool store(const ArticulatedObject& obj) const override;
49 
50  bool storeInstance(const ArticulatedObject& obj) const;
51  std::optional<armem::MemoryID> storeClass(const ArticulatedObject& obj) const;
52 
53  // const std::string& getPropertyPrefix() const override;
54 
55  std::string getProviderName() const;
56  void setProviderName(const std::string& providerName);
57 
58 
59  private:
60  std::optional<armem::MemoryID> storeOrGetClass(const ArticulatedObject& obj) const;
61 
62  void updateKnownObjects(const armem::MemoryID& subscriptionID,
63  const std::vector<armem::MemoryID>& snapshotIDs);
64  void updateKnownObjects();
65  void updateKnownObject(const armem::MemoryID& snapshotId);
66 
67  // TODO duplicate
68  std::unordered_map<std::string, armem::MemoryID>
69  queryDescriptions(const armem::Time& timestamp);
70  std::optional<robot_state::description::RobotDescription>
71  getRobotDescription(const armarx::armem::wm::Memory& memory) const;
72  std::unordered_map<std::string, armem::MemoryID>
73  getRobotDescriptions(const armarx::armem::wm::Memory& memory) const;
74 
75  struct Properties
76  {
77  std::string memoryName = "Object";
78  std::string coreInstanceSegmentName = "Instance";
79  std::string coreClassSegmentName = "Class";
80  std::string providerName = "";
81 
82  bool allowClassCreation = false;
83  } properties;
84 
85  const std::string propertyPrefix = "mem.obj.articulated.";
86 
87  armem::client::Writer memoryWriter;
88  mutable std::mutex memoryWriterMutex;
89 
90  armem::client::Reader memoryReader;
91  mutable std::mutex memoryReaderMutex;
92 
93  // key: name of object: RobotDescription::name
94  mutable std::unordered_map<std::string, MemoryID> knownObjects;
95  };
96 
97 
98 } // namespace armarx::armem::articulated_object
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
Reader.h
Writer.h
armarx::armem::robot_state::Robot
Definition: types.h:126
armarx::armem::articulated_object::Writer::setProviderName
void setProviderName(const std::string &providerName)
Definition: Writer.cpp:188
armarx::armem::articulated_object::Writer::store
bool store(const ArticulatedObject &obj) const override
Definition: Writer.cpp:263
armarx::armem::articulated_object::Writer::getProviderName
std::string getProviderName() const
Definition: Writer.cpp:182
armarx::armem::articulated_object::Writer::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: Writer.cpp:50
armarx::memory
Brief description of class memory.
Definition: memory.h:39
interfaces.h
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::articulated_object::Writer
Definition: Writer.h:38
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::armem::articulated_object::WriterInterface
Definition: interfaces.h:28
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::articulated_object::Writer::~Writer
~Writer() override=default
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
IceUtil::Handle< class PropertyDefinitionContainer >
forward_declarations.h
armarx::armem::articulated_object
Definition: ArticulatedObjectReader.cpp:25
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::articulated_object::Writer::storeInstance
bool storeInstance(const ArticulatedObject &obj) const
Definition: Writer.cpp:194
armarx::armem::articulated_object::Writer::registerPropertyDefinitions
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
Definition: Writer.cpp:29
armarx::armem::articulated_object::Writer::storeClass
std::optional< armem::MemoryID > storeClass(const ArticulatedObject &obj) const
Definition: Writer.cpp:133
MemoryNameSystem.h
armarx::armem::articulated_object::Writer::Writer
Writer()=default