Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
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 
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 
00099 RTT_corba_CConfigurationInterface_i::~RTT_corba_CConfigurationInterface_i (void)
00100 {
00101     
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(); 
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(); 
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     
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