DataSourceProxy.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 DataSourceProxy.hpp
3 
4  DataSourceProxy.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_CORBA_DATASOURCE_PROXY_HPP
40 #define ORO_CORBA_DATASOURCE_PROXY_HPP
41 
42 #include "../../internal/DataSource.hpp"
43 #include "../../Logger.hpp"
44 #include "../../base/ActionInterface.hpp"
45 #include "CorbaConversion.hpp"
46 #include "CorbaTypeTransporter.hpp"
47 #include "CorbaLib.hpp"
48 #include <cassert>
49 
50 namespace RTT
51 {
52  namespace corba
53  {
60  {
61  };
65  template<class T>
67  : public internal::DataSource<T>
68  {
69  corba::CService_var mserv;
70  const std::string mname;
74 
75  public:
85  DataSourceProxy( corba::CService_ptr s, const std::string& name, bool isproperty )
86  : mserv( corba::CService::_duplicate( s ) ), mname(name), misproperty(isproperty)
87  {
88  assert( !CORBA::is_nil(s) );
89  types::TypeTransporter* tp = this->getTypeInfo()->getProtocol(ORO_CORBA_PROTOCOL_ID);
90  ctp = dynamic_cast<corba::CorbaTypeTransporter*>(tp);
91  assert( ctp ); // only call this from CorbaTempateTypeInfo.
92 #if 0
93  if ( misproperty && ! mserv->hasProperty( name.c_str()))
94  throw NonExistingDataSource();
95  if ( !misproperty && ! mserv->hasAttribute( name.c_str()))
96  throw NonExistingDataSource();
97 #endif
98  }
99 
101  return last_value;
102  }
103 
105  return last_value;
106  }
107 
108  virtual typename internal::DataSource<T>::result_t get() const {
109  CORBA::Any_var res;
110  if ( misproperty ) {
111  res = mserv->getProperty( mname.c_str() );
112  } else {
113  res = mserv->getAttribute( mname.c_str() );
114  }
115  internal::ReferenceDataSource<T> rds(last_value);
116  rds.ref();
117  if ( ctp->updateFromAny(&res.in(),&rds ) == false)
118  Logger::log() <<Logger::Error << "Could not update DataSourceProxy from remote value!"<<Logger::endl;
119  return last_value;
120  }
121 
122  virtual internal::DataSource<T>* clone() const {
123  return new DataSourceProxy<T>( corba::CService::_duplicate( mserv.in() ), mname, misproperty );
124  }
125 
126  virtual internal::DataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const {
127  alreadyCloned[this] = const_cast<DataSourceProxy<T>*>(this);
128  return const_cast<DataSourceProxy<T>*>(this);
129  }
130 
131  virtual std::string getType() const {
132  // both should be equivalent, but we display the local type.
134  //return std::string( mserv->getType() );
135  }
136 
137  };
138 
142  template<class T>
145  {
147  corba::CService_var mserv;
148  const std::string mname;
152  //mutable typename internal::DataSource<T>::value_t last_value;
153 
154  public:
155  ValueDataSourceProxy( corba::CService_ptr serv, const std::string& name, bool isproperty)
156  : mserv( corba::CService::_duplicate(serv) ), mname(name), misproperty(isproperty)
157  {
158  storage = new internal::ValueDataSource<value_t>();
159  assert( serv );
160  types::TypeTransporter* tp = this->getTypeInfo()->getProtocol(ORO_CORBA_PROTOCOL_ID);
161  ctp = dynamic_cast<corba::CorbaTypeTransporter*>(tp);
162  assert(ctp);
163 #if 0
164  if ( misproperty && !mserv->hasProperty( name.c_str()) )
165  throw NonExistingDataSource();
166  if ( !misproperty && ( !mserv->hasAttribute( name.c_str()) || !mserv->isAttributeAssignable( name.c_str()) ))
167  throw NonExistingDataSource();
168  this->get(); // initialize such that value()/rvalue() return a sane value !
169 #endif
170  }
171 
173  return storage->rvalue();
174  }
175 
177  return storage->rvalue();
178  }
179 
180 
181  virtual typename internal::DataSource<T>::result_t get() const {
182  CORBA::Any_var res;
183  if ( misproperty ) {
184  res = mserv->getProperty( mname.c_str() );
185  } else {
186  res = mserv->getAttribute( mname.c_str() );
187  }
188  internal::ReferenceDataSource<T> rds( storage->set() );
189  rds.ref();
190  if ( ctp->updateFromAny(&res.in(), &rds ) == false)
191  Logger::log() <<Logger::Error << "Could not update ValueDataSourceProxy from remote value!"<<Logger::endl;
192  return storage->rvalue();
193  }
194 
195  virtual void set( typename internal::AssignableDataSource<T>::param_t t ) {
197  vds.ref();
198  CORBA::Any_var toset = ctp->createAny(&vds);
199  if ( misproperty ) {
200  mserv->setProperty( mname.c_str(), toset.in() );
201  } else {
202  mserv->setAttribute( mname.c_str(), toset.in() );
203  }
204  storage->set( t );
205  }
206 
208  this->get();
209  return storage->set();
210  }
211 
212  virtual void updated()
213  {
214  this->set( storage->value() );
215  }
216 
218  return new ValueDataSourceProxy<T>( corba::CService::_duplicate( mserv.in() ), mname, misproperty );
219  }
220 
221  virtual internal::AssignableDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const {
222  alreadyCloned[this] = const_cast<ValueDataSourceProxy<T>*>(this);
223  return const_cast<ValueDataSourceProxy<T>*>(this);
224  }
225  };
226 
227  }
228 }
229 
230 #endif
virtual internal::AssignableDataSource< T > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
internal::DataSource< T >::result_t value() const
virtual internal::DataSource< T > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
internal::DataSource< T >::value_t last_value
boost::call_traits< value_t >::reference reference_t
Definition: DataSource.hpp:193
virtual void set(param_t t)=0
virtual CORBA::Any_ptr createAny(base::DataSourceBase::shared_ptr source) const =0
internal::AssignableDataSource< value_t >::shared_ptr storage
ValueDataSourceProxy(corba::CService_ptr serv, const std::string &name, bool isproperty)
CorbaTypeTransporter * ctp
virtual internal::DataSource< T > * clone() const
DataSourceProxy(corba::CService_ptr s, const std::string &name, bool isproperty)
internal::AssignableDataSource< T >::const_reference_t rvalue() const
static std::string GetType()
virtual const_reference_t rvalue() const =0
static std::ostream & endl(std::ostream &__os)
Definition: Logger.cpp:383
internal::AssignableDataSource< T >::value_t value_t
virtual std::string getType() const
internal::AssignableDataSource< T >::const_reference_t rvalue() const
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
static Logger & log()
Definition: Logger.cpp:117
virtual result_t value() const =0
DataSource< T >::value_t value_t
Definition: DataSource.hpp:190
virtual bool updateFromAny(const CORBA::Any *blob, base::DataSourceBase::shared_ptr target) const =0
DataSource< T >::const_reference_t const_reference_t
Definition: DataSource.hpp:191
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
virtual internal::AssignableDataSource< T > * clone() const
boost::call_traits< value_t >::param_type param_t
Definition: DataSource.hpp:192
internal::DataSource< T >::result_t value() const


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32