Orocos Real-Time Toolkit  2.8.3
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  ret[i] = CORBA::string_dup( names[i].c_str() );
134  return ret._retn();
135 }
136 
138  void)
139 {
140  ::RTT::corba::CConfigurationInterface::CPropertyNames_var ret = new ::RTT::corba::CConfigurationInterface::CPropertyNames();
141  if (mar)
142  mbag = mar->properties();
143 
144  vector<string> allprops = listProperties( *mbag );
145  vector<string> alldescs = listPropertyDescriptions( *mbag );
146 
147  ret->length( allprops.size() );
148  vector<string>::iterator it = allprops.begin();
149  vector<string>::iterator dit = alldescs.begin();
150  size_t index = 0;
151  for( ; it != allprops.end(); ++it, ++index, ++dit) {
153  prop.name = CORBA::string_dup( it->c_str() );
154  prop.description = CORBA::string_dup( dit->c_str() );
155  ret[index] = prop;
156  }
157  return ret._retn();
158 }
159 
161  const char * name)
162 {
163  if ( !mar || !mar->hasAttribute( string(name) ) )
164  return new CORBA::Any();
165  DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
166  const TypeInfo* ti = ds->getTypeInfo();
168  assert( ctt );
169  try {
170  return ctt->createAny( ds );
171  } catch(std::exception const& e) {
172  throw StdException(e.what());
173  }
174 }
175 
177  const char * name,
178  const ::CORBA::Any & value)
179 {
180  if ( !mar || !mar->hasAttribute( string(name) ) )
181  return 0;
182  DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
183  const TypeInfo* ti = ds->getTypeInfo();
185  assert( ctt );
186  return ctt->updateFromAny( &value, ds );
187 }
188 
190  const char * name)
191 {
192  if (mar)
193  mbag = mar->properties(); // leave this here to get latest propertybag.
194  if ( mbag == 0 )
195  return new CORBA::Any();
197  if ( !ds ) {
198  log(Error) <<"CConfigurationInterface: no such property: " << name << ". Returning empty CORBA::Any."<<endlog();
199  return new CORBA::Any();
200  }
201  const TypeInfo* ti = ds->getTypeInfo();
203  assert( ctt );
204  try {
205  return ctt->createAny( ds );
206  } catch(std::exception const& e) {
207  throw StdException(e.what());
208  }
209 }
210 
212  const char * name,
213  const ::CORBA::Any & value)
214 {
215  if (mar)
216  mbag = mar->properties(); // leave this here to get latest propertybag.
218  if ( !ds )
219  return 0;
220  const TypeInfo* ti = ds->getTypeInfo();
222  assert( ctt );
223  return ctt->updateFromAny( &value, ds );
224 }
225 
227  const char * name)
228 {
229  return mar->hasAttribute( name );
230 }
231 
233  const char * name)
234 {
235  if (mar->getValue(name))
236  return mar->getValue(name)->getDataSource()->isAssignable();
237  return 0;
238 }
240  const char * name)
241 {
243  if (ds)
244  return CORBA::string_dup( ds->getType().c_str() );
245  return CORBA::string_dup( "na" );
246 }
247 
249  const char * name)
250 {
252  if (ds)
253  return CORBA::string_dup( ds->getTypeName().c_str() );
254  return CORBA::string_dup( "na" );
255 }
256 
258  const char * name)
259 {
261  if (ds) {
262  std::string result = ds->toString();
263  return CORBA::string_dup( result.c_str() );
264  }
265  return CORBA::string_dup( "na" );
266 }
267 
269  const char* name, const char* value
270  )
271 {
273  if (!ds)
274  return false;
275  if ( ds->getTypeInfo()->fromString( value, ds ) ) {
276  RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
277  return false;
278  }
279  return true;
280 }
281 
283  const char * name)
284 {
285  // converts result to bool.
286  return bool( getPropertyDataSource(name) );
287 }
289  const char * name)
290 {
292  if (ds)
293  return CORBA::string_dup( ds->getType().c_str() );
294  return CORBA::string_dup( "na" );
295 }
296 
298  const char * name)
299 {
301  if (ds)
302  return CORBA::string_dup( ds->getTypeName().c_str() );
303  return CORBA::string_dup( "na" );
304 }
305 
307  const char * name)
308 {
310  if (ds) {
311  std::string result = ds->toString();
312  return CORBA::string_dup( result.c_str() );
313  }
314  return CORBA::string_dup( "na" );
315 }
316 
318  const char* name, const char* value
319  )
320 {
322  if (!ds)
323  return false;
324  if ( ds->getTypeInfo()->fromString( value, ds ) ) {
325  RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
326  return false;
327  }
328  return true;
329 }
330 
331 
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:66
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:51
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)