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 #if 0
00044 //necessary to keep MSVC happy 
00045 //avoids redefinitions in winsock2.h
00046 #pragma push_macro("_WINSOCKAPI_")
00047 #ifndef _WINSOCKAPI_
00048 #define _WINSOCKAPI_
00049 #endif
00050 
00051 #include <windows.h>
00052 
00053 #pragma pop_macro("_WINSOCKAPI_")
00054 
00055 #endif
00056 
00057 #include "corba.h"
00058 #ifdef CORBA_IS_TAO
00059 #include <tao/corba.h>
00060 #include <tao/PortableServer/PortableServer.h>
00061 #else
00062 #include <omniORB4/CORBA.h>
00063 #include <omniORB4/poa.h>
00064 #endif
00065 
00066 #include "../DataObjectInterfaces.hpp"
00067 #include "../DataSources.hpp"
00068 #include "OperationsC.h"
00069 #include "CorbaLib.hpp"
00070 
00071 namespace RTT
00072 { namespace Corba {
00073 
00074 
00083     template<class T>
00084     class CorbaDataObjectProxy
00085         : public DataObjectInterface<T>
00086     {
00087         std::string name;
00088         AssignableExpression_var mec;
00089     public:
00097         CorbaDataObjectProxy(const std::string& _name, AssignableExpression_ptr ec )
00098             : name(_name), mec(AssignableExpression::_duplicate(ec) )
00099         {
00100         }
00101 
00105         ~CorbaDataObjectProxy() {
00106         }
00107 
00113         const std::string& getName() const { return name;}
00114 
00115         void setName( const std::string& _name )
00116         {
00117             name = _name;
00118         }
00119 
00123         typedef T DataType;
00124 
00130         void Get( DataType& pull ) const {
00131             Logger::In in("CorbaDataObjectProxy::Get");
00132             CORBA::Any_var v;
00133             v = mec->get();
00134             ReferenceDataSource<T> rds(pull);
00135             rds.ref();
00136             if ( rds.updateBlob(ORO_CORBA_PROTOCOL_ID, &v.in() ) == false) {
00137                 log(Error) << "Could not read remote value: wrong data type."<<endlog();
00138                 return;
00139             }
00140         }
00141 
00147         DataType Get() const { DataType p; this->Get(p); return p; }
00148 
00154         void Set( const DataType& push ) {
00155             // Trick: we must create a datasource to convert 'push' to
00156             // an Any. We do not convert it ourselves, since this would
00157             // invoke Get() first.
00158             ValueDataSource<T> vds(push);
00159             vds.ref();
00160             CORBA::Any_var toset = (CORBA::Any_ptr)vds.createBlob(ORO_CORBA_PROTOCOL_ID);
00161             mec->set( toset.in() );
00162         }
00163 
00164         CorbaDataObjectProxy<DataType>* clone() const {
00165             return new CorbaDataObjectProxy<DataType>(name, mec.in());
00166         }
00167 
00168         CorbaDataObjectProxy<DataType>* copy( std::map<const DataSourceBase*, DataSourceBase*>&  ) const {
00169             return const_cast<CorbaDataObjectProxy<DataType>*>(this);
00170         }
00171 
00172     };
00173 }}
00174 
00175 #endif
00176 
Generated on Thu Dec 23 13:22:36 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3