ConfigurationInterfaceI.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  ConfigurationInterfaceI.cpp
00003 
00004                         ConfigurationInterfaceI.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 // -*- C++ -*-
00040 //
00041 // $Id$
00042 
00043 // ****  Code generated by the The ACE ORB (TAO) IDL Compiler ****
00044 // TAO and the TAO IDL Compiler have been developed by:
00045 //       Center for Distributed Object Computing
00046 //       Washington University
00047 //       St. Louis, MO
00048 //       USA
00049 //       http://www.cs.wustl.edu/~schmidt/doc-center.html
00050 // and
00051 //       Distributed Object Computing Laboratory
00052 //       University of California at Irvine
00053 //       Irvine, CA
00054 //       USA
00055 //       http://doc.ece.uci.edu/
00056 // and
00057 //       Institute for Software Integrated Systems
00058 //       Vanderbilt University
00059 //       Nashville, TN
00060 //       USA
00061 //       http://www.isis.vanderbilt.edu/
00062 //
00063 // Information about TAO is available at:
00064 //     http://www.cs.wustl.edu/~schmidt/TAO.html
00065 
00066 // TAO_IDL - Generated from
00067 // ../../../ACE_wrappers/TAO/TAO_IDL/be/be_codegen.cpp:1196
00068 
00069 #include "ConfigurationInterfaceI.h"
00070 #include "ConfigurationInterfaceC.h"
00071 #include "CorbaLib.hpp"
00072 #include "CorbaTypeTransporter.hpp"
00073 #include <vector>
00074 #include "../../PropertyBag.hpp"
00075 #include "../../Property.hpp"
00076 #include "../../rtt-detail-fwd.hpp"
00077 
00078 using namespace RTT;
00079 using namespace RTT::detail;
00080 using namespace std;
00081 
00082 // Implementation skeleton constructor
00083 RTT_corba_CConfigurationInterface_i::RTT_corba_CConfigurationInterface_i (ConfigurationInterface* ar, PortableServer::POA_ptr the_poa)
00084     :mar (ar), mbag(0), mpoa( PortableServer::POA::_duplicate(the_poa))
00085 {
00086 }
00087 
00088 RTT_corba_CConfigurationInterface_i::RTT_corba_CConfigurationInterface_i (PropertyBag* bag, PortableServer::POA_ptr the_poa)
00089     :mar (0), mbag(bag), mpoa( PortableServer::POA::_duplicate(the_poa))
00090 {
00091 }
00092 
00093 PortableServer::POA_ptr RTT_corba_CConfigurationInterface_i::_default_POA()
00094 {
00095     return PortableServer::POA::_duplicate(mpoa);
00096 }
00097 
00098 // Implementation skeleton destructor
00099 RTT_corba_CConfigurationInterface_i::~RTT_corba_CConfigurationInterface_i (void)
00100 {
00101     // if no ConfigurationInterface, it must have been a PropertyBag.
00102     if ( mar == 0 )
00103         delete mbag;
00104 }
00105 
00106 ::RTT::base::DataSourceBase::shared_ptr RTT_corba_CConfigurationInterface_i::getPropertyDataSource(const std::string& value_name)
00107 {
00108     if (!mar)
00109         return DataSourceBase::shared_ptr();
00110     if ( findProperty( *mar->properties(), value_name) )
00111         return findProperty( *mar->properties(), value_name)->getDataSource();
00112     return DataSourceBase::shared_ptr();
00113 }
00114 
00115 ::RTT::base::DataSourceBase::shared_ptr RTT_corba_CConfigurationInterface_i::getAttributeDataSource(const std::string& value_name)
00116 {
00117     if (!mar)
00118         return DataSourceBase::shared_ptr();
00119     if ( mar->getAttribute(value_name) )
00120         return mar->getAttribute(value_name)->getDataSource();
00121     return DataSourceBase::shared_ptr();
00122 }
00123 
00124 ::RTT::corba::CConfigurationInterface::CAttributeNames * RTT_corba_CConfigurationInterface_i::getAttributeList (
00125     void)
00126 {
00127     ::RTT::corba::CConfigurationInterface::CAttributeNames_var ret = new ::RTT::corba::CConfigurationInterface::CAttributeNames();
00128     if ( !mar )
00129         return ret._retn();
00130     vector<string> names = mar->getAttributeNames();
00131     ret->length( names.size() );
00132     for(size_t i=0; i != names.size(); ++i)
00133         ret[i] = CORBA::string_dup( names[i].c_str() );
00134     return ret._retn();
00135 }
00136 
00137 ::RTT::corba::CConfigurationInterface::CPropertyNames * RTT_corba_CConfigurationInterface_i::getPropertyList (
00138     void)
00139 {
00140     ::RTT::corba::CConfigurationInterface::CPropertyNames_var ret = new ::RTT::corba::CConfigurationInterface::CPropertyNames();
00141     if (mar)
00142         mbag = mar->properties();
00143 
00144     vector<string> allprops = listProperties( *mbag );
00145     vector<string> alldescs = listPropertyDescriptions( *mbag );
00146 
00147     ret->length( allprops.size() );
00148     vector<string>::iterator it = allprops.begin();
00149     vector<string>::iterator dit = alldescs.begin();
00150     size_t index = 0;
00151     for( ; it != allprops.end(); ++it, ++index, ++dit) {
00152         ::RTT::corba::CConfigurationInterface::CProperty prop;
00153         prop.name = CORBA::string_dup( it->c_str() );
00154         prop.description = CORBA::string_dup( dit->c_str() );
00155         ret[index] = prop;
00156     }
00157     return ret._retn();
00158 }
00159 
00160 ::CORBA::Any * RTT_corba_CConfigurationInterface_i::getAttribute (
00161     const char * name)
00162 {
00163     if ( !mar || !mar->hasAttribute( string(name) ) )
00164         return new CORBA::Any();
00165     DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
00166     const TypeInfo* ti = ds->getTypeInfo();
00167     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00168     assert( ctt );
00169     try {
00170         return ctt->createAny( ds );
00171     } catch(std::exception const& e) {
00172         throw StdException(e.what());
00173     }
00174 }
00175 
00176 ::CORBA::Boolean RTT_corba_CConfigurationInterface_i::setAttribute (
00177     const char * name,
00178     const ::CORBA::Any & value)
00179 {
00180     if ( !mar || !mar->hasAttribute( string(name) ) )
00181         return 0;
00182     DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
00183     const TypeInfo* ti = ds->getTypeInfo();
00184     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00185     assert( ctt );
00186     return ctt->updateFromAny( &value, ds );
00187 }
00188 
00189 ::CORBA::Any * RTT_corba_CConfigurationInterface_i::getProperty (
00190     const char * name)
00191 {
00192     if (mar)
00193         mbag = mar->properties(); // leave this here to get latest propertybag.
00194     if ( mbag == 0 )
00195         return new CORBA::Any();
00196     DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
00197     if ( !ds ) {
00198         log(Error) <<"CConfigurationInterface: no such property: " << name << ". Returning empty CORBA::Any."<<endlog();
00199         return new CORBA::Any();
00200     }
00201     const TypeInfo* ti = ds->getTypeInfo();
00202     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00203     assert( ctt );
00204     try {
00205         return ctt->createAny( ds );
00206     } catch(std::exception const& e) {
00207         throw StdException(e.what());
00208     }
00209 }
00210 
00211 ::CORBA::Boolean RTT_corba_CConfigurationInterface_i::setProperty (
00212     const char * name,
00213     const ::CORBA::Any & value)
00214 {
00215     if (mar)
00216         mbag = mar->properties(); // leave this here to get latest propertybag.
00217     DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
00218     if ( !ds )
00219         return 0;
00220     const TypeInfo* ti = ds->getTypeInfo();
00221     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00222     assert( ctt );
00223     return ctt->updateFromAny( &value, ds );
00224 }
00225 
00226 CORBA::Boolean RTT_corba_CConfigurationInterface_i::hasAttribute (
00227     const char * name)
00228 {
00229     return mar->hasAttribute( name );
00230 }
00231 
00232 CORBA::Boolean RTT_corba_CConfigurationInterface_i::isAttributeAssignable (
00233     const char * name)
00234 {
00235     if (mar->getValue(name))
00236         return mar->getValue(name)->getDataSource()->isAssignable();
00237     return 0;
00238 }
00239 char * RTT_corba_CConfigurationInterface_i::getAttributeType (
00240     const char * name)
00241 {
00242     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00243     if (ds)
00244         return CORBA::string_dup( ds->getType().c_str() );
00245     return CORBA::string_dup( "na" );
00246 }
00247 
00248 char * RTT_corba_CConfigurationInterface_i::getAttributeTypeName (
00249     const char * name)
00250 {
00251     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00252     if (ds)
00253         return CORBA::string_dup( ds->getTypeName().c_str() );
00254     return CORBA::string_dup( "na" );
00255 }
00256 
00257 char * RTT_corba_CConfigurationInterface_i::attributeToString (
00258     const char * name)
00259 {
00260     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00261     if (ds) {
00262         std::string result = ds->toString();
00263         return CORBA::string_dup( result.c_str() );
00264     }
00265     return CORBA::string_dup( "na" );
00266 }
00267 
00268 CORBA::Boolean RTT_corba_CConfigurationInterface_i::attributeFromString (
00269     const char* name, const char* value
00270   )
00271 {
00272     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00273     if (!ds)
00274         return false;
00275     if ( ds->getTypeInfo()->fromString( value, ds ) ) {
00276         RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
00277         return false;
00278     }
00279     return true;
00280 }
00281 
00282 CORBA::Boolean RTT_corba_CConfigurationInterface_i::hasProperty (
00283     const char * name)
00284 {
00285     // converts result to bool.
00286     return bool( getPropertyDataSource(name) );
00287 }
00288 char * RTT_corba_CConfigurationInterface_i::getPropertyType (
00289     const char * name)
00290 {
00291     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00292     if (ds)
00293         return CORBA::string_dup( ds->getType().c_str() );
00294     return CORBA::string_dup( "na" );
00295 }
00296 
00297 char * RTT_corba_CConfigurationInterface_i::getPropertyTypeName (
00298     const char * name)
00299 {
00300     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00301     if (ds)
00302         return CORBA::string_dup( ds->getTypeName().c_str() );
00303     return CORBA::string_dup( "na" );
00304 }
00305 
00306 char * RTT_corba_CConfigurationInterface_i::propertyToString (
00307     const char * name)
00308 {
00309     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00310     if (ds) {
00311         std::string result = ds->toString();
00312         return CORBA::string_dup( result.c_str() );
00313     }
00314     return CORBA::string_dup( "na" );
00315 }
00316 
00317 CORBA::Boolean RTT_corba_CConfigurationInterface_i::propertyFromString (
00318     const char* name, const char* value
00319   )
00320 {
00321     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00322     if (!ds)
00323         return false;
00324     if ( ds->getTypeInfo()->fromString( value, ds ) ) {
00325         RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
00326         return false;
00327     }
00328     return true;
00329 }
00330 
00331 


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:51