MemoryNameSystem.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  * @package RobotAPI::libraries::armem
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <map>
26 #include <optional>
27 
28 #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
29 #include <RobotAPI/interface/armem/server/MemoryInterface.h>
30 
34 
35 
36 namespace armarx
37 {
38  class ManagedIceObject;
39 }
40 namespace armarx::armem::client
41 {
42  class Reader;
43  class Writer;
44 }
45 
47 {
48  class EntityInstance;
49 }
50 
51 namespace armarx::armem::client
52 {
53 
70  {
71  public:
72 
74 
82  MemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns,
83  ManagedIceObject* component = nullptr);
84 
85  void initialize(mns::MemoryNameSystemInterfacePrx mns, ManagedIceObject* component = nullptr);
86 
87 
88  mns::MemoryNameSystemInterfacePrx getMemoryNameSystem() const;
89  void getMemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns);
90 
91  void setComponent(ManagedIceObject* component);
92 
93 
94  // Name Resolution
95 
101  void update();
102 
103 
104  // Reader/Writer construction
105 
115 
119  Reader useReader(const std::string& memoryName);
120  Reader useReader(const std::string& memoryName, ManagedIceObject& component);
121 
128  std::map<std::string, Reader> getAllReaders(bool update = true);
134  std::map<std::string, Reader> getAllReaders() const;
135 
136 
146 
150  Writer useWriter(const std::string& memoryName);
151  Writer useWriter(const std::string& memoryName, ManagedIceObject& component);
152 
159  std::map<std::string, Writer> getAllWriters(bool update = true);
165  std::map<std::string, Writer> getAllWriters() const;
166 
167 
168  // ToDo: commit() and query()
169 
180  std::optional<wm::EntityInstance> resolveEntityInstance(const MemoryID& id);
181 
182  std::map<MemoryID, wm::EntityInstance> resolveEntityInstances(const std::vector<MemoryID>& ids);
183 
192  mns::dto::MemoryServerInterfaces resolveServer(const MemoryID& memoryID);
193 
194  // Registration - only for memory servers
195 
204  void registerServer(const MemoryID& memoryID, mns::dto::MemoryServerInterfaces server);
205 
213  void removeServer(const MemoryID& memoryID);
214 
215 
216 
217  // Operators
218 
220  inline operator bool() const
221  {
222  return bool(mns);
223  }
224 
225 
226  private:
227 
236  mns::dto::MemoryServerInterfaces waitForServer(const MemoryID& memoryID);
237 
247  mns::dto::MemoryServerInterfaces useServer(const MemoryID& memoryID);
248  mns::dto::MemoryServerInterfaces useServer(const MemoryID& memoryID, ManagedIceObject& component);
249  mns::dto::MemoryServerInterfaces useServer(const std::string& memoryName);
250  mns::dto::MemoryServerInterfaces useServer(const std::string& memoryName, ManagedIceObject& component);
251 
252 
253  private:
254 
255  template <class ClientT>
256  using ClientFactory = std::function<std::optional<ClientT>(const mns::dto::MemoryServerInterfaces& server)>;
257 
258  template <class ClientT>
259  std::map<std::string, ClientT> _getAllClients(ClientFactory<ClientT>&& factory) const;
260 
261 
263  mns::MemoryNameSystemInterfacePrx mns = nullptr;
264 
266  ManagedIceObject* component = nullptr;
267 
269  std::map<std::string, mns::dto::MemoryServerInterfaces> servers;
270 
271  };
272 
273 
274 }
armarx::armem::client::MemoryNameSystem::resolveServer
mns::dto::MemoryServerInterfaces resolveServer(const MemoryID &memoryID)
Resolve the given memory server for the given memory ID.
Definition: MemoryNameSystem.cpp:97
armarx::armem::client::MemoryNameSystem::removeServer
void removeServer(const MemoryID &memoryID)
Remove a memory server from the MNS.
Definition: MemoryNameSystem.cpp:412
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:25
armarx::armem::wm::EntityInstance
Definition: memory_definitions.h:23
armarx::ProxyType::component
@ component
armarx::armem::client::MemoryNameSystem::getAllReaders
std::map< std::string, Reader > getAllReaders() const
Get Readers for all registered servers (without updating).
Definition: MemoryNameSystem.cpp:262
MemoryID.h
armarx::armem::client::MemoryNameSystem::useWriter
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Definition: MemoryNameSystem.cpp:274
armarx::armem::client::MemoryNameSystem::getAllWriters
std::map< std::string, Writer > getAllWriters() const
Get Writers for all registered servers (without updating).
Definition: MemoryNameSystem.cpp:308
armarx::armem::client
Definition: forward_declarations.h:7
armarx::armem::client::MemoryNameSystem::registerServer
void registerServer(const MemoryID &memoryID, mns::dto::MemoryServerInterfaces server)
Register a memory server in the MNS.
Definition: MemoryNameSystem.cpp:396
armarx::armem::client::MemoryNameSystem::resolveEntityInstance
std::optional< wm::EntityInstance > resolveEntityInstance(const MemoryID &id)
Resolve a memory ID to an EntityInstance.
Definition: MemoryNameSystem.cpp:314
armarx::armem::client::MemoryNameSystem::getWriter
Writer getWriter(const MemoryID &memoryID)
Get a writer to the given memory name.
Definition: MemoryNameSystem.cpp:268
armarx::armem::wm
Definition: MemoryNameSystem.h:46
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:48
armarx::armem::client::MemoryNameSystem::useReader
Reader useReader(const MemoryID &memoryID)
Use a memory server and get a reader for it.
Definition: MemoryNameSystem.cpp:182
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:24
armarx::armem::client::MemoryNameSystem::getMemoryNameSystem
mns::MemoryNameSystemInterfacePrx getMemoryNameSystem() const
Definition: MemoryNameSystem.cpp:426
armarx::armem::client::MemoryNameSystem::resolveEntityInstances
std::map< MemoryID, wm::EntityInstance > resolveEntityInstances(const std::vector< MemoryID > &ids)
Definition: MemoryNameSystem.cpp:328
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:165
Registry.h
armarx::armem::client::MemoryNameSystem::setComponent
void setComponent(ManagedIceObject *component)
Definition: MemoryNameSystem.cpp:438
armarx::armem::client::util::MemoryListener
Handles update signals from the memory system and distributes it to its subsribers.
Definition: MemoryListener.h:27
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::armem::client::MemoryNameSystem::initialize
void initialize(mns::MemoryNameSystemInterfacePrx mns, ManagedIceObject *component=nullptr)
Definition: MemoryNameSystem.cpp:29
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::client::MemoryNameSystem::update
void update()
Update the internal registry to the data in the MNS.
Definition: MemoryNameSystem.cpp:36
armarx::armem::client::MemoryNameSystem::getReader
Reader getReader(const MemoryID &memoryID)
Get a reader to the given memory name.
Definition: MemoryNameSystem.cpp:175
MemoryListener.h
armarx::armem::client::MemoryNameSystem::MemoryNameSystem
MemoryNameSystem()
Definition: MemoryNameSystem.cpp:17
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28