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 
26 #include <assert.h> // for assert
27 
28 #include <atomic> // for atomic, atomic_bool
29 #include <cstddef> // for size_t
30 #include <limits> // for numeric_limits
31 #include <mutex> // for mutex
32 #include <string> // for string
33 #include <unordered_map> // for unordered_map
34 #include <vector> // for vector
35 
36 #include <Ice/BuiltinSequences.h> // for StringSeq
37 #include <Ice/Config.h> // for Long
38 #include <Ice/Current.h> // for Current
39 #include <Ice/Handle.h> // for Handle
40 #include <Ice/Identity.h> // for Identity, IdentitySeq
41 #include <Ice/ObjectF.h> // for ObjectPtr, upCast
42 #include <Ice/PropertiesF.h> // for upCast
43 #include <Ice/ProxyF.h> // for ObjectPrx
44 
45 #include "ArmarXCore/core/ManagedIceObject.h" // for ManagedIceObjectPtr
49 #include "ArmarXCore/interface/core/util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h"
53 #include <ArmarXCore/interface/core/RemoteObjectNode.h> // for upCast, etc
54 
55 namespace armarx
56 {
57  class RemoteObjectNode;
58 
59  /**
60  * @brief An ice handle for a RemoteObjectNodeComponent
61  */
63 
64  /**
65  * @brief Properties for a RemoteObjectNodeComponent
66  */
68  {
69  public:
70  /**
71  * @brief ctor
72  * @param prefix the used prefix for properties
73  */
76  {
77  defineOptionalProperty<int>(
78  "CoreCount", 0, "The used count of cores (<=0 => autodetect)");
79  }
80  };
81 
82  /**
83  * @defgroup Component-RemoteObjectNode RemoteObjectNode
84  * @ingroup ArmarXCore-Components
85  * @brief Implementation of the slice interface RemoteObjectNodeInterface.
86  *
87  */
89  virtual public RemoteObjectNodeInterface,
90  virtual public armarx::Component
91  {
92  public:
93  static unsigned getDefaultCoreCount();
94 
95  /**
96  * @brief ctor
97  */
98  RemoteObjectNode() = default;
99 
100  /**
101  * @brief dtor
102  */
103  ~RemoteObjectNode() override
104  {
105  assert(shuttingDown);
106  }
107 
108  // inherited from Component
109  /**
110  * @brief Returns the object node's default name.
111  * @return The object node's default name.
112  */
113  std::string
114  getDefaultName() const override
115  {
116  return "RemoteObjectNode";
117  }
118 
119  /**
120  * @brief reads in properties
121  */
122  void
123  onInitComponent() override
124  {
125  setCoreCount(getProperty<int>("CoreCount").getValue());
126  }
127 
128  void
130  {
131  }
132 
133  //virtual void onDisconnectComponent() override;
134  /**
135  * @brief Removes all remote objects
136  */
137  void onExitComponent() override;
138 
139  /**
140  * @see PropertyUser::createPropertyDefinitions()
141  */
144  {
146  }
147 
148  //from RemoteObjectNodeInterface
149  Ice::ObjectPrx createPersistentComponent(const std::string& componentFactoryName,
150  const std::string& registrationName,
151  const ComponentParameter& params,
152  const Ice::Current& = Ice::emptyCurrent) override;
153  ClientSideRemoteHandleControlBlockBasePtr
154  createRemoteHandledComponent(const std::string& componentFactoryName,
155  const std::string& registrationName,
156  const ComponentParameter& params,
157  const Ice::Current& = Ice::emptyCurrent) override;
158 
159  Ice::ObjectPrx
161  const Ice::ObjectPtr& registree,
162  const Ice::Current& = Ice::emptyCurrent) override;
163  ClientSideRemoteHandleControlBlockBasePtr
165  const Ice::ObjectPtr& registree,
166  const Ice::Current& = Ice::emptyCurrent) override;
167 
168  Ice::ObjectPrx registerPersistentObject(const std::string& registrationName,
169  const Ice::ObjectPtr& registree,
170  const Ice::Current& = Ice::emptyCurrent) override;
171  ClientSideRemoteHandleControlBlockBasePtr
172  registerRemoteHandledObject(const std::string& registrationName,
173  const Ice::ObjectPtr& registree,
174  const Ice::Current& = Ice::emptyCurrent) override;
175 
176  /**
177  * @brief Returns the number of cores to use.
178  * @return The number of cores to use.
179  */
180  Ice::Long
181  getNumberOfCores(const Ice::Current& = Ice::emptyCurrent) const override
182  {
183  return coreCountUsed;
184  }
185 
186  Ice::Long getNumberOfObjects(const Ice::Current& = Ice::emptyCurrent) const override;
187  Ice::Long
188  getNumberOfPersistentObjects(const Ice::Current& = Ice::emptyCurrent) const override;
189  Ice::Long
190  getNumberOfRemoteHandledObjects(const Ice::Current& = Ice::emptyCurrent) const override;
191  Ice::StringSeq
192  getKnownComponentFactories(const Ice::Current& = Ice::emptyCurrent) const override;
193 
194  virtual void setCoreCount(int newCount);
195 
196  protected:
197  //setup the object to be available per proxy
199  {
201  Ice::ObjectPrx prx;
202  };
203 
205  std::string registrationName);
206  ManagedIceObjectPtrAndPrx setupComponent(const std::string& componentFactoryName,
207  const std::string& registrationName,
208  const ComponentParameter& params);
209 
211  {
213  Ice::ObjectPrx prx;
214  };
215 
217 
218  //helper add data to the RON
219  ClientSideRemoteHandleControlBlockBasePtr
221  ClientSideRemoteHandleControlBlockBasePtr
225 
226  //cleanup
228  void shutdownAndCleanup();
229 
230  //data
232  std::atomic_bool shuttingDown{false};
233 
234  /**
235  * @brief the map of running objects
236  */
237  std::unordered_map<Ice::Long, RemoteHandleControlBlockPtr> remoteHandledObjects;
238  /**
239  * @brief The persistent managed ice objects
240  */
241  std::vector<ManagedIceObjectPtr> persistentManagedIceObjects;
242  /**
243  * @brief The identities of persistent ice objects
244  */
246 
247  /**
248  * @brief mutex to protect the map
249  */
250  mutable std::mutex dataMutex;
251 
252  /**
253  * @brief The nuber of cores returned, when querried for it.
254  */
255  std::size_t coreCountUsed;
256  };
257 } // namespace armarx
armarx::RemoteObjectNode::getKnownComponentFactories
Ice::StringSeq getKnownComponentFactories(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:108
armarx::RemoteObjectNode::getDefaultName
std::string getDefaultName() const override
Returns the object node's default name.
Definition: RemoteObjectNode.h:114
armarx::RemoteObjectNode::setupManagedIceObject
ManagedIceObjectPtrAndPrx setupManagedIceObject(ManagedIceObjectPtr mioPtr, std::string registrationName)
Definition: RemoteObjectNode.cpp:222
armarx::RemoteObjectNode::persistentIceObjectIdentities
Ice::IdentitySeq persistentIceObjectIdentities
The identities of persistent ice objects.
Definition: RemoteObjectNode.h:245
armarx::RemoteObjectNode::registerPersistentObject
Ice::ObjectPrx registerPersistentObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:180
armarx::RemoteObjectNode::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: RemoteObjectNode.h:129
RemoteHandle.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::RemoteObjectNode::IceObjectIdentityAndPrx::prx
Ice::ObjectPrx prx
Definition: RemoteObjectNode.h:213
armarx::RemoteObjectNode::nextRemoteHandledObjectId
std::atomic< Ice::Long > nextRemoteHandledObjectId
Definition: RemoteObjectNode.h:231
armarx::RemoteObjectNode::getNumberOfRemoteHandledObjects
Ice::Long getNumberOfRemoteHandledObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:101
armarx::RemoteObjectNode::IceObjectIdentityAndPrx::ident
Ice::Identity ident
Definition: RemoteObjectNode.h:212
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx::ptr
ManagedIceObjectPtr ptr
Definition: RemoteObjectNode.h:200
armarx::RemoteObjectNodePropertyDefinitions
Properties for a RemoteObjectNodeComponent.
Definition: RemoteObjectNode.h:67
armarx::RemoteObjectNode::doRegisterRemoteHandledManagedIceObjectAtRON
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
Definition: RemoteObjectNode.cpp:254
armarx::RemoteObjectNode::persistentManagedIceObjects
std::vector< ManagedIceObjectPtr > persistentManagedIceObjects
The persistent managed ice objects.
Definition: RemoteObjectNode.h:241
armarx::RemoteObjectNode::getDefaultCoreCount
static unsigned getDefaultCoreCount()
Definition: RemoteObjectNode.cpp:64
IceInternal::Handle< RemoteObjectNode >
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::RemoteObjectNode::onInitComponent
void onInitComponent() override
reads in properties
Definition: RemoteObjectNode.h:123
Property.h
armarx::RemoteObjectNode::onExitComponent
void onExitComponent() override
Removes all remote objects.
Definition: RemoteObjectNode.cpp:79
ManagedIceObject.h
armarx::RemoteObjectNodePropertyDefinitions::RemoteObjectNodePropertyDefinitions
RemoteObjectNodePropertyDefinitions(std::string prefix)
ctor
Definition: RemoteObjectNode.h:74
PropertyUser.h
RemoteHandleControlBlock.h
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx::prx
Ice::ObjectPrx prx
Definition: RemoteObjectNode.h:201
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::RemoteObjectNode::setupComponent
ManagedIceObjectPtrAndPrx setupComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params)
Definition: RemoteObjectNode.cpp:232
armarx::RemoteObjectNode
Definition: RemoteObjectNode.h:88
armarx::RemoteObjectNode::doRegisterPersistentIceObjectAtRON
Ice::ObjectPrx doRegisterPersistentIceObjectAtRON(IceObjectIdentityAndPrx io)
Definition: RemoteObjectNode.cpp:329
armarx::RemoteObjectNode::getNumberOfCores
Ice::Long getNumberOfCores(const Ice::Current &=Ice::emptyCurrent) const override
Returns the number of cores to use.
Definition: RemoteObjectNode.h:181
armarx::RemoteObjectNode::getNumberOfPersistentObjects
Ice::Long getNumberOfPersistentObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:94
armarx::RemoteObjectNode::registerRemoteHandledObjectWithIdentity
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:161
armarx::RemoteObjectNode::getNumberOfObjects
Ice::Long getNumberOfObjects(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteObjectNode.cpp:86
armarx::RemoteObjectNode::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RemoteObjectNode.h:143
armarx::RemoteObjectNode::coreCountUsed
std::size_t coreCountUsed
The nuber of cores returned, when querried for it.
Definition: RemoteObjectNode.h:255
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::RemoteObjectNode::IceObjectIdentityAndPrx
Definition: RemoteObjectNode.h:210
armarx::RemoteObjectNode::shutdownAndCleanup
void shutdownAndCleanup()
Definition: RemoteObjectNode.cpp:360
armarx::RemoteObjectNode::setupIceObject
IceObjectIdentityAndPrx setupIceObject(const Ice::ObjectPtr &ptr, Ice::Identity ident)
Definition: RemoteObjectNode.cpp:247
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:114
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:79
armarx::RemoteObjectNode::setCoreCount
virtual void setCoreCount(int newCount)
Definition: RemoteObjectNode.cpp:70
armarx::RemoteObjectNode::shuttingDown
std::atomic_bool shuttingDown
Definition: RemoteObjectNode.h:232
armarx::RemoteObjectNode::doRegisterRemoteHandledIceObjectAtRON
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledIceObjectAtRON(IceObjectIdentityAndPrx io)
Definition: RemoteObjectNode.cpp:284
armarx::RemoteObjectNode::~RemoteObjectNode
~RemoteObjectNode() override
dtor
Definition: RemoteObjectNode.h:103
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
PropertyDefinition.hpp
armarx::RemoteObjectNode::registerRemoteHandledObject
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:201
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteObjectNode::dataMutex
std::mutex dataMutex
mutex to protect the map
Definition: RemoteObjectNode.h:250
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:128
armarx::RemoteObjectNode::removeRemoteHandledObject
void removeRemoteHandledObject(Ice::Long id)
Definition: RemoteObjectNode.cpp:345
armarx::RemoteObjectNode::ManagedIceObjectPtrAndPrx
Definition: RemoteObjectNode.h:198
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
min
T min(T t1, T t2)
Definition: gdiam.h:44
armarx::RemoteObjectNode::doRegisterPersistentManagedIceObjectAtRON
Ice::ObjectPrx doRegisterPersistentManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
Definition: RemoteObjectNode.cpp:313
armarx::RemoteObjectNode::remoteHandledObjects
std::unordered_map< Ice::Long, RemoteHandleControlBlockPtr > remoteHandledObjects
the map of running objects
Definition: RemoteObjectNode.h:237
armarx::RemoteObjectNode::registerPersistentObjectWithIdentity
Ice::ObjectPrx registerPersistentObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteObjectNode.cpp:142
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27