Orocos Real-Time Toolkit  2.9.0
ConfigurationInterfaceI.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 ConfigurationInterfaceI.cpp
3 
4  ConfigurationInterfaceI.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 // -*- C++ -*-
40 //
41 // $Id$
42 
43 // **** Code generated by the The ACE ORB (TAO) IDL Compiler ****
44 // TAO and the TAO IDL Compiler have been developed by:
45 // Center for Distributed Object Computing
46 // Washington University
47 // St. Louis, MO
48 // USA
49 // http://www.cs.wustl.edu/~schmidt/doc-center.html
50 // and
51 // Distributed Object Computing Laboratory
52 // University of California at Irvine
53 // Irvine, CA
54 // USA
55 // http://doc.ece.uci.edu/
56 // and
57 // Institute for Software Integrated Systems
58 // Vanderbilt University
59 // Nashville, TN
60 // USA
61 // http://www.isis.vanderbilt.edu/
62 //
63 // Information about TAO is available at:
64 // http://www.cs.wustl.edu/~schmidt/TAO.html
65 
66 // TAO_IDL - Generated from
67 // ../../../ACE_wrappers/TAO/TAO_IDL/be/be_codegen.cpp:1196
68 
70 #include "ConfigurationInterfaceC.h"
71 #include "CorbaLib.hpp"
72 #include "CorbaTypeTransporter.hpp"
73 #include <vector>
74 #include "../../PropertyBag.hpp"
75 #include "../../Property.hpp"
76 #include "../../rtt-detail-fwd.hpp"
77 
78 using namespace RTT;
79 using namespace RTT::detail;
80 using namespace std;
81 
82 // Implementation skeleton constructor
84  :mar (ar), mbag(0), mpoa( PortableServer::POA::_duplicate(the_poa))
85 {
86 }
87 
89  :mar (0), mbag(bag), mpoa( PortableServer::POA::_duplicate(the_poa))
90 {
91 }
92 
94 {
95  return PortableServer::POA::_duplicate(mpoa);
96 }
97 
98 // Implementation skeleton destructor
100 {
101  // if no ConfigurationInterface, it must have been a PropertyBag.
102  if ( mar == 0 )
103  delete mbag;
104 }
105 
107 {
108  if (!mar)
110  if ( findProperty( *mar->properties(), value_name) )
111  return findProperty( *mar->properties(), value_name)->getDataSource();
113 }
114 
116 {
117  if (!mar)
119  if ( mar->getAttribute(value_name) )
120  return mar->getAttribute(value_name)->getDataSource();
122 }
123 
125  void)
126 {
127  ::RTT::corba::CConfigurationInterface::CAttributeNames_var ret = new ::RTT::corba::CConfigurationInterface::CAttributeNames();
128  if ( !mar )
129  return ret._retn();
130  vector<string> names = mar->getAttributeNames();
131  ret->length( names.size() );
132  for(size_t i=0; i != names.size(); ++i)
133  {
135  ret[i].name = CORBA::string_dup( names[i].c_str() );
136  ret[i].type_name = CORBA::string_dup( ds->getTypeName().c_str() );
137  ret[i].assignable = ds->isAssignable();
138  }
139  return ret._retn();
140 }
141 
143  void)
144 {
145  ::RTT::corba::CConfigurationInterface::CPropertyNames_var ret = new ::RTT::corba::CConfigurationInterface::CPropertyNames();
146  if (mar)
147  mbag = mar->properties();
148 
149  vector<string> allprops = listProperties( *mbag );
150  vector<string> alldescs = listPropertyDescriptions( *mbag );
151 
152  ret->length( allprops.size() );
153  vector<string>::iterator it = allprops.begin();
154  vector<string>::iterator dit = alldescs.begin();
155  size_t index = 0;
156  for( ; it != allprops.end(); ++it, ++index, ++dit) {
158  prop.name = CORBA::string_dup( it->c_str() );
159  prop.description = CORBA::string_dup( dit->c_str() );
160  prop.type_name = getPropertyType((*it).c_str());
161  ret[index] = prop;
162  }
163  return ret._retn();
164 }
165 
167  const char * name)
168 {
169  if ( !mar || !mar->hasAttribute( string(name) ) )
170  return new CORBA::Any();
171  DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
172  const TypeInfo* ti = ds->getTypeInfo();
174  assert( ctt );
175  try {
176  return ctt->createAny( ds );
177  } catch(std::exception const& e) {
178  throw StdException(e.what());
179  }
180 }
181 
183  const char * name,
184  const ::CORBA::Any & value)
185 {
186  if ( !mar || !mar->hasAttribute( string(name) ) )
187  return 0;
188  DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
189  const TypeInfo* ti = ds->getTypeInfo();
191  assert( ctt );
192  return ctt->updateFromAny( &value, ds );
193 }
194 
196  const char * name)
197 {
198  if (mar)
199  mbag = mar->properties(); // leave this here to get latest propertybag.
200  if ( mbag == 0 )
201  return new CORBA::Any();
203  if ( !ds ) {
204  log(Error) <<"CConfigurationInterface: no such property: " << name << ". Returning empty CORBA::Any."<<endlog();
205  return new CORBA::Any();
206  }
207  const TypeInfo* ti = ds->getTypeInfo();
209  assert( ctt );
210  try {
211  return ctt->createAny( ds );
212  } catch(std::exception const& e) {
213  throw StdException(e.what());
214  }
215 }
216 
218  const char * name,
219  const ::CORBA::Any & value)
220 {
221  if (mar)
222  mbag = mar->properties(); // leave this here to get latest propertybag.
224  if ( !ds )
225  return 0;
226  const TypeInfo* ti = ds->getTypeInfo();
228  assert( ctt );
229  return ctt->updateFromAny( &value, ds );
230 }
231 
233  const char * name)
234 {
235  return mar->hasAttribute( name );
236 }
237 
239  const char * name)
240 {
241  if (mar->getValue(name))
242  return mar->getValue(name)->getDataSource()->isAssignable();
243  return 0;
244 }
246  const char * name)
247 {
249  if (ds)
250  return CORBA::string_dup( ds->getType().c_str() );
251  return CORBA::string_dup( "na" );
252 }
253 
255  const char * name)
256 {
258  if (ds)
259  return CORBA::string_dup( ds->getTypeName().c_str() );
260  return CORBA::string_dup( "na" );
261 }
262 
264  const char * name)
265 {
267  if (ds) {
268  std::string result = ds->toString();
269  return CORBA::string_dup( result.c_str() );
270  }
271  return CORBA::string_dup( "na" );
272 }
273 
275  const char* name, const char* value
276  )
277 {
279  if (!ds)
280  return false;
281  if ( ds->getTypeInfo()->fromString( value, ds ) ) {
282  RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
283  return false;
284  }
285  return true;
286 }
287 
289  const char * name)
290 {
291  // converts result to bool.
292  return bool( getPropertyDataSource(name) );
293 }
295  const char * name)
296 {
298  if (ds)
299  return CORBA::string_dup( ds->getType().c_str() );
300  return CORBA::string_dup( "na" );
301 }
302 
304  const char * name)
305 {
307  if (ds)
308  return CORBA::string_dup( ds->getTypeName().c_str() );
309  return CORBA::string_dup( "na" );
310 }
311 
313  const char * name)
314 {
316  if (ds) {
317  std::string result = ds->toString();
318  return CORBA::string_dup( result.c_str() );
319  }
320  return CORBA::string_dup( "na" );
321 }
322 
324  const char* name, const char* value
325  )
326 {
328  if (!ds)
329  return false;
330  if ( ds->getTypeInfo()->fromString( value, ds ) ) {
331  RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
332  return false;
333  }
334  return true;
335 }
336 
337 
bool hasAttribute(const std::string &name) const
Check if an attribute is present in this interface.
virtual ::CORBA::Boolean setAttribute(const char *name, const ::CORBA::Any &value)
virtual ::CORBA::Any * getAttribute(const char *name)
vector< string > listProperties(const PropertyBag &source, const std::string &separator)
List all properties in a PropertyBag in a single list.
virtual ::RTT::corba::CConfigurationInterface::CPropertyNames * getPropertyList(void)
PropertyBag * properties()
Return a bag of all properties.
virtual CORBA::Any_ptr createAny(base::DataSourceBase::shared_ptr source) const =0
Evaluate source and create an any which contains the value of source.
STL namespace.
virtual ::RTT::corba::CConfigurationInterface::CAttributeNames * getAttributeList(void)
virtual char * getPropertyTypeName(const char *name)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
virtual DataSourceBase::shared_ptr getDataSource() const =0
Return a internal::DataSource which contains the same contents.
virtual ::CORBA::Any * getProperty(const char *name)
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
This function locates a Property in nested PropertyBags.
Convenient short notation for every sub-namespace of RTT.
CORBA::Boolean hasProperty(const char *name)
base::AttributeBase * getValue(const std::string &name) const
vector< string > listPropertyDescriptions(const PropertyBag &source, const std::string &separator)
List all descriptions of properties in a PropertyBag in a single list.
virtual char * attributeToString(const char *name)
::RTT::base::DataSourceBase::shared_ptr getAttributeDataSource(const std::string &value_name)
CORBA::Boolean hasAttribute(const char *name)
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:67
RTT_corba_CConfigurationInterface_i(RTT::ConfigurationInterface *ar, PortableServer::POA_ptr the_poa)
base::AttributeBase * getAttribute(const std::string &name) const
A class for keeping track of Attribute, Constant and Property objects of a TaskContext.
virtual char * propertyToString(const char *name)
virtual CORBA::Boolean propertyFromString(const char *name, const char *value)
virtual CORBA::Boolean attributeFromString(const char *name, const char *value)
TypeTransporter * getProtocol(int protocol_id) const
Returns this type&#39;s transport for a given protocol.
Definition: TypeInfo.cpp:150
virtual char * getAttributeTypeName(const char *name)
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
virtual ::CORBA::Boolean setProperty(const char *name, const ::CORBA::Any &value)
AttributeNames getAttributeNames() const
Return the names of all attributes in this repository.
CORBA::Boolean isAttributeAssignable(const char *name)
virtual bool updateFromAny(const CORBA::Any *blob, base::DataSourceBase::shared_ptr target) const =0
Update an assignable datasource target with the contents of blob.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
virtual char * getPropertyType(const char *name)
Extends the TypeTransporter in order to allow the creation of channel elements or output halves for a...
::RTT::base::DataSourceBase::shared_ptr getPropertyDataSource(const std::string &value_name)
virtual char * getAttributeType(const char *name)