CorbaTemplateProtocol.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: FMTC  Tue Mar 11 21:49:24 CET 2008  CorbaTemplateProtocol.hpp
00003 
00004                         CorbaTemplateProtocol.hpp -  description
00005                            -------------------
00006     begin                : Tue March 11 2008
00007     copyright            : (C) 2008 FMTC
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:34