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 "../DataSource.hpp"
00043 #include "OperationsC.h"
00044 #include "CORBAExpression.hpp"
00045 #include "../Logger.hpp"
00046 #include "../DataSources.hpp"
00047
00048 namespace RTT
00049 {namespace Corba
00050 {
00051
00055 class ExpressionProxy
00056 : public DataSourceBase
00057 {
00058 public:
00059 typedef boost::intrusive_ptr<ExpressionProxy> shared_ptr;
00060
00066 static ExpressionProxy::shared_ptr Create(::RTT::Corba::Expression_ptr expr);
00067
00073 static DataSourceBase::shared_ptr CreateDataSource(::RTT::Corba::Expression_ptr expr);
00074
00075
00082 template<class T>
00083 static DataSource<T>* NarrowDataSource(::RTT::Corba::Expression_ptr expr) {
00084
00085 CORBA::Any_var any = expr->value();
00086 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00087 ReferenceDataSource<T> rds( target );
00088 rds.ref();
00089 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any.in() ) ) {
00090 Logger::log() <<Logger::Debug<< "Found valid conversion from server "<< expr->getType()
00091 <<" to local "<< DataSource<T>::GetType()<<Logger::endl;
00092 return new CORBAExpression<T>( expr );
00093 }
00094 return 0;
00095 }
00096
00103 template<class T>
00104 static DataSource<T>* NarrowConstant( const CORBA::Any& any) {
00105
00106
00107 return CreateConstantHelper<T>::Create( any );
00108 }
00109
00116 template<class T>
00117 static AssignableDataSource<T>* NarrowAssignableDataSource( ::RTT::Corba::Expression_ptr expr) {
00118
00119 Corba::AssignableExpression_var ret = Corba::AssignableExpression::_narrow( expr );
00120 if ( !CORBA::is_nil(ret) ) {
00121 CORBA::Any_var any = ret->value();
00122 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00123 ReferenceDataSource<T> rds( target );
00124 rds.ref();
00125 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any.in() ) ) {
00126 Logger::log() <<Logger::Debug<< "Found valid assignment conversion from server "<< ret->getType()
00127 <<" to local "<< DataSource<T>::GetType()<<Logger::endl;
00128 return new CORBAAssignableExpression<T>( ret._retn() );
00129 }
00130 }
00131 return 0;
00132 }
00133
00139 template<class T>
00140 DataSource<T>* narrowDataSource() const {
00141 return NarrowDataSource<T>( mdata );
00142 }
00143
00148 DataSource<void>* narrowDataSource() const {
00149 return new CORBAExpression<void>( mdata.in() );
00150 }
00151
00157 template<class T>
00158 AssignableDataSource<T>* narrowAssignableDataSource() const {
00159 return NarrowAssignableDataSource<T>( mdata.in() );
00160 }
00161
00167
00168
00169 virtual int serverProtocol() const
00170 {
00171 return ORO_CORBA_PROTOCOL_ID;
00172 }
00173
00174 virtual bool evaluate() const {
00175 return mdata->evaluate();
00176 }
00177
00178 virtual DataSourceBase* clone() const {
00179 return new ExpressionProxy( mdata.in() );
00180 }
00181
00182 virtual DataSourceBase* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00183 alreadyCloned[this] = const_cast<ExpressionProxy*>(this);
00184 return alreadyCloned[this];
00185 }
00186
00187 virtual std::string getType() const { return std::string( mdata->getType() ); }
00188
00189 virtual const TypeInfo* getTypeInfo() const { return detail::DataSourceTypeInfo<detail::UnknownType>::getTypeInfo(); }
00190
00191 virtual std::string getTypeName() const { return std::string( mdata->getTypeName() ); }
00192
00193 virtual void* createBlob(int p) {
00194 if (p == ORO_CORBA_PROTOCOL_ID)
00195 return mdata->value();
00196 return 0;
00197 }
00198
00199 virtual void* getBlob(int p) {
00200 if (p == ORO_CORBA_PROTOCOL_ID)
00201 return mdata->get();
00202 return 0;
00203 }
00204
00205 virtual void* server(int p, void* arg) {
00206 if (p == ORO_CORBA_PROTOCOL_ID)
00207 return Corba::Expression::_duplicate(mdata.in());
00208 return 0;
00209 }
00210
00211 virtual void* server(int p, void* arg) const {
00212 if (p == ORO_CORBA_PROTOCOL_ID)
00213 return Corba::Expression::_duplicate(mdata.in());
00214 return 0;
00215 }
00216
00217 virtual void* method(int p, MethodC* , void* arg) {
00218 if (p == ORO_CORBA_PROTOCOL_ID)
00219 return Corba::Method::_narrow( mdata.in() );
00220 return 0;
00221 }
00222
00223 private:
00224 template<class T>
00225 struct CreateConstantHelper
00226 {
00227 static DataSource<T>* Create(const CORBA::Any& any) {
00228
00229 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00230 ReferenceDataSource<T> rds( target );
00231 rds.ref();
00232 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any ) ) {
00233 Logger::log() <<Logger::Debug<< "Found valid conversion from CORBA::Any "
00234 <<" to local constant "<< DataSource<T>::GetType()<<Logger::endl;
00235 return new ConstantDataSource<T>( target );
00236 }
00237 return 0;
00238 }
00239 };
00240
00241 template<class T>
00242 struct CreateConstantHelper<T&>
00243 {
00244 static DataSource<T&>* Create(const CORBA::Any& any) {
00245 return 0;
00246 }
00247 };
00248
00249 template<class T>
00250 struct CreateConstantHelper<const T&>
00251 {
00252 static DataSource<const T&>* Create(const CORBA::Any& any) {
00253
00254 typename DataSource<T>::value_t target = typename DataSource<T>::value_t();
00255 ReferenceDataSource<T> rds( target );
00256 rds.ref();
00257 if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &any ) ) {
00258 Logger::log() <<Logger::Debug<< "Found valid conversion from CORBA::Any "
00259 <<" to local constant "<< DataSource<const T&>::GetType()<<Logger::endl;
00260 return new ConstantDataSource<const T&>( target );
00261 }
00262 return 0;
00263 }
00264 };
00265
00266 protected:
00267 typedef std::map<Corba::Expression_ptr, ExpressionProxy::shared_ptr> EMap;
00268 typedef std::map<Corba::Expression_ptr, DataSourceBase::shared_ptr> DMap;
00269
00270 static EMap proxies;
00271 static DMap dproxies;
00272
00277 ExpressionProxy( ::RTT::Corba::Expression_ptr t );
00278
00279 Corba::Expression_var mdata;
00280
00281 };
00282
00283 }}
00284
00285 #endif