Orocos Real-Time Toolkit  2.8.3
RTTCorbaConversion.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 tag: Peter Soetens Mon Jun 26 13:25:58 CEST 2006 CorbaConversion.hpp
3 
4 CorbaConversion.hpp - description
5 -------------------
6 begin : Mon June 26 2006
7 copyright : (C) 2006 Peter Soetens
8 email : peter.soetens@fmtc.be
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_RTT_CORBA_CONVERSION_HPP
40 #define ORO_RTT_CORBA_CONVERSION_HPP
41 
42 
43 #include "CorbaConversion.hpp"
44 #include "OrocosTypesC.h"
45 #include "TaskContextC.h"
46 #include "TaskContextServer.hpp"
47 #include "TaskContextProxy.hpp"
48 #include "CorbaConnPolicy.hpp"
49 #ifdef OS_RT_MALLOC
50 #include <rtt/rt_string.hpp>
51 #endif
52 
53 namespace RTT {
54  namespace corba {
55 
56  template<>
57  struct AnyConversion<double> : public AnyConversionHelper<double> {
58  typedef CORBA::DoubleSeq sequence;
59  };
60 
61  template<>
62  struct AnyConversion<float> : public AnyConversionHelper<float> {
63  typedef CORBA::FloatSeq sequence;
64  };
65 
66  template<>
67  struct AnyConversion<int> : public AnyConversionHelper<int, CORBA::Long> {
68  typedef CORBA::LongSeq sequence;
69  };
70 
71  //template<>
72  //struct AnyConversion<long> : public AnyConversionHelper<long> {};
73 
74  template<>
75  struct AnyConversion<unsigned int> : public AnyConversionHelper<unsigned int, CORBA::ULong> {
76  typedef CORBA::ULongSeq sequence;
77  };
78 
79  template<>
80  struct AnyConversion<CORBA::Any_ptr>
81  {
82  typedef CORBA::Any_ptr CorbaType;
83  typedef CORBA::Any_ptr StdType;
84 
85  static bool update(const CORBA::Any& any, CORBA::Any_ptr _value) {
86  //Logger::log() << Logger::Debug << "Updating type CORBA::Any_ptr with CORBA::Any." <<Logger::endl;
87  *_value = any;
88  return true;
89  }
90 
91  static CORBA::Any_ptr createAny( CORBA::Any_ptr t ) {
92  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
93  return new CORBA::Any(*t);
94  }
95 
96  static bool updateAny( const StdType& t, CORBA::Any& any ) {
97  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
98  any <<= CORBA::Any(*t);
99  return true;
100  }
101  };
102 
103  template<>
104  struct AnyConversion<CORBA::Any_var>
105  {
106  typedef CORBA::Any_ptr CorbaType;
107  typedef CORBA::Any_var StdType;
108 
109  static bool update(const CORBA::Any& any, CORBA::Any_var _value) {
110  //Logger::log() << Logger::Debug << "Updating type CORBA::Any_var with CORBA::Any." <<Logger::endl;
111  *_value.out() = any;
112  return true;
113  }
114 
115  static CORBA::Any_ptr createAny( CORBA::Any_var t ) {
116  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
117  return new CORBA::Any( t.in() );
118  }
119 
120  static bool updateAny( const StdType& t, CORBA::Any& any ) {
121  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
122  any <<= CORBA::Any( t.in() );
123  return true;
124  }
125  };
126 
127  template<>
128  struct AnyConversion<bool>
129  {
130  typedef CORBA::Boolean CorbaType;
131  typedef bool StdType;
132 
133  typedef CORBA::BooleanSeq sequence;
134 
135  static CORBA::Any::from_boolean toAny( bool t ) {
136  //Logger::log() << Logger::Debug << "Converting type 'bool' to from_boolean." <<Logger::endl;
137  return CORBA::Any::from_boolean(t);
138  }
139  static CORBA::Any::to_boolean fromAny( CORBA::Boolean& t ) {
140  return CORBA::Any::to_boolean(t);
141  }
142  static StdType get(const CORBA::Boolean t) {
143  return t;
144  }
145 
146  static bool toStdType(StdType& tp, const CorbaType& cb) {
147  tp = get(cb);
148  return true;
149  }
150  static bool toCorbaType(CorbaType& cb, const StdType& tp) {
151  cb = tp;
152  return true;
153  }
154 
155  static bool update(const CORBA::Any& any, StdType& _value) {
156  CorbaType result;
157  if ( any >>= AnyConversion<bool>::fromAny( result ) ) {
158  _value = AnyConversion<bool>::get(result);
159  return true;
160  }
161  return false;
162  }
163 
164  static CORBA::Any_ptr createAny( bool t ) {
165  CORBA::Any_ptr ret = new CORBA::Any();
166  *ret <<= toAny( t );
167  return ret;
168  }
169 
170  static bool updateAny( bool t, CORBA::Any& any ) {
171  any <<= toAny( t );
172  return true;
173  }
174  };
175 
176  template<>
177  struct AnyConversion<char>
178  {
179  typedef CORBA::Char CorbaType;
180  typedef char StdType;
181 
182  typedef CORBA::CharSeq sequence;
183 
184  static CORBA::Any::from_char toAny( StdType t ) {
185  return CORBA::Any::from_char(t);
186  }
187 
188  static CORBA::Any::to_char fromAny( CorbaType& t ) {
189  return CORBA::Any::to_char(t);
190  }
191 
192  static StdType get(const CorbaType t) {
193  return t;
194  }
195 
196  static bool toStdType(StdType& tp, const CorbaType& cb) {
197  tp = get(cb);
198  return true;
199  }
200  static bool toCorbaType(CorbaType& cb, const StdType& tp) {
201  cb = tp;
202  return true;
203  }
204 
205  static bool update(const CORBA::Any& any, StdType& _value) {
206  CorbaType result;
207  if ( any >>= AnyConversion<StdType>::fromAny( result ) ) {
208  _value = AnyConversion<StdType>::get(result);
209  return true;
210  }
211  return false;
212  }
213 
214  static CORBA::Any_ptr createAny( char t ) {
215  CORBA::Any_ptr ret = new CORBA::Any();
216  *ret <<= toAny( t );
217  return ret;
218  }
219 
220  static bool updateAny( char t, CORBA::Any& any ) {
221  any <<= toAny( t );
222  return true;
223  }
224  };
225 
226  template<>
227  struct AnyConversion<std::string>
228  {
229  typedef CORBA::StringSeq sequence;
230 
231  typedef const char* CorbaType;
232  typedef std::string StdType;
233 
234  static CorbaType toAny(const std::string& orig) {
235  //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
236  return orig.c_str();
237  }
238 
239  static StdType get(const CorbaType t) {
240  return StdType( t );
241  }
242 
243  static bool toStdType(StdType& dest, const CorbaType src) {
244  dest = get(src);
245  return true;
246  }
247 
254  template<class T>
255  static bool toCorbaType(T dest, const StdType& src) {
256  dest = src.c_str();
257  return true;
258  }
259 
260  static bool update(const CORBA::Any& any, StdType& _value) {
261  CorbaType result;
262  //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
263  if ( any >>= result ) {
264  _value = result;
265  return true;
266  }
267  return false;
268  }
269 
270  static CORBA::Any_ptr createAny( const std::string& t ) {
271  CORBA::Any_ptr ret = new CORBA::Any();
272  *ret <<= toAny( t );
273  return ret;
274  }
275 
276  static bool updateAny( StdType const& t, CORBA::Any& any ) {
277  any <<= toAny( t );
278  return true;
279  }
280  };
281 
286  template<>
288  {
291  static CorbaType toAny(const StdType& orig) {
292  //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
293  return toCORBA(orig);
294  }
295 
296  static StdType get(const CorbaType t) {
297  return toRTT( t );
298  }
299 
300  static bool update(const CORBA::Any& any, StdType& _value) {
301  CorbaType* result;
302  //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
303  if ( any >>= result ) {
304  _value = toRTT(*result);
305  return true;
306  }
307  return false;
308  }
309 
310  static CORBA::Any_ptr createAny( const StdType& t ) {
311  CORBA::Any_ptr ret = new CORBA::Any();
312  *ret <<= toAny( t );
313  return ret;
314  }
315 
316  static bool updateAny( StdType const& t, CORBA::Any& any ) {
317  any <<= toAny( t );
318  return true;
319  }
320  };
321 
322  template<>
324  {
325  typedef RTT::corba::CTaskContext_ptr CorbaType;
327 
328  static bool update(const CORBA::Any& any, StdType& _value) {
329  RTT::corba::CTaskContext_ptr task;
330  if ( any >>= task ) {
331  // read-only insertion, we duplicate the _ptr in Create:
332  _value = TaskContextProxy::Create( task );
333  return true;
334  }
335  return true;
336  }
337 
338  static CORBA::Any_ptr createAny( const StdType& t ) {
339  CORBA::Any_ptr ret = new CORBA::Any();
340  // copying insertion:
341  *ret <<= TaskContextServer::CreateServer(t,false,false);
342  return ret;
343  }
344 
345  static bool updateAny( const StdType& t, CORBA::Any& any ) {
346  if (t) {
347  // copying insertion:
348  any <<= TaskContextServer::CreateServer(t, false, false );
349  } else {
350  // leave any.
351  }
352  return true;
353  }
354  };
355 
356 #ifdef OS_RT_MALLOC
357  template<>
358  struct AnyConversion< rt_string >
359  {
360  typedef const char* CorbaType;
361  typedef rt_string StdType;
362 
363  static bool toCorbaType(CorbaType& cb,const StdType& orig) {
364  cb = orig.c_str();
365  return true;
366  }
367 
368  static CorbaType toAny(const StdType& orig) {
369  return orig.c_str();
370  }
371 
372  static bool toStdType(StdType& dest, const CorbaType orig) {
373  dest = StdType(orig);
374  return true;
375  }
376 
377  static bool update(const CORBA::Any& any, StdType& ret) {
378  CorbaType orig;
379  if ( any >>= orig )
380  {
381  ret = orig;
382  return true;
383  }
384  return false;
385  }
386 
387  static CORBA::Any_ptr createAny( const StdType& t ) {
388  CORBA::Any_ptr ret = new CORBA::Any();
389  *ret <<= toAny( t );
390  return ret;
391  }
392 
393  static bool updateAny( StdType const& t, CORBA::Any& any ) {
394  any <<= toAny( t );
395  return true;
396  }
397 
398  };
399 #endif
400  }
401 }
402 
403 #endif
CORBA::Any CorbaType
corba type
static bool updateAny(StdType tp, CORBA::Any &any)
Updates an CORBA::Any object from of a C++/IDL type.
static CORBA::Any::to_char fromAny(CorbaType &t)
This class converts a given application-specific type to a CORBA::Any object and vice versa...
static bool toStdType(StdType &tp, const CorbaType &cb)
static CORBA::Any::from_boolean toAny(bool t)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool updateAny(char t, CORBA::Any &any)
static bool update(const CORBA::Any &any, CORBA::Any_var _value)
static bool update(const CORBA::Any &any, StdType tp)
Updates tp with the contents of any.
static bool update(const CORBA::Any &any, StdType &_value)
static CORBA::Any_ptr createAny(const StdType &t)
static bool update(const CORBA::Any &any, StdType &_value)
STL namespace.
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static CORBA::Any_ptr createAny(CORBA::Any_var t)
static CTaskContext_ptr CreateServer(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
Factory method: create a CORBA server for an existing TaskContext.
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:92
static bool updateAny(const StdType &t, CORBA::Any &any)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
Updates cb with the contents of tp.
RTT::ConnPolicy toRTT(RTT::corba::CConnPolicy const &corba_policy)
Converts a Corba CConnPolicy object to a RTT ConPolicy object.
static CORBA::Any_ptr createAny(CORBA::Any_ptr t)
static bool updateAny(const StdType &t, CORBA::Any &any)
static bool toStdType(StdType &dest, const CorbaType src)
Used for the conversion of types that are binary compatible between CORBA type and std C++ type...
static bool updateAny(StdType const &t, CORBA::Any &any)
static CORBA::Any::from_char toAny(StdType t)
static bool update(const CORBA::Any &any, StdType &_value)
static CorbaType toAny(const std::string &orig)
static bool toStdType(StdType &tp, const CorbaType &cb)
Updates tp with the contents of cb.
static CORBA::Any_ptr createAny(const std::string &t)
static bool update(const CORBA::Any &any, CORBA::Any_ptr _value)
RTT::corba::CConnPolicy toCORBA(RTT::ConnPolicy const &policy)
Converts a RTT ConnPolicy object to a Corba CConPolicy object.
static CORBA::Any_ptr createAny(const StdType &t)
static CORBA::Any_ptr createAny(char t)
static CorbaType toAny(const StdType &orig)
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
static bool toCorbaType(T dest, const StdType &src)
Use for the conversion from a stl container to a sequence<string>
static bool update(const CORBA::Any &any, StdType &_value)
static CORBA::Any_ptr createAny(StdType tp)
Creates an CORBA::Any object out of a C++/IDL type.
static bool updateAny(const StdType &t, CORBA::Any &any)
static bool update(const CORBA::Any &any, StdType &_value)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
static bool updateAny(bool t, CORBA::Any &any)
static bool updateAny(StdType const &t, CORBA::Any &any)
static TaskContextProxy * Create(std::string name, bool is_ior=false)
Factory method: create a CORBA Proxy for an existing TaskContextServer.
static CORBA::Any::to_boolean fromAny(CORBA::Boolean &t)
static CORBA::Any_ptr createAny(bool t)