CorbaDataObjectProxy.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:19 CET 2006  CorbaDataObjectProxy.hpp
00003 
00004                         CorbaDataObjectProxy.hpp -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 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 
00040 #ifndef ORO_CORBA_DATAOBJECTPROXY_HPP
00041 #define ORO_CORBA_DATAOBJECTPROXY_HPP
00042 
00043 
00044 #include "../DataObjectInterfaces.hpp"
00045 #include "../DataSources.hpp"
00046 #include "OperationsC.h"
00047 #include "CorbaLib.hpp"
00048 #include "corba.h"
00049 
00050 namespace RTT
00051 { namespace Corba {
00052 
00053 
00062     template<class T>
00063     class CorbaDataObjectProxy
00064         : public DataObjectInterface<T>
00065     {
00066         std::string name;
00067         AssignableExpression_var mec;
00068     public:
00076         CorbaDataObjectProxy(const std::string& _name, AssignableExpression_ptr ec )
00077             : name(_name), mec(AssignableExpression::_duplicate(ec) )
00078         {
00079         }
00080 
00084         ~CorbaDataObjectProxy() {
00085         }
00086 
00092         const std::string& getName() const { return name;}
00093 
00094         void setName( const std::string& _name )
00095         {
00096             name = _name;
00097         }
00098 
00102         typedef T DataType;
00103 
00109         void Get( DataType& pull ) const {
00110             Logger::In in("CorbaDataObjectProxy::Get");
00111             CORBA::Any_var v;
00112             v = mec->get();
00113             ReferenceDataSource<T> rds(pull);
00114             rds.ref();
00115             if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &v.in() ) == false) {
00116                 log(Error) << "Could not read remote value: wrong data type."<<endlog();
00117                 return;
00118             }
00119         }
00120 
00126         DataType Get() const { DataType p; this->Get(p); return p; }
00127 
00133         void Set( const DataType& push ) {
00134             // Trick: we must create a datasource to convert 'push' to
00135             // an Any. We do not convert it ourselves, since this would
00136             // invoke Get() first.
00137             ValueDataSource<T> vds(push);
00138             vds.ref();
00139             CORBA::Any_var toset = (CORBA::Any_ptr)vds.createBlob(ORO_CORBA_PROTOCOL_ID);
00140             mec->set( toset.in() );
00141         }
00142 
00143         CorbaDataObjectProxy<DataType>* clone() const {
00144             return new CorbaDataObjectProxy<DataType>(name, mec.in());
00145         }
00146 
00147         CorbaDataObjectProxy<DataType>* copy( std::map<const DataSourceBase*, DataSourceBase*>&  ) const {
00148             return const_cast<CorbaDataObjectProxy<DataType>*>(this);
00149         }
00150 
00151     };
00152 }}
00153 
00154 #endif
00155 

Generated on Tue Aug 25 14:17:21 2009 for Orocos Real-Time Toolkit by  doxygen 1.5.8