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     return ctt->createAny( ds );
00170 }
00171 
00172 ::CORBA::Boolean RTT_corba_CConfigurationInterface_i::setAttribute (
00173     const char * name,
00174     const ::CORBA::Any & value)
00175 {
00176     if ( !mar || !mar->hasAttribute( string(name) ) )
00177         return 0;
00178     DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
00179     const TypeInfo* ti = ds->getTypeInfo();
00180     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00181     assert( ctt );
00182     return ctt->updateFromAny( &value, ds );
00183 }
00184 
00185 ::CORBA::Any * RTT_corba_CConfigurationInterface_i::getProperty (
00186     const char * name)
00187 {
00188     if (mar)
00189         mbag = mar->properties(); // leave this here to get latest propertybag.
00190     if ( mbag == 0 )
00191         return new CORBA::Any();
00192     DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
00193     if ( !ds ) {
00194         log(Error) <<"CConfigurationInterface: no such property: " << name << ". Returning empty CORBA::Any."<<endlog();
00195         return new CORBA::Any();
00196     }
00197     const TypeInfo* ti = ds->getTypeInfo();
00198     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00199     assert( ctt );
00200     return ctt->createAny( ds );
00201 }
00202 
00203 ::CORBA::Boolean RTT_corba_CConfigurationInterface_i::setProperty (
00204     const char * name,
00205     const ::CORBA::Any & value)
00206 {
00207     if (mar)
00208         mbag = mar->properties(); // leave this here to get latest propertybag.
00209     DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
00210     if ( !ds )
00211         return 0;
00212     const TypeInfo* ti = ds->getTypeInfo();
00213     CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
00214     assert( ctt );
00215     return ctt->updateFromAny( &value, ds );
00216 }
00217 
00218 CORBA::Boolean RTT_corba_CConfigurationInterface_i::hasAttribute (
00219     const char * name)
00220 {
00221     return mar->hasAttribute( name );
00222 }
00223 
00224 CORBA::Boolean RTT_corba_CConfigurationInterface_i::isAttributeAssignable (
00225     const char * name)
00226 {
00227     if (mar->getValue(name))
00228         return mar->getValue(name)->getDataSource()->isAssignable();
00229     return 0;
00230 }
00231 char * RTT_corba_CConfigurationInterface_i::getAttributeType (
00232     const char * name)
00233 {
00234     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00235     if (ds)
00236         return CORBA::string_dup( ds->getType().c_str() );
00237     return CORBA::string_dup( "na" );
00238 }
00239 
00240 char * RTT_corba_CConfigurationInterface_i::getAttributeTypeName (
00241     const char * name)
00242 {
00243     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00244     if (ds)
00245         return CORBA::string_dup( ds->getTypeName().c_str() );
00246     return CORBA::string_dup( "na" );
00247 }
00248 
00249 char * RTT_corba_CConfigurationInterface_i::attributeToString (
00250     const char * name)
00251 {
00252     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00253     if (ds) {
00254         std::string result = ds->toString();
00255         return CORBA::string_dup( result.c_str() );
00256     }
00257     return CORBA::string_dup( "na" );
00258 }
00259 
00260 CORBA::Boolean RTT_corba_CConfigurationInterface_i::attributeFromString (
00261     const char* name, const char* value
00262   )
00263 {
00264     DataSourceBase::shared_ptr ds = getAttributeDataSource( name );
00265     if (!ds)
00266         return false;
00267     if ( ds->getTypeInfo()->fromString( value, ds ) ) {
00268         RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
00269         return false;
00270     }
00271     return true;
00272 }
00273 
00274 CORBA::Boolean RTT_corba_CConfigurationInterface_i::hasProperty (
00275     const char * name)
00276 {
00277     // converts result to bool.
00278     return bool( getPropertyDataSource(name) );
00279 }
00280 char * RTT_corba_CConfigurationInterface_i::getPropertyType (
00281     const char * name)
00282 {
00283     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00284     if (ds)
00285         return CORBA::string_dup( ds->getType().c_str() );
00286     return CORBA::string_dup( "na" );
00287 }
00288 
00289 char * RTT_corba_CConfigurationInterface_i::getPropertyTypeName (
00290     const char * name)
00291 {
00292     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00293     if (ds)
00294         return CORBA::string_dup( ds->getTypeName().c_str() );
00295     return CORBA::string_dup( "na" );
00296 }
00297 
00298 char * RTT_corba_CConfigurationInterface_i::propertyToString (
00299     const char * name)
00300 {
00301     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00302     if (ds) {
00303         std::string result = ds->toString();
00304         return CORBA::string_dup( result.c_str() );
00305     }
00306     return CORBA::string_dup( "na" );
00307 }
00308 
00309 CORBA::Boolean RTT_corba_CConfigurationInterface_i::propertyFromString (
00310     const char* name, const char* value
00311   )
00312 {
00313     DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
00314     if (!ds)
00315         return false;
00316     if ( ds->getTypeInfo()->fromString( value, ds ) ) {
00317         RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
00318         return false;
00319     }
00320     return true;
00321 }
00322 
00323 


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:19