ExpressionProxy.hpp
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 #ifndef ORO_CORBA_EXPRESSIONPROXY_HPP
00040 #define ORO_CORBA_EXPRESSIONPROXY_HPP
00041
00042 #include "../rtt-config.h"
00043 #include "corba.h"
00044 #ifdef CORBA_IS_TAO
00045 #include <tao/PortableServer/PortableServer.h>
00046 #else
00047 #include <omniORB4/poa.h>
00048 #endif
00049 #include "OperationsC.h"
00050 #include "../DataSource.hpp"
00051 #include "CORBAExpression.hpp"
00052 #include "../Logger.hpp"
00053 #include "../DataSources.hpp"
00054
00055 namespace RTT
00056 {namespace Corba
00057 {
00058
00062 class RTT_CORBA_API ExpressionProxy
00063 : public DataSourceBase
00064 {
00065 public:
00066 typedef boost::intrusive_ptr<ExpressionProxy> shared_ptr;
00067
00073 static ExpressionProxy::shared_ptr Create(::RTT::Corba::Expression_ptr expr);
00074
00080 static DataSourceBase::shared_ptr CreateDataSource(::RTT::Corba::Expression_ptr expr);
00081
00082
00089 template<class T>
00090 static DataSource<T>* NarrowDataSource(::RTT::Corba::Expression_ptr expr) {
00091
00092 CORBA::Any_var any = expr->value();
00093 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00094 ReferenceDataSource<T> rds( target );
00095 rds.ref();
00096 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any.in() ) ) {
00097 Logger::log() <<Logger::Debug<< "Found valid conversion from server "<< expr->getType()
00098 <<" to local "<< DataSource<T>::GetType()<<Logger::endl;
00099 return new CORBAExpression<T>( expr );
00100 }
00101 return 0;
00102 }
00103
00110 template<class T>
00111 static DataSource<T>* NarrowConstant( const CORBA::Any& any) {
00112
00113
00114 return CreateConstantHelper<T>::Create( any );
00115 }
00116
00123 template<class T>
00124 static AssignableDataSource<T>* NarrowAssignableDataSource( ::RTT::Corba::Expression_ptr expr) {
00125
00126 Corba::AssignableExpression_var ret = Corba::AssignableExpression::_narrow( expr );
00127 if ( !CORBA::is_nil(ret) ) {
00128 CORBA::Any_var any = ret->value();
00129 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00130 ReferenceDataSource<T> rds( target );
00131 rds.ref();
00132 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any.in() ) ) {
00133 Logger::log() <<Logger::Debug<< "Found valid assignment conversion from server "<< ret->getType()
00134 <<" to local "<< DataSource<T>::GetType()<<Logger::endl;
00135 return new CORBAAssignableExpression<T>( ret._retn() );
00136 }
00137 }
00138 return 0;
00139 }
00140
00146 template<class T>
00147 DataSource<T>* narrowDataSource() const {
00148 return NarrowDataSource<T>( mdata );
00149 }
00150
00155 DataSource<void>* narrowDataSource() const {
00156 return new CORBAExpression<void>( mdata.in() );
00157 }
00158
00164 template<class T>
00165 AssignableDataSource<T>* narrowAssignableDataSource() const {
00166 return NarrowAssignableDataSource<T>( mdata.in() );
00167 }
00168
00174
00175
00176 virtual int serverProtocol() const
00177 {
00178 return ORO_CORBA_PROTOCOL_ID;
00179 }
00180
00181 virtual bool evaluate() const {
00182 return mdata->evaluate();
00183 }
00184
00185 virtual DataSourceBase* clone() const {
00186 return new ExpressionProxy( mdata.in() );
00187 }
00188
00189 virtual DataSourceBase* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00190 alreadyCloned[this] = const_cast<ExpressionProxy*>(this);
00191 return alreadyCloned[this];
00192 }
00193
00194 virtual std::string getType() const { return std::string( mdata->getType() ); }
00195
00196 virtual const TypeInfo* getTypeInfo() const { return detail::DataSourceTypeInfo<detail::UnknownType>::getTypeInfo(); }
00197
00198 virtual std::string getTypeName() const { return std::string( mdata->getTypeName() ); }
00199
00200 virtual void* createBlob(int p) {
00201 if (p == ORO_CORBA_PROTOCOL_ID)
00202 return mdata->value();
00203 return 0;
00204 }
00205
00206 virtual void* getBlob(int p) {
00207 if (p == ORO_CORBA_PROTOCOL_ID)
00208 return mdata->get();
00209 return 0;
00210 }
00211
00212 virtual void* server(int p, void* arg) {
00213 if (p == ORO_CORBA_PROTOCOL_ID)
00214 return Corba::Expression::_duplicate(mdata.in());
00215 return 0;
00216 }
00217
00218 virtual void* server(int p, void* arg) const {
00219 if (p == ORO_CORBA_PROTOCOL_ID)
00220 return Corba::Expression::_duplicate(mdata.in());
00221 return 0;
00222 }
00223
00224 virtual void* method(int p, MethodC* , void* arg) {
00225 if (p == ORO_CORBA_PROTOCOL_ID)
00226 return Corba::Method::_narrow( mdata.in() );
00227 return 0;
00228 }
00229
00230 private:
00231 template<class T>
00232 struct CreateConstantHelper
00233 {
00234 static DataSource<T>* Create(const CORBA::Any& any) {
00235
00236 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00237 ReferenceDataSource<T> rds( target );
00238 rds.ref();
00239 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any ) ) {
00240 Logger::log() <<Logger::Debug<< "Found valid conversion from CORBA::Any "
00241 <<" to local constant "<< DataSource<T>::GetType()<<Logger::endl;
00242 return new ConstantDataSource<T>( target );
00243 }
00244 return 0;
00245 }
00246 };
00247
00248 template<class T>
00249 struct CreateConstantHelper<T&>
00250 {
00251 static DataSource<T&>* Create(const CORBA::Any& any) {
00252 return 0;
00253 }
00254 };
00255
00256 template<class T>
00257 struct CreateConstantHelper<const T&>
00258 {
00259 static DataSource<const T&>* Create(const CORBA::Any& any) {
00260
00261 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00262 ReferenceDataSource<T> rds( target );
00263 rds.ref();
00264 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any ) ) {
00265 Logger::log() <<Logger::Debug<< "Found valid conversion from CORBA::Any "
00266 <<" to local constant "<< DataSource<const T&>::GetType()<<Logger::endl;
00267 return new ConstantDataSource<const T&>( target );
00268 }
00269 return 0;
00270 }
00271 };
00272
00273 protected:
00274 typedef std::map<Corba::Expression_ptr, ExpressionProxy::shared_ptr> EMap;
00275 typedef std::map<Corba::Expression_ptr, DataSourceBase::shared_ptr> DMap;
00276
00277 static EMap proxies;
00278 static DMap dproxies;
00279
00284 ExpressionProxy( ::RTT::Corba::Expression_ptr t );
00285
00286 Corba::Expression_var mdata;
00287
00288 };
00289
00290 }}
00291
00292 #endif