OperationsI.h
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
00070 #include "../rtt-config.h"
00071 #include "corba.h"
00072 #include "../DataSource.hpp"
00073
00074 #ifndef INCLUDE_EXECUTIONI_H_
00075 #define INCLUDE_EXECUTIONI_H_
00076
00077 #include "OperationsC.h"
00078 #ifdef CORBA_IS_TAO
00079 #include "OperationsS.h"
00080 #endif
00081 #include "CorbaConversion.hpp"
00082 #include "AnyDataSource.hpp"
00083 #include "../DispatchInterface.hpp"
00084 #include "../Logger.hpp"
00085 #include "../MethodC.hpp"
00086 #include "../DataSources.hpp"
00087
00088 namespace RTT
00089 {
00090 class CommandC;
00091 }
00092
00093 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00094 #pragma once
00095 #endif
00096
00100 class Orocos_AnyExpression_i
00101 : public virtual POA_RTT::Corba::Expression,
00102 public virtual PortableServer::RefCountServantBase
00103 {
00104 protected:
00105 RTT::DataSourceBase::shared_ptr morig;
00106 CORBA::Any_var last_value;
00107 PortableServer::POA_var mpoa;
00108 public:
00109 typedef RTT::DataSourceBase::const_ptr SourceType;
00110 typedef CORBA::Any ResultType;
00111
00112 virtual void copy( RTT::DataSourceBase::shared_ptr new_ds ) {
00113 morig = new_ds;
00114 }
00115
00116
00117 Orocos_AnyExpression_i (RTT::DataSourceBase::shared_ptr orig, PortableServer::POA_ptr the_poa)
00118 : morig( orig ), last_value( (CORBA::Any_ptr)morig->createBlob(ORO_CORBA_PROTOCOL_ID) )
00119 , mpoa( PortableServer::POA::_duplicate(the_poa) )
00120 {}
00121
00122 PortableServer::POA_ptr _default_POA()
00123 {
00124 return PortableServer::POA::_duplicate(mpoa);
00125 }
00126
00127
00128 virtual ~Orocos_AnyExpression_i (void) {}
00129
00130 virtual
00131 CORBA::Any* value (
00132
00133 )
00134 ACE_THROW_SPEC ((
00135 CORBA::SystemException
00136 )) {
00137 return new CORBA::Any( last_value.in() );
00138 }
00139
00140 virtual
00141 CORBA::Boolean evaluate (
00142
00143 )
00144 ACE_THROW_SPEC ((
00145 CORBA::SystemException
00146 )) {
00147 last_value = (CORBA::Any_ptr)morig->getBlob(ORO_CORBA_PROTOCOL_ID);
00148 bool result = true;
00149
00150 RTT::AnyConversion<bool>::update( last_value.in(), result );
00151 return result;
00152 }
00153
00154 virtual
00155 CORBA::Any * get (
00156
00157 )
00158 ACE_THROW_SPEC ((
00159 CORBA::SystemException
00160 )) {
00161 return (CORBA::Any*)morig->getBlob(ORO_CORBA_PROTOCOL_ID);
00162 }
00163
00164 virtual
00165 char * getType (
00166
00167 )
00168 ACE_THROW_SPEC ((
00169 CORBA::SystemException
00170 )) {
00171 return CORBA::string_dup( morig->getType().c_str() );
00172 }
00173
00174 virtual
00175 char * toString (
00176
00177 )
00178 ACE_THROW_SPEC ((
00179 CORBA::SystemException
00180 )) {
00181 std::string result = morig->toString();
00182 return CORBA::string_dup( result.c_str() );
00183 }
00184
00185
00186 virtual
00187 char * getTypeName (
00188
00189 )
00190 ACE_THROW_SPEC ((
00191 CORBA::SystemException
00192 )) {
00193 return CORBA::string_dup( morig->getTypeName().c_str() );
00194 }
00195
00196 virtual void destroyExpression()
00197 ACE_THROW_SPEC ((
00198 CORBA::SystemException
00199 ))
00200 {
00201 }
00202
00203 };
00204
00205
00206 class Orocos_AnyAssignableExpression_i
00207 : public Orocos_AnyExpression_i,
00208 public virtual POA_RTT::Corba::AssignableExpression
00209 {
00210 RTT::DataSourceBase::shared_ptr mset;
00211 public:
00212
00213 virtual void copy( RTT::DataSourceBase::shared_ptr new_ds ) {
00214 mset = new_ds;
00215 morig = new_ds;
00216 }
00217
00218
00219 Orocos_AnyAssignableExpression_i (RTT::DataSourceBase::shared_ptr orig, PortableServer::POA_ptr the_poa)
00220 : Orocos_AnyExpression_i(orig, the_poa), mset( orig )
00221 {}
00222
00223
00224 virtual ~Orocos_AnyAssignableExpression_i (void) {}
00225
00226 virtual
00227 CORBA::Boolean set (
00228 const ::CORBA::Any & value
00229 )
00230 ACE_THROW_SPEC ((
00231 CORBA::SystemException
00232 )) {
00233 if ( mset->updateBlob(ORO_CORBA_PROTOCOL_ID, &value ) == false) {
00234 #if CORBA_IS_TAO
00235 CORBA::TypeCode_ptr tc = value.type();
00236 #else
00237 CORBA::TypeCode_var tc = value.type();
00238 #endif
00239 RTT::log(RTT::Error) << "Failed to update Assignable Expression of type "<< mset->getTypeName()
00240 << " with Any (Type id:" << tc->id() << " Type name:"<< tc->name() <<")"<<RTT::endlog();
00241 return false;
00242 }
00243 return true;
00244 }
00245
00246 virtual
00247 CORBA::Boolean fromString (
00248 const char* value
00249 )
00250 ACE_THROW_SPEC ((
00251 CORBA::SystemException
00252 )) {
00253
00254 if ( !mset->getTypeInfo()->fromString( value, mset ) ) {
00255 RTT::log(RTT::Error) << "Corba::AssignableExpression: Could not assign string to "<<mset->getType() <<"." <<RTT::endlog()
00256 <<" Tried to assign as "<< RTT::DataSource<ResultType>::GetType() << " to native type "<< RTT::DataSource<SourceType>::GetType()<< RTT::endlog();
00257 return false;
00258 }
00259 return true;
00260 }
00261
00262 };
00263
00264
00265 class Orocos_Action_i
00266 : public virtual POA_RTT::Corba::Action,
00267 public virtual PortableServer::RefCountServantBase
00268 {
00269 RTT::MethodC morig;
00270 RTT::CommandInterface* mcom;
00271 PortableServer::POA_var mpoa;
00272 public:
00273
00274 Orocos_Action_i ( RTT::MethodC* orig, RTT::CommandInterface* com, PortableServer::POA_ptr the_poa );
00275
00276 PortableServer::POA_ptr _default_POA()
00277 {
00278 return PortableServer::POA::_duplicate(mpoa);
00279 }
00280
00281
00282 virtual ~Orocos_Action_i (void);
00283
00284 virtual
00285 CORBA::Boolean execute (
00286
00287 )
00288 ACE_THROW_SPEC ((
00289 CORBA::SystemException
00290 ));
00291
00292 virtual
00293 CORBA::Boolean executeAny (
00294 const ::RTT::Corba::AnyArguments& args
00295 )
00296 ACE_THROW_SPEC ((
00297 CORBA::SystemException
00298 ,::RTT::Corba::WrongNumbArgException
00299 ,::RTT::Corba::WrongTypeArgException
00300 ));
00301
00302 virtual
00303 void reset (
00304
00305 )
00306 ACE_THROW_SPEC ((
00307 CORBA::SystemException
00308 ));
00309
00310 virtual void destroyAction()
00311 ACE_THROW_SPEC ((
00312 CORBA::SystemException
00313 ))
00314 {
00315 }
00316
00317 };
00318
00319 class Orocos_AnyMethod_i
00320 : public virtual Orocos_AnyExpression_i,
00321 public virtual POA_RTT::Corba::Method
00322 {
00323 protected:
00324 RTT::MethodC mmethodc;
00325
00326 public:
00327 virtual void copy( RTT::DataSourceBase::shared_ptr new_ds ) {
00328 morig = new_ds;
00329 }
00330
00331
00332 Orocos_AnyMethod_i (RTT::MethodC orig, RTT::DataSourceBase::shared_ptr datas, PortableServer::POA_ptr the_poa )
00333 : Orocos_AnyExpression_i( datas, the_poa ), mmethodc(orig)
00334 {}
00335
00336
00337 virtual ~Orocos_AnyMethod_i (void) {}
00338
00339 virtual
00340 CORBA::Boolean execute (
00341
00342 )
00343 ACE_THROW_SPEC ((
00344 CORBA::SystemException
00345 )) {
00346 return this->evaluate();
00347 }
00348
00349 CORBA::Boolean executeAny (
00350 const ::RTT::Corba::AnyArguments& args
00351 )
00352 ACE_THROW_SPEC ((
00353 CORBA::SystemException
00354 ,::RTT::Corba::WrongNumbArgException
00355 ,::RTT::Corba::WrongTypeArgException
00356 )) {
00357 RTT::MethodC mgen = mmethodc;
00358 try {
00359 for (size_t i =0; i != args.length(); ++i)
00360 mgen.arg( RTT::DataSourceBase::shared_ptr( new RTT::Corba::AnyDataSource( new CORBA::Any( args[i] ) )));
00361
00362 if ( !mgen.ready() )
00363 throw ::RTT::Corba::WrongNumbArgException( args.length()+1, args.length() );
00364 morig = mgen.getDataSource();
00365 return this->evaluate();
00366 } catch ( RTT::wrong_number_of_args_exception& wna ) {
00367 throw ::RTT::Corba::WrongNumbArgException( wna.wanted, wna.received );
00368 } catch ( RTT::wrong_types_of_args_exception& wta ) {
00369 throw ::RTT::Corba::WrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() );
00370 }
00371 return false;
00372 }
00373
00374 virtual
00375 void reset(
00376
00377 )
00378 ACE_THROW_SPEC ((
00379 CORBA::SystemException
00380 )) {
00381 this->morig->reset();
00382 }
00383
00384 virtual void destroyAction()
00385 ACE_THROW_SPEC ((
00386 CORBA::SystemException
00387 ))
00388 {
00389 }
00390
00391 };
00392
00393
00394 class Orocos_Command_i
00395 : public virtual POA_RTT::Corba::Command,
00396 public virtual PortableServer::RefCountServantBase
00397 {
00398 protected:
00399 RTT::CommandC* morig;
00400 RTT::CommandC* mcomm;
00401 PortableServer::POA_var mpoa;
00402 public:
00403
00410 Orocos_Command_i (RTT::CommandC& orig,RTT::CommandC& c, PortableServer::POA_ptr the_poa);
00411
00415 Orocos_Command_i (RTT::DispatchInterface::shared_ptr orig, PortableServer::POA_ptr the_poa);
00416
00417 PortableServer::POA_ptr _default_POA()
00418 {
00419 return PortableServer::POA::_duplicate(mpoa);
00420 }
00421
00422
00423 virtual ~Orocos_Command_i (void);
00424
00425 virtual
00426 CORBA::Boolean execute (
00427
00428 )
00429 ACE_THROW_SPEC ((
00430 CORBA::SystemException
00431 ));
00432
00433 virtual
00434 CORBA::Boolean executeAny (
00435 const ::RTT::Corba::AnyArguments& args
00436 )
00437 ACE_THROW_SPEC ((
00438 CORBA::SystemException
00439 ,::RTT::Corba::WrongNumbArgException
00440 ,::RTT::Corba::WrongTypeArgException
00441 ));
00442
00443 virtual
00444 CORBA::Boolean sent (
00445
00446 )
00447 ACE_THROW_SPEC ((
00448 CORBA::SystemException
00449 ));
00450
00451 virtual
00452 CORBA::Boolean accepted (
00453
00454 )
00455 ACE_THROW_SPEC ((
00456 CORBA::SystemException
00457 ));
00458
00459 virtual
00460 CORBA::Boolean executed (
00461
00462 )
00463 ACE_THROW_SPEC ((
00464 CORBA::SystemException
00465 ));
00466
00467 virtual
00468 CORBA::Boolean valid (
00469
00470 )
00471 ACE_THROW_SPEC ((
00472 CORBA::SystemException
00473 ));
00474
00475 virtual
00476 CORBA::Boolean done (
00477
00478 )
00479 ACE_THROW_SPEC ((
00480 CORBA::SystemException
00481 ));
00482
00483 virtual
00484 void reset (
00485
00486 )
00487 ACE_THROW_SPEC ((
00488 CORBA::SystemException
00489 ));
00490
00491 virtual void destroyCommand()
00492 ACE_THROW_SPEC ((
00493 CORBA::SystemException
00494 ));
00495 };
00496
00497 #endif
00498