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 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();
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();
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
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