RemoteObjectNode.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
29 #include <ArmarXCore/interface/core/RemoteObjectNode.h> // for upCast, etc
30 #include <Ice/BuiltinSequences.h> // for StringSeq
31 #include <Ice/Config.h> // for Long
32 #include <Ice/Current.h> // for Current
33 #include <Ice/Handle.h> // for Handle
34 #include <Ice/Identity.h> // for Identity, IdentitySeq
35 #include <Ice/ObjectF.h> // for ObjectPtr, upCast
36 #include <Ice/PropertiesF.h> // for upCast
37 #include <Ice/ProxyF.h> // for ObjectPrx
38 #include <assert.h> // for assert
39 #include <atomic> // for atomic, atomic_bool
40 #include <cstddef> // for size_t
41 #include <limits> // for numeric_limits
42 #include <mutex> // for mutex
43 #include <string> // for string
44 #include <unordered_map> // for unordered_map
45 #include <vector> // for vector
46 
47 #include "ArmarXCore/core/ManagedIceObject.h" // for ManagedIceObjectPtr
51 #include "ArmarXCore/interface/core/util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h"
52 
53 namespace armarx
54 {
55  class RemoteObjectNode;
56 
57  /**
58  * @brief An ice handle for a RemoteObjectNodeComponent
59  */
61 
62  /**
63  * @brief Properties for a RemoteObjectNodeComponent
64  */
67  {
68  public:
69  /**
70  * @brief ctor
71  * @param prefix the used prefix for properties
72  */
75  {
76  defineOptionalProperty<int>("CoreCount", 0, "The used count of cores (<=0 => autodetect)");
77  }
78  };
79 
80  /**
81  * @defgroup Component-RemoteObjectNode RemoteObjectNode
82  * @ingroup ArmarXCore-Components
83  * @brief Implementation of the slice interface RemoteObjectNodeInterface.
84  *
85  */
87  virtual public RemoteObjectNodeInterface,
88  virtual public armarx::Component
89  {
90  public:
91  static unsigned getDefaultCoreCount();
92 
93  /**
94  * @brief ctor
95  */
96  RemoteObjectNode() = default;
97 
98  /**
99  * @brief dtor
100  */
101  ~RemoteObjectNode() override
102  {
103  assert(shuttingDown);
104  }
105 
106  // inherited from Component
107  /**
108  * @brief Returns the object node's default name.
109  * @return The object node's default name.
110  */
111  std::string getDefaultName() const override
112  {
113  return "RemoteObjectNode";
114  }
115  /**
116  * @brief reads in properties
117  */
118  void onInitComponent() override
119  {
120  setCoreCount(getProperty<int>("CoreCount").getValue());
121  }
122 
123  void onConnectComponent() override {}
124  //virtual void onDisconnectComponent() override;
125  /**
126  * @brief Removes all remote objects
127  */
128  void onExitComponent() override;
129 
130  /**
131  * @see PropertyUser::createPropertyDefinitions()
132  */
134  {
136  }
137 
138  //from RemoteObjectNodeInterface
139  Ice::ObjectPrx createPersistentComponent(const std::string& componentFactoryName, const std::string& registrationName, const ComponentParameter& params, const Ice::Current& = Ice::emptyCurrent) override;
140  ClientSideRemoteHandleControlBlockBasePtr createRemoteHandledComponent(const std::string& componentFactoryName, const std::string& registrationName, const ComponentParameter& params, const Ice::Current& = Ice::emptyCurrent) override;
141 
142  Ice::ObjectPrx registerPersistentObjectWithIdentity(const Ice::Identity& ident, const Ice::ObjectPtr& registree, const Ice::Current& = Ice::emptyCurrent) override;
143  ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObjectWithIdentity(const Ice::Identity& ident, const Ice::ObjectPtr& registree, const Ice::Current& = Ice::emptyCurrent) override;
144 
145  Ice::ObjectPrx registerPersistentObject(const std::string& registrationName, const Ice::ObjectPtr& registree, const Ice::Current& = Ice::emptyCurrent) override;
146  ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObject(const std::string& registrationName, const Ice::ObjectPtr& registree, const Ice::Current& = Ice::emptyCurrent) override;
147 
148  /**
149  * @brief Returns the number of cores to use.
150  * @return The number of cores to use.
151  */
152  Ice::Long getNumberOfCores(const Ice::Current& = Ice::emptyCurrent) const override
153  {
154  return coreCountUsed;
155  }
156  Ice::Long getNumberOfObjects(const Ice::Current& = Ice::emptyCurrent) const override;
157  Ice::Long getNumberOfPersistentObjects(const Ice::Current& = Ice::emptyCurrent) const override;
158  Ice::Long getNumberOfRemoteHandledObjects(const Ice::Current& = Ice::emptyCurrent) const override;
159  Ice::StringSeq getKnownComponentFactories(const Ice::Current& = Ice::emptyCurrent) const override;
160 
161  virtual void setCoreCount(int newCount);
162  protected:
163  //setup the object to be available per proxy
165  {
167  Ice::ObjectPrx prx;
168 
169  };
170 
171  ManagedIceObjectPtrAndPrx setupManagedIceObject(ManagedIceObjectPtr mioPtr, std::string registrationName);
172  ManagedIceObjectPtrAndPrx setupComponent(const std::string& componentFactoryName, const std::string& registrationName, const ComponentParameter& params);
173 
175  {
177  Ice::ObjectPrx prx;
178  };
179 
181 
182  //helper add data to the RON
183  ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio);
184  ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledIceObjectAtRON(IceObjectIdentityAndPrx io);
187 
188  //cleanup
190  void shutdownAndCleanup();
191 
192  //data
194  std::atomic_bool shuttingDown {false};
195 
196  /**
197  * @brief the map of running objects
198  */
199  std::unordered_map<Ice::Long, RemoteHandleControlBlockPtr> remoteHandledObjects;
200  /**
201  * @brief The persistent managed ice objects
202  */
203  std::vector<ManagedIceObjectPtr> persistentManagedIceObjects;
204  /**
205  * @brief The identities of persistent ice objects
206  */
208 
209  /**
210  * @brief mutex to protect the map
211  */
212  mutable std::mutex dataMutex;
213 
214  /**
215  * @brief The nuber of cores returned, when querried for it.
216  */
217  std::size_t coreCountUsed;
218  };
219 }
armarx::RemoteObjectNode::getKnownComponentFactories
Ice::StringSeq getKnownComponentFactories(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:96
armarx::RemoteObjectNode::getDefaultName
std::string getDefaultName() const override
Returns the object node's default name.
Definition: RemoteObjectNode.h:111
armarx::RemoteObjectNode::setupManagedIceObject
ManagedIceObjectPtrAndPrx setupManagedIceObject(ManagedIceObjectPtr mioPtr, std::string registrationName)
Definition: RemoteObjectNode.cpp:180
armarx::RemoteObjectNode::persistentIceObjectIdentities
Ice::IdentitySeq persistentIceObjectIdentities
The identities of persistent ice objects.
Definition: RemoteObjectNode.h:207
armarx::RemoteObjectNode::registerPersistentObject
Ice::ObjectPrx registerPersistentObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:147
armarx::RemoteObjectNode::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: RemoteObjectNode.h:123
RemoteHandle.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::RemoteObjectNode::IceObjectIdentityAndPrx::prx
Ice::ObjectPrx prx
Definition: RemoteObjectNode.h:177
armarx::RemoteObjectNode::nextRemoteHandledObjectId
std::atomic< Ice::Long > nextRemoteHandledObjectId
Definition: RemoteObjectNode.h:193
armarx::RemoteObjectNode::getNumberOfRemoteHandledObjects
Ice::Long getNumberOfRemoteHandledObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:91
armarx::RemoteObjectNode::IceObjectIdentityAndPrx::ident
Ice::Identity ident
Definition: RemoteObjectNode.h:176
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx::ptr
ManagedIceObjectPtr ptr
Definition: RemoteObjectNode.h:166
armarx::RemoteObjectNodePropertyDefinitions
Properties for a RemoteObjectNodeComponent.
Definition: RemoteObjectNode.h:65
armarx::RemoteObjectNode::doRegisterRemoteHandledManagedIceObjectAtRON
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
Definition: RemoteObjectNode.cpp:201
armarx::RemoteObjectNode::persistentManagedIceObjects
std::vector< ManagedIceObjectPtr > persistentManagedIceObjects
The persistent managed ice objects.
Definition: RemoteObjectNode.h:203
armarx::RemoteObjectNode::getDefaultCoreCount
static unsigned getDefaultCoreCount()
Definition: RemoteObjectNode.cpp:62
IceInternal::Handle< RemoteObjectNode >
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::RemoteObjectNode::onInitComponent
void onInitComponent() override
reads in properties
Definition: RemoteObjectNode.h:118
Property.h
armarx::RemoteObjectNode::onExitComponent
void onExitComponent() override
Removes all remote objects.
Definition: RemoteObjectNode.cpp:75
ManagedIceObject.h
armarx::RemoteObjectNodePropertyDefinitions::RemoteObjectNodePropertyDefinitions
RemoteObjectNodePropertyDefinitions(std::string prefix)
ctor
Definition: RemoteObjectNode.h:73
PropertyUser.h
RemoteHandleControlBlock.h
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx::prx
Ice::ObjectPrx prx
Definition: RemoteObjectNode.h:167
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::RemoteObjectNode::setupComponent
ManagedIceObjectPtrAndPrx setupComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params)
Definition: RemoteObjectNode.cpp:187
armarx::RemoteObjectNode
Definition: RemoteObjectNode.h:86
armarx::RemoteObjectNode::doRegisterPersistentIceObjectAtRON
Ice::ObjectPrx doRegisterPersistentIceObjectAtRON(IceObjectIdentityAndPrx io)
Definition: RemoteObjectNode.cpp:270
armarx::RemoteObjectNode::getNumberOfCores
Ice::Long getNumberOfCores(const Ice::Current &=Ice::emptyCurrent) const override
Returns the number of cores to use.
Definition: RemoteObjectNode.h:152
armarx::RemoteObjectNode::getNumberOfPersistentObjects
Ice::Long getNumberOfPersistentObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:86
armarx::RemoteObjectNode::registerRemoteHandledObjectWithIdentity
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:132
armarx::RemoteObjectNode::getNumberOfObjects
Ice::Long getNumberOfObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:81
armarx::RemoteObjectNode::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RemoteObjectNode.h:133
armarx::RemoteObjectNode::coreCountUsed
std::size_t coreCountUsed
The nuber of cores returned, when querried for it.
Definition: RemoteObjectNode.h:217
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::RemoteObjectNode::IceObjectIdentityAndPrx
Definition: RemoteObjectNode.h:174
armarx::RemoteObjectNode::shutdownAndCleanup
void shutdownAndCleanup()
Definition: RemoteObjectNode.cpp:298
armarx::RemoteObjectNode::setupIceObject
IceObjectIdentityAndPrx setupIceObject(const Ice::ObjectPtr &ptr, Ice::Identity ident)
Definition: RemoteObjectNode.cpp:195
armarx::RemoteObjectNode::createPersistentComponent
Ice::ObjectPrx createPersistentComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:101
armarx::RemoteObjectNode::RemoteObjectNode
RemoteObjectNode()=default
ctor
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::RemoteObjectNode::setCoreCount
virtual void setCoreCount(int newCount)
Definition: RemoteObjectNode.cpp:67
armarx::RemoteObjectNode::shuttingDown
std::atomic_bool shuttingDown
Definition: RemoteObjectNode.h:194
armarx::RemoteObjectNode::doRegisterRemoteHandledIceObjectAtRON
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledIceObjectAtRON(IceObjectIdentityAndPrx io)
Definition: RemoteObjectNode.cpp:229
armarx::RemoteObjectNode::~RemoteObjectNode
~RemoteObjectNode() override
dtor
Definition: RemoteObjectNode.h:101
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
PropertyDefinition.hpp
armarx::RemoteObjectNode::registerRemoteHandledObject
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:163
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteObjectNode::dataMutex
std::mutex dataMutex
mutex to protect the map
Definition: RemoteObjectNode.h:212
armarx::RemoteObjectNode::createRemoteHandledComponent
ClientSideRemoteHandleControlBlockBasePtr createRemoteHandledComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:109
armarx::RemoteObjectNode::removeRemoteHandledObject
void removeRemoteHandledObject(Ice::Long id)
Definition: RemoteObjectNode.cpp:284
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx
Definition: RemoteObjectNode.h:164
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
min
T min(T t1, T t2)
Definition: gdiam.h:42
armarx::RemoteObjectNode::doRegisterPersistentManagedIceObjectAtRON
Ice::ObjectPrx doRegisterPersistentManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
Definition: RemoteObjectNode.cpp:257
armarx::RemoteObjectNode::remoteHandledObjects
std::unordered_map< Ice::Long, RemoteHandleControlBlockPtr > remoteHandledObjects
the map of running objects
Definition: RemoteObjectNode.h:199
armarx::RemoteObjectNode::registerPersistentObjectWithIdentity
Ice::ObjectPrx registerPersistentObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:118
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28