Orocos Real-Time Toolkit  2.9.0
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<long long> : public AnyConversionHelper<long long, CORBA::LongLong> {
81  typedef CORBA::LongLongSeq sequence;
82  };
83 
84  template<>
85  struct AnyConversion<unsigned long long> : public AnyConversionHelper<unsigned long long, CORBA::ULongLong> {
86  typedef CORBA::ULongLongSeq sequence;
87  };
88 
89  template<>
91  {
94 
95  static bool update(const CORBA::Any& any, CORBA::Any_ptr _value) {
96  //Logger::log() << Logger::Debug << "Updating type CORBA::Any_ptr with CORBA::Any." <<Logger::endl;
97  *_value = any;
98  return true;
99  }
100 
102  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
103  return new CORBA::Any(*t);
104  }
105 
106  static bool updateAny( const StdType& t, CORBA::Any& any ) {
107  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_ptr." <<Logger::endl;
108  any <<= CORBA::Any(*t);
109  return true;
110  }
111  };
112 
113  template<>
114  struct AnyConversion<CORBA::Any_var>
115  {
117  typedef CORBA::Any_var StdType;
118 
119  static bool update(const CORBA::Any& any, CORBA::Any_var _value) {
120  //Logger::log() << Logger::Debug << "Updating type CORBA::Any_var with CORBA::Any." <<Logger::endl;
121  *_value.out() = any;
122  return true;
123  }
124 
125  static CORBA::Any_ptr createAny( CORBA::Any_var t ) {
126  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
127  return new CORBA::Any( t.in() );
128  }
129 
130  static bool updateAny( const StdType& t, CORBA::Any& any ) {
131  //Logger::log() << Logger::Debug << "Duplicating CORBA::Any_var." <<Logger::endl;
132  any <<= CORBA::Any( t.in() );
133  return true;
134  }
135  };
136 
137  template<>
138  struct AnyConversion<bool>
139  {
140  typedef CORBA::Boolean CorbaType;
141  typedef bool StdType;
142 
143  typedef CORBA::BooleanSeq sequence;
144 
145  static CORBA::Any::from_boolean toAny( bool t ) {
146  //Logger::log() << Logger::Debug << "Converting type 'bool' to from_boolean." <<Logger::endl;
147  return CORBA::Any::from_boolean(t);
148  }
149  static CORBA::Any::to_boolean fromAny( CORBA::Boolean& t ) {
150  return CORBA::Any::to_boolean(t);
151  }
152  static StdType get(const CORBA::Boolean t) {
153  return t;
154  }
155 
156  static bool toStdType(StdType& tp, const CorbaType& cb) {
157  tp = get(cb);
158  return true;
159  }
160  static bool toCorbaType(CorbaType& cb, const StdType& tp) {
161  cb = tp;
162  return true;
163  }
164 
165  static bool update(const CORBA::Any& any, StdType& _value) {
166  CorbaType result;
167  if ( any >>= AnyConversion<bool>::fromAny( result ) ) {
168  _value = AnyConversion<bool>::get(result);
169  return true;
170  }
171  return false;
172  }
173 
174  static CORBA::Any_ptr createAny( bool t ) {
175  CORBA::Any_ptr ret = new CORBA::Any();
176  *ret <<= toAny( t );
177  return ret;
178  }
179 
180  static bool updateAny( bool t, CORBA::Any& any ) {
181  any <<= toAny( t );
182  return true;
183  }
184  };
185 
186  template<>
187  struct AnyConversion<char>
188  {
189  typedef CORBA::Char CorbaType;
190  typedef char StdType;
191 
192  typedef CORBA::CharSeq sequence;
193 
194  static CORBA::Any::from_char toAny( StdType t ) {
195  return CORBA::Any::from_char(t);
196  }
197 
198  static CORBA::Any::to_char fromAny( CorbaType& t ) {
199  return CORBA::Any::to_char(t);
200  }
201 
202  static StdType get(const CorbaType t) {
203  return t;
204  }
205 
206  static bool toStdType(StdType& tp, const CorbaType& cb) {
207  tp = get(cb);
208  return true;
209  }
210  static bool toCorbaType(CorbaType& cb, const StdType& tp) {
211  cb = tp;
212  return true;
213  }
214 
215  static bool update(const CORBA::Any& any, StdType& _value) {
216  CorbaType result;
217  if ( any >>= AnyConversion<StdType>::fromAny( result ) ) {
218  _value = AnyConversion<StdType>::get(result);
219  return true;
220  }
221  return false;
222  }
223 
224  static CORBA::Any_ptr createAny( char t ) {
225  CORBA::Any_ptr ret = new CORBA::Any();
226  *ret <<= toAny( t );
227  return ret;
228  }
229 
230  static bool updateAny( char t, CORBA::Any& any ) {
231  any <<= toAny( t );
232  return true;
233  }
234  };
235 
236  template<>
237  struct AnyConversion<std::string>
238  {
239  typedef CORBA::StringSeq sequence;
240 
241  typedef const char* CorbaType;
242  typedef std::string StdType;
243 
244  static CorbaType toAny(const std::string& orig) {
245  //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
246  return orig.c_str();
247  }
248 
249  static StdType get(const CorbaType t) {
250  return StdType( t );
251  }
252 
253  static bool toStdType(StdType& dest, const CorbaType src) {
254  dest = get(src);
255  return true;
256  }
257 
264  template<class T>
265  static bool toCorbaType(T dest, const StdType& src) {
266  dest = src.c_str();
267  return true;
268  }
269 
270  static bool update(const CORBA::Any& any, StdType& _value) {
271  CorbaType result;
272  //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
273  if ( any >>= result ) {
274  _value = result;
275  return true;
276  }
277  return false;
278  }
279 
280  static CORBA::Any_ptr createAny( const std::string& t ) {
281  CORBA::Any_ptr ret = new CORBA::Any();
282  *ret <<= toAny( t );
283  return ret;
284  }
285 
286  static bool updateAny( StdType const& t, CORBA::Any& any ) {
287  any <<= toAny( t );
288  return true;
289  }
290  };
291 
296  template<>
298  {
301  static CorbaType toAny(const StdType& orig) {
302  //Logger::log() << Logger::Debug << "Converting type 'string' to const char*." <<Logger::endl;
303  return toCORBA(orig);
304  }
305 
306  static StdType get(const CorbaType t) {
307  return toRTT( t );
308  }
309 
310  static bool update(const CORBA::Any& any, StdType& _value) {
311  CorbaType* result;
312  //Logger::log() << Logger::Debug << "Updating std::string with Any." <<Logger::endl;
313  if ( any >>= result ) {
314  _value = toRTT(*result);
315  return true;
316  }
317  return false;
318  }
319 
320  static CORBA::Any_ptr createAny( const StdType& t ) {
321  CORBA::Any_ptr ret = new CORBA::Any();
322  *ret <<= toAny( t );
323  return ret;
324  }
325 
326  static bool updateAny( StdType const& t, CORBA::Any& any ) {
327  any <<= toAny( t );
328  return true;
329  }
330  };
331 
332  template<>
334  {
335  typedef RTT::corba::CTaskContext_ptr CorbaType;
337 
338  static bool update(const CORBA::Any& any, StdType& _value) {
339  RTT::corba::CTaskContext_ptr task;
340  if ( any >>= task ) {
341  // read-only insertion, we duplicate the _ptr in Create:
342  _value = TaskContextProxy::Create( task );
343  return true;
344  }
345  return true;
346  }
347 
348  static CORBA::Any_ptr createAny( const StdType& t ) {
349  CORBA::Any_ptr ret = new CORBA::Any();
350  // copying insertion:
351  *ret <<= TaskContextServer::CreateServer(t,false,false);
352  return ret;
353  }
354 
355  static bool updateAny( const StdType& t, CORBA::Any& any ) {
356  if (t) {
357  // copying insertion:
358  any <<= TaskContextServer::CreateServer(t, false, false );
359  } else {
360  // leave any.
361  }
362  return true;
363  }
364  };
365 
366 #ifdef OS_RT_MALLOC
367  template<>
368  struct AnyConversion< rt_string >
369  {
370  typedef const char* CorbaType;
371  typedef rt_string StdType;
372 
373  static bool toCorbaType(CorbaType& cb,const StdType& orig) {
374  cb = orig.c_str();
375  return true;
376  }
377 
378  static CorbaType toAny(const StdType& orig) {
379  return orig.c_str();
380  }
381 
382  static bool toStdType(StdType& dest, const CorbaType orig) {
383  dest = StdType(orig);
384  return true;
385  }
386 
387  static bool update(const CORBA::Any& any, StdType& ret) {
388  CorbaType orig;
389  if ( any >>= orig )
390  {
391  ret = orig;
392  return true;
393  }
394  return false;
395  }
396 
397  static CORBA::Any_ptr createAny( const StdType& t ) {
398  CORBA::Any_ptr ret = new CORBA::Any();
399  *ret <<= toAny( t );
400  return ret;
401  }
402 
403  static bool updateAny( StdType const& t, CORBA::Any& any ) {
404  any <<= toAny( t );
405  return true;
406  }
407 
408  };
409 #endif
410  }
411 }
412 
413 #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)
Any * Any_ptr
Definition: corba.h:62
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:107
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.
Definition: corba.h:61
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:52
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)