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 #ifndef ORO_CORBA_TEMPATE_PROTOCOL_HPP
00040 #define ORO_CORBA_TEMPATE_PROTOCOL_HPP
00041
00042 #include "CorbaTypeTransporter.hpp"
00043 #include "RemoteChannelElement.hpp"
00044 #include "../../types/Types.hpp"
00045 #include "../../InputPort.hpp"
00046 #include "../../OutputPort.hpp"
00047 #include "ServiceC.h"
00048 #include "DataFlowI.h"
00049 #include "../../internal/ConnID.hpp"
00050 #include "DataSourceProxy.hpp"
00051
00052 namespace RTT
00053 { namespace corba
00054 {
00058 template<class T>
00059 class CorbaTemplateProtocol
00060 : public CorbaTypeTransporter
00061 {
00062 public:
00066 typedef T UserType;
00070 typedef typename Property<T>::DataSourceType PropertyType;
00071
00072 CRemoteChannelElement_i* createChannelElement_i(DataFlowInterface* sender,PortableServer::POA_ptr poa, bool is_pull) const
00073 { return new RemoteChannelElement<T>(*this, sender, poa, is_pull); }
00074
00078 virtual CORBA::Any* createAny( base::DataSourceBase::shared_ptr source) const
00079 {
00080 typename internal::ReferenceDataSource<T>::shared_ptr d_ref = boost::dynamic_pointer_cast< internal::ReferenceDataSource<T> >( source );
00081 if ( d_ref )
00082 return AnyConversion<PropertyType>::createAny( d_ref->set());
00083
00084 typename internal::DataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::DataSource<T> >( source );
00085 if ( d )
00086 return AnyConversion<PropertyType>::createAny( d->get());
00087
00088 return 0;
00089 }
00090
00094 virtual bool updateAny( base::DataSourceBase::shared_ptr source, CORBA::Any& any) const
00095 {
00096 typename internal::ReferenceDataSource<T>::shared_ptr d_ref = boost::dynamic_pointer_cast< internal::ReferenceDataSource<T> >( source );
00097 if ( d_ref )
00098 return AnyConversion<PropertyType>::updateAny( d_ref->set(), any);
00099
00100 typename internal::DataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::DataSource<T> >( source );
00101 if ( d )
00102 return AnyConversion<PropertyType>::updateAny( d->get(), any);
00103
00104 return false;
00105 }
00106
00107 virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any* any) const
00108 {
00109 base::DataSourceBase::shared_ptr result = new internal::ValueDataSource<T>();
00110 if ( updateFromAny(any, result) )
00111 return result;
00112 return base::DataSourceBase::shared_ptr();
00113 }
00114
00118 virtual bool updateFromAny(const CORBA::Any* any, base::DataSourceBase::shared_ptr target) const
00119 {
00120 typename internal::ReferenceDataSource<T>::shared_ptr ad_ref = boost::dynamic_pointer_cast< internal::ReferenceDataSource<T> >( target );
00121 if ( ad_ref ) {
00122 if (AnyConversion<PropertyType>::update(*any, ad_ref->set() ) ) {
00123 return true;
00124 }
00125 return false;
00126 }
00127
00128 typename internal::AssignableDataSource<T>::shared_ptr ad = internal::AssignableDataSource<T>::narrow( target.get() );
00129 if ( ad ) {
00130 PropertyType value = PropertyType();
00131 if (AnyConversion<PropertyType>::update(*any, value ) ) {
00132 ad->set( value );
00133 return true;
00134 }
00135 return false;
00136 }
00137
00138 return false;
00139 }
00140
00141 virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string& vname) {
00142 return base::DataSourceBase::shared_ptr( new ValueDataSourceProxy<PropertyType>( serv, vname, true) );
00143 }
00144
00145 virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string& vname) {
00146 if ( serv->isAttributeAssignable( vname.c_str() ) ) {
00147 return base::DataSourceBase::shared_ptr( new ValueDataSourceProxy<PropertyType>( serv, vname, false) );
00148 }
00149 else {
00150 return base::DataSourceBase::shared_ptr( new DataSourceProxy<PropertyType>( serv, vname, false ) );
00151 }
00152 }
00153 };
00154 }
00155 }
00156
00157 #endif