Component.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::core
19 * @author Kai Welke (welke at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
28 #include <ArmarXCore/core/ManagedIceObject.h> // for ManagedIceObject
35 
36 #include <Ice/Handle.h> // for Handle
37 
38 #include <string> // for string
39 
40 // Forward declarations
41 namespace Ice
42 {
44 }
45 
46 namespace armarx
47 {
48 
54  class Component;
55 
58 
59  class ComponentPlugin;
60 
61 
72  {
73  public:
74 
75  ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter = true);
76  };
77 
78 
96  virtual public ManagedIceObject,
97  virtual public PropertyUser
98  {
99  public:
118  template <class T, class TPtr = IceInternal::Handle<T>>
119  static TPtr create(Ice::PropertiesPtr properties = Ice::createProperties(),
120  const std::string& configName = "", const std::string& configDomain = "ArmarX")
121  {
122  ARMARX_TRACE;
123  ARMARX_DEBUG_S << "create component (configName = " << configName
124  << ", configDomain = " << configDomain << " of type "
125  << GetTypeString<T>();
126  TPtr ptr = new T();
127  ptr->createdByComponentCreate = true;
128 
129  ComponentPtr compPtr = ptr;
130 
131  ARMARX_DEBUG_S << "initializing properties";
132  if (configName == "")
133  {
134  ptr->initializeProperties(compPtr->getDefaultName(), properties, configDomain);
135  }
136  else
137  {
138  ptr->initializeProperties(configName, properties, configDomain);
139  }
140  ARMARX_DEBUG_S << "call post ini properties hook";
141  compPtr->icePropertiesInitialized();
142  ARMARX_DEBUG_S << "returning component";
143  return ptr;
144  }
145 
148 
153  virtual void componentPropertiesUpdated(const std::set<std::string>& changedProperties);
154 
155  virtual void preOnInitComponent() override;
156  virtual void preOnConnectComponent() override;
157 
166  void initializeProperties(const std::string& configName, Ice::PropertiesPtr const& properties, const std::string& configDomain);
167 
169  void injectPropertyDefinitions(PropertyDefinitionsPtr& props) override;
170 
175  void forceComponentCreatedByComponentCreateFunc();
176 
177 
178  std::vector<PropertyUserPtr> getAdditionalPropertyUsers() const;
179 
180 
181  // Convenience wrappers for {offering|using|get}{Topic|Proxy}() with name from property.
182 
189  void offeringTopicFromProperty(const std::string& propertyName);
190 
198  void usingTopicFromProperty(const std::string& propertyName, bool orderedPublishing = false);
199 
208  bool usingProxyFromProperty(const std::string& propertyName, const std::string& endpoints = "");
209 
217  template <class TopicProxyType>
218  TopicProxyType getTopicFromProperty(const std::string& propertyName)
219  {
220  return getTopic<TopicProxyType>(getProperty<std::string>(propertyName));
221  }
222  template <class TopicProxyType>
223  void getTopicFromProperty(TopicProxyType& top, const std::string& propertyName)
224  {
225  top = getTopic<TopicProxyType>(getProperty<std::string>(propertyName));
226  }
227 
235  template <class ProxyType>
236  ProxyType getProxyFromProperty(const std::string& propertyName,
237  bool addToDependencies = false,
238  const std::string& endpoints = "",
239  bool throwOnProxyError = true)
240  {
241  return getProxy<ProxyType>(getProperty<std::string>(propertyName),
242  addToDependencies, endpoints, throwOnProxyError);
243  }
244  template <class ProxyType>
245  void getProxyFromProperty(ProxyType& proxy, const std::string& propertyName,
246  bool addToDependencies = false,
247  const std::string& endpoints = "",
248  bool throwOnProxyError = true)
249  {
250  proxy = getProxy<ProxyType>(getProperty<std::string>(propertyName),
251  addToDependencies, endpoints, throwOnProxyError);
252  }
253 
254 
255  protected:
256 
258  Component();
259 
260 
262  PropertyDefinitionsPtr createPropertyDefinitions() override;
263 
271  std::string getConfigDomain();
272 
280  std::string getConfigName();
281 
293  std::string getConfigIdentifier();
294 
295 
296 
297  virtual void icePropertiesInitialized() {}
298 
304  void addPropertyUser(const PropertyUserPtr& subPropertyUser);
305 
306 
307  private:
308 
309  friend class ArmarXManager;
310 
316  void icePropertiesUpdated(const std::set<std::string>& changedProperties) override final;
317 
318 
319  // idenfitication of properties
320  std::string configDomain;
321  std::string configName;
322 
323  std::vector<PropertyUserPtr> additionalPropertyUsers;
324 
325 
330  bool createdByComponentCreate;
331  };
332 
333 }
334 
GetTypeString.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::Component::getTopicFromProperty
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition: Component.h:218
IceInternal::Handle< ::Ice::Properties >
armarx::Component::icePropertiesInitialized
virtual void icePropertiesInitialized()
Definition: Component.h:297
armarx::Component::getProxyFromProperty
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
Definition: Component.h:236
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
ManagedIceObject.h
Ice::createProperties
Ice::PropertiesPtr createProperties()
PropertyUser.h
armarx::Component::create
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
Definition: Component.h:119
armarx::ProxyType
ProxyType
Definition: ProxyPropertyDefinition.h:41
armarx::PropertyDefinitionContainer
PropertyDefinitionContainer.
Definition: PropertyDefinitionContainer.h:53
armarx::Component::getProxyFromProperty
void getProxyFromProperty(ProxyType &proxy, const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Definition: Component.h:245
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
Ice
Definition: DBTypes.cpp:64
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:165
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
PropertyDefinition.hpp
PropertyDefinitionContainer.h
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
ImportExport.h
armarx::Component::getTopicFromProperty
void getTopicFromProperty(TopicProxyType &top, const std::string &propertyName)
Definition: Component.h:223
armarx::ComponentPtr
IceInternal::Handle< Component > ComponentPtr
Component smart pointer type.
Definition: ArmarXFwd.h:45
ComponentPlugin.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::PropertyUser
Abstract PropertyUser class.
Definition: PropertyUser.h:62
armarx::ArmarXManager
Main class of an ArmarX process.
Definition: ArmarXManager.h:95
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
PropertyDefinition.h