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
55namespace 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 {
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 */
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
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 */
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
160 registerPersistentObjectWithIdentity(const Ice::Identity& ident,
161 const Ice::ObjectPtr& registree,
162 const Ice::Current& = Ice::emptyCurrent) override;
163 ClientSideRemoteHandleControlBlockBasePtr
164 registerRemoteHandledObjectWithIdentity(const Ice::Identity& ident,
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 {
212 Ice::Identity ident;
213 Ice::ObjectPrx prx;
214 };
215
216 IceObjectIdentityAndPrx setupIceObject(const Ice::ObjectPtr& ptr, Ice::Identity ident);
217
218 //helper add data to the RON
219 ClientSideRemoteHandleControlBlockBasePtr
221 ClientSideRemoteHandleControlBlockBasePtr
225
226 //cleanup
227 void removeRemoteHandledObject(Ice::Long id);
228 void shutdownAndCleanup();
229
230 //data
231 std::atomic<Ice::Long> nextRemoteHandledObjectId{std::numeric_limits<Ice::Long>::min()};
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
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Properties for a RemoteObjectNodeComponent.
RemoteObjectNodePropertyDefinitions(std::string prefix)
ctor
Ice::Long getNumberOfCores(const Ice::Current &=Ice::emptyCurrent) const override
Returns the number of cores to use.
void onInitComponent() override
reads in properties
Ice::ObjectPrx registerPersistentObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
ClientSideRemoteHandleControlBlockBasePtr createRemoteHandledComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params, const Ice::Current &=Ice::emptyCurrent) override
RemoteObjectNode()=default
ctor
Ice::ObjectPrx doRegisterPersistentManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
IceObjectIdentityAndPrx setupIceObject(const Ice::ObjectPtr &ptr, Ice::Identity ident)
Ice::ObjectPrx doRegisterPersistentIceObjectAtRON(IceObjectIdentityAndPrx io)
std::vector< ManagedIceObjectPtr > persistentManagedIceObjects
The persistent managed ice objects.
Ice::Long getNumberOfRemoteHandledObjects(const Ice::Current &=Ice::emptyCurrent) const override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Ice::Long getNumberOfObjects(const Ice::Current &=Ice::emptyCurrent) const override
Ice::ObjectPrx registerPersistentObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledIceObjectAtRON(IceObjectIdentityAndPrx io)
ClientSideRemoteHandleControlBlockBasePtr doRegisterRemoteHandledManagedIceObjectAtRON(ManagedIceObjectPtrAndPrx mio)
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObjectWithIdentity(const Ice::Identity &ident, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
std::atomic_bool shuttingDown
static unsigned getDefaultCoreCount()
std::atomic< Ice::Long > nextRemoteHandledObjectId
Ice::IdentitySeq persistentIceObjectIdentities
The identities of persistent ice objects.
std::size_t coreCountUsed
The nuber of cores returned, when querried for it.
Ice::Long getNumberOfPersistentObjects(const Ice::Current &=Ice::emptyCurrent) const override
void onConnectComponent() override
Pure virtual hook for the subclass.
virtual void setCoreCount(int newCount)
Ice::StringSeq getKnownComponentFactories(const Ice::Current &=Ice::emptyCurrent) const override
ManagedIceObjectPtrAndPrx setupComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params)
ClientSideRemoteHandleControlBlockBasePtr registerRemoteHandledObject(const std::string &registrationName, const Ice::ObjectPtr &registree, const Ice::Current &=Ice::emptyCurrent) override
std::mutex dataMutex
mutex to protect the map
void removeRemoteHandledObject(Ice::Long id)
void onExitComponent() override
Removes all remote objects.
std::unordered_map< Ice::Long, RemoteHandleControlBlockPtr > remoteHandledObjects
the map of running objects
ManagedIceObjectPtrAndPrx setupManagedIceObject(ManagedIceObjectPtr mioPtr, std::string registrationName)
std::string getDefaultName() const override
Returns the object node's default name.
Ice::ObjectPrx createPersistentComponent(const std::string &componentFactoryName, const std::string &registrationName, const ComponentParameter &params, const Ice::Current &=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< ManagedIceObject > ManagedIceObjectPtr
Definition ArmarXFwd.h:42
IceInternal::Handle< RemoteObjectNode > RemoteObjectNodePtr
An ice handle for a RemoteObjectNodeComponent.