corba/template.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- python -*-
3 #
4 # @file template.py
5 # @brief doil servant class template
6 # @date $Date$
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2008
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id$
17 #
18 
19 
20 # doil type conversion header
21 typeconv_h = """\
22 // -*- C++ -*-
23 /*!
24  * @file TypeConversion.h
25  * @brief doil-CORBA type conversion
26  * @date $Date$
27  * @author This file was automatically generated from [idl_fname]
28  * by omniidl/doil backend
29  *
30  * $Id$
31  */
32 
33 #ifndef [typeconv_include_guard]
34 #define [typeconv_include_guard]
35 
36 //
37 [for inc in include_h]
38 #include <[inc]>
39 [endfor]
40 
41 #include <[types_h_path]>
42 
43 [for decl in declarations]
44 [decl]
45 [endfor]
46 
47 #endif // [typeconv_include_guard]
48 
49 """
50 typeconv_cpp = """\
51 // -*- C++ -*-
52 /*!
53  * @file TypeConversion.h
54  * @brief doil-CORBA type conversion
55  * @date $Date$
56  * @author This file was automatically generated from [idl_fname]
57  * by omniidl/doil backend
58  *
59  * $Id$
60  */
61 
62 #include <doil/corba/BasicTypeConversion.h>
63 #include <[typeconv_h_path]>
64 #include <doil/corba/SeqTypeConversion.h>
65 #include <doil/corba/CORBAManager.h>
66 
67 [for node in tree]
68 [if node.corba.decl_type is "interface"]
69 #include <[node.local.iface_h_path]>
70 [endif]
71 [endfor]
72 
73 [for impl in implementations]
74 [impl]
75 [endfor]
76 
77 // end of TypeConversion
78 
79 """
80 
81 
82 #------------------------------------------------------------
83 # object conversion declaration
84 object_conv_h = """\
85 // corba object -> local object
86 bool
87 corba_to_local([corba.name_fq]_ptr _from,
88  [local.iface_name_fq]* _to);
89 
90 // local object -> corba object
91 bool
92 local_to_corba([local.iface_name_fq]* _from,
93  [corba.name_fq]_ptr _to);
94 
95 """
96 
97 #------------------------------------------------------------
98 # object conversion implementation
99 object_conv_cpp = """\
100 // corba object -> local object
101 bool
102 corba_to_local([corba.name_fq]_ptr _from,
103  [local.iface_name_fq]* _to)
104 {
105  doil::LocalBase* lobj;
106  lobj = doil::CORBA::CORBAManager::instance().toLocal((::CORBA::Object_ptr&)_from);
107  if (lobj == NULL) return false;
108  _to = dynamic_cast< [local.iface_name_fq]* >(lobj);
109  if (_to == NULL) return false;
110  return true;
111 }
112 
113 // local object -> corba object
114 bool
115 local_to_corba([local.iface_name_fq]* _from,
116  [corba.name_fq]_ptr _to)
117 {
118  CORBA::Object_ptr obj;
119  obj = doil::CORBA::CORBAManager::instance().toReference((doil::LocalBase*)_from);
120  _to = [corba.name_fq]::_narrow(obj);
121  if (CORBA::is_nil(_to)) return false;
122  return true;
123 }
124 
125 """
126 
127 #------------------------------------------------------------
128 # object declaration
129 struct_conv_h = """\
130 // struct corba -> local
131 bool
132 corba_to_local(const [corba.name_fq]& _from,
133  [local.name_fq]& _to);
134 
135 // struct local -> corba
136 bool
137 local_to_corba(const [local.name_fq]& _from,
138  [corba.name_fq]& _to);
139 
140 """
141 #------------------------------------------------------------
142 # struct conversion declaration
143 struct_conv_cpp = """\
144 // struct corba -> local
145 bool
146 corba_to_local(const [corba.name_fq]& _from,
147  [local.name_fq]& _to)
148 {
149 [for mem in members]
150 [if mem.corba.tk is "tk_objref"]
151  if (!corba_to_local(([mem.corba.base_type]&)_from.[mem.corba.member_name],
152  _to.[mem.local.member_name]))
153 [else]
154  if (!corba_to_local(_from.[mem.corba.member_name],
155  _to.[mem.local.member_name]))
156 [endif]
157  return false;
158 [endfor]
159  return true;
160 }
161 
162 // struct local -> corba
163 bool
164 local_to_corba(const [local.name_fq]& _from,
165  [corba.name_fq]& _to)
166 {
167 [for mem in members]
168 [if mem.corba.tk is "tk_objref"]
169  if (!local_to_corba(_from.[mem.local.member_name],
170  ([mem.corba.base_type]&)_to.[mem.corba.member_name]))
171 [else]
172  if (!local_to_corba(_from.[mem.local.member_name],
173  _to.[mem.corba.member_name]))
174 [endif]
175  return false;
176 [endfor]
177  return true;
178 }
179 
180 """
181 
182 #------------------------------------------------------------
183 # union conversion declaration
184 union_conv_h = """\
185 // union corba -> local
186 bool
187 corba_to_local(const [local.name_fq]& _from,
188  [corba.name_fq]& _to);
189 
190 // union local -> corba
191 bool
192 corba_to_local(const [corba.name_fq]& _from,
193  [local.name_fq]& _to);
194 
195 """
196 
197 #------------------------------------------------------------
198 # union conversion implementation
199 union_conv_cpp = """\
200 // union corba -> local
201 bool
202 corba_to_local(const [corba.name_fq]& _from,
203  [local.name_fq]& _to)
204 {
205  switch (_from._d())
206  {
207 [for cas in cases]
208  case [cas.corba.discriminator_fq] :
209  {
210  [cas.local.case_type] l[cas.local.case_member];
211  [cas.corba.case_type] c[cas.corba.case_member];
212  c[cas.corba.case_member] = _from.[cas.corba.case_member]();
213  corba_to_local(c[cas.corba.case_member], l[cas.local.case_member]);
214  _to.set_[cas.local.case_member](l[cas.local.case_member]);
215  break;
216  }
217 [endfor]
218  default:
219  return false;
220  }
221  return true;
222 }
223 
224 // union local -> corba
225 bool
226 local_to_corba(const [local.name_fq]& _from,
227  [corba.name_fq]& _to)
228 {
229  switch (_from.get_type())
230  {
231 [for cas in cases]
232  case [cas.local.discriminator_fq] :
233  {
234  [cas.corba.case_type] c[cas.corba.case_member];
235  [cas.local.case_type] l[cas.local.case_member];
236  l[cas.local.case_member] = _from.get_[cas.corba.case_member]();
237  local_to_corba(l[cas.local.case_member], c[cas.corba.case_member]);
238  _to.[cas.local.case_member](c[cas.corba.case_member]);
239  break;
240  }
241 [endfor]
242  default:
243  return false;
244  }
245  return true;
246 }
247 
248 """
249 
250 #------------------------------------------------------------
251 # enum conversion declaration
252 enum_conv_h = """\
253 // enum corba -> local
254 inline bool
255 corba_to_local(const [corba.name_fq]& _from,
256  [local.name_fq]& _to)
257 {
258  _to = [local.name_fq]((long)_from);
259  return true;
260 }
261 
262 // enum local -> corba
263 inline bool
264 local_to_corba(const [local.name_fq]& _from,
265  [corba.name_fq]& _to)
266 {
267  _to = [corba.name_fq]((long)_from);
268  return true;
269 }
270 
271 """
272 
273 #------------------------------------------------------------
274 # enum conversion implementation
275 enum_conv_cpp = """\
276 """
277 
278 exception_conv_h = """\
279 // exxception corba -> local
280 bool
281 corba_to_local(const [local.name_fq]& _from,
282  [corba.name_fq]& _to);
283 
284 // exception local -> corba
285 bool
286 corba_to_local(const [corba.name_fq]& _from,
287  [local.name_fq]& _to);
288 
289 """
290 exception_conv_cpp = """\
291 // exception corba -> local
292 bool
293 corba_to_local(const [corba.name_fq]& _from,
294  [local.name_fq]& _to)
295 {
296 [for mem in members]
297  if (!corba_to_local(_from.[mem.corba.member_name],
298  _to.[mem.local.member_name]))
299  return false;
300 [endfor]
301  return true;
302 }
303 
304 // exception local -> corba
305 bool
306 local_to_corba(const [local.name_fq]& _from,
307  [corba.name_fq]& _to)
308 {
309 [for mem in members]
310  if (!local_to_corba(_from.[mem.local.member_name],
311  _to.[mem.corba.member_name]))
312  return false;
313 [endfor]
314  return true;
315 }
316 
317 """
318 
319 #------------------------------------------------------------
320 # typedef conversion declaration
321 typedef_decl_h = """\
322 [if corba.tk is "tk_alias"][elif corba.tk is "tk_string"][elif corba.tk is "tk_long"][else]
323 // typedef corba -> local : [corba.tk]
324 bool
325 corba_to_local(const [corba.derived_type_fq]& _from,
326  [local.derived_type_fq]& _to);
327 
328 // typedef local -> corba : [corba.tk]
329 bool
330 local_to_corba(const [local.derived_type_fq]& _from,
331  [corba.derived_type_fq]& _to);
332 
333 [endif]
334 """
335 #------------------------------------------------------------
336 # typedef conversion implementation
337 typedef_dec_cpp = """\
338 [if corba.tk is "tk_alias"][elif corba.tk is "tk_string"][elif corba.tk is "tk_long"][else]
339 // typedef corba -> local : [corba.tk]
340 bool
341 corba_to_local(const [corba.derived_type_fq]& _from,
342  [local.derived_type_fq]& _to)
343 {
344 [if corba.tk is "tk_sequence"]
345  return corba_to_local_seq< [corba.derived_type_fq],
346  [corba.element_type_fq],
347  [local.derived_type_fq],
348  [local.element_type_fq] >(_from, _to);
349 [elif corba.tk is "tk_enum"]
350  _to = [corba.derived_type_fq]((long)_from);
351  return true;
352 [elif corba.tk is "tk_string"]
353  return corba_to_local((const [corba.base_type])_from,
354  ([local.base_type]&)_to);
355 [else]
356 [if-any corba.is_primitive]
357  _to = _from;
358 [else]
359  return corba_to_local((const [corba.base_type])_from,
360  ([local.base_type]&)_to);
361 [endif]
362 [endif]
363 }
364 
365 // typedef local -> corba : [corba.tk]
366 bool
367 local_to_corba(const [local.derived_type_fq]& _from,
368  [corba.derived_type_fq]& _to)
369 {
370 [if corba.tk is "tk_sequence"]
371  return local_to_corba_seq< [local.derived_type_fq],
372  [local.element_type_fq],
373  [corba.derived_type_fq],
374  [corba.element_type_fq] >(_from, _to);
375 [elif corba.tk is "tk_enum"]
376  _to = [corba.derived_type]((CORBA::Long)rhs);
377  return true;
378 [elif corba.tk is "tk_string"]
379  return local_to_corba((const [local.base_type]&)_from,
380  ([corba.base_type])_to);
381 [else]
382 [if-any corba.is_primitive]
383  _to = _from;
384 [else]
385  return local_to_corba(([local.base_type])_from,
386  ([corba.base_type]&)_to);
387 [endif]
388 [endif]
389 }
390 [endif]
391 """
392 
393 
394 
395 #------------------------------------------------------------
396 # doil servant header file template
397 #
398 # Given keys.
399 # - servant_name : doil servant class name
400 # - iface_name : interface class name to be delegated by this servant
401 # - include_guard : include guard definition name
402 # - fq_POA_name : fully qualified POA name
403 # - operations : operation definitions
404 #
405 servant_h = """\
406 // -*- C++ -*-
407 /*!
408  * @file [local.servant_h]
409  * @brief [local.servant_name] CORBA servant for doil
410  * @date $Date$
411  * @author This file was automatically generated from [idl_fname]
412  * by omniidl/doil backend
413  *
414  * $Id$
415  */
416 #ifndef [local.servant_include_guard]
417 #define [local.servant_include_guard]
418 
419 #include <coil/Properties.h>
420 #include <doil/corba/CORBAServantBase.h>
421 #include <doil/corba/BasicTypeConversion.h>
422 [for inc in include_h]
423 #include <[inc]>
424 [endfor]
425 [for inc in inherits]
426 #include <[inc.local.servant_h]>
427 [endfor]
428 
429 #include <[types_h_path]>
430 
431 namespace doil
432 {
433  class ImplBase;
434 };
435 
436 // interface class forward declaration
437 [for ns in local.iface_ns]
438 namespace [ns]
439 {
440 [endfor]
441  class [local.iface_name];
442 [for-inv ns in local.iface_ns]
443 }; // namespace [ns]
444 
445 [endfor]
446 
447 
448 [for ns in local.servant_ns]
449 namespace [ns]
450 {
451 [endfor]
452 
453  class [local.servant_name]
454  : public virtual [corba.name_poa],
455 [for inc in inherits]
456  public virtual [inc.local.servant_name_fq],
457 [endfor]
458  public virtual ::doil::CORBA::CORBAServantBase
459  {
460  public:
461  [local.servant_name](doil::ImplBase* impl);
462  virtual ~[local.servant_name]();
463 
464 [for op in operations]
465  virtual [op.return.corba.retn_type] [op.name]
466 ([for a in op.args]
467 [if-index a is last][a.corba.arg_type] [a.corba.arg_name]
468 [else][a.corba.arg_type] [a.corba.arg_name], [endif]
469 [endfor]);
470 [endfor]
471 
472  private:
473  [local.iface_name_fq]* m_impl;
474  };
475 
476 [for-inv ns in local.servant_ns]
477 }; // namespace [ns]
478 [endfor]
479 
480 extern "C"
481 {
482  void [local.servant_name]CORBAInit(coil::Properties& prop);
483 };
484 
485 #endif // [local.servant_include_guard]
486 
487 """
488 
489 #
490 # doil servant code file template
491 #
492 # Given keys.
493 # - servant_name : doil servant class name
494 # - iface_name : interface class name to be delegated by this servant
495 # - include_guard : include guard definition name
496 # - fq_POA_name : fully qualified POA name
497 # - operations : operation definitions
498 #
499 servant_cpp = """\
500 // -*- C++ -*-
501 /*!
502  * @file [local.servant_cpp]
503  * @brief [local.iface_name] CORBA servant for doil
504  * @date $Date$
505  * @author This file was automatically generated from [idl_fname]
506  * by omniidl/doil backend
507  *
508  * $Id$
509  */
510 
511 #include <doil/ImplBase.h>
512 #include <doil/corba/CORBAManager.h>
513 #include <[local.iface_h_path]>
514 #include <[local.servant_h_path]>
515 #include <[typeconv_h_path]>
516 
517 [for ns in local.servant_ns]
518 namespace [ns]
519 {
520 [endfor]
521  /*!
522  * @brief ctor
523  */
524  [local.servant_name]::[local.servant_name](doil::ImplBase* impl)
525  : ::doil::CORBA::CORBAServantBase(impl), m_impl(NULL)[for inc in inherits],
526  [inc.local.servant_name_fq](impl)[endfor]
527  {
528  m_impl = dynamic_cast< [local.iface_name_fq]* >(impl);
529  if (m_impl == NULL) throw std::bad_alloc();
530  m_impl->incRef();
531  }
532 
533  /*!
534  * @brief dtor
535  */
536  [local.servant_name]::~[local.servant_name]()
537  {
538  m_impl->decRef();
539  }
540 
541  [for op in operations]
542 
543  /*!
544  * @brief [op.name]
545  */
546  [op.return.corba.retn_type] [local.servant_name]::[op.name]
547 ([for a in op.args]
548 [if-index a is last][a.corba.arg_type] [a.corba.arg_name]
549 [else][a.corba.arg_type] [a.corba.arg_name], [endif]
550 [endfor])
551  {
552 [for a in op.args]
553  [a.local.var_type] [a.local.var_name];
554 [endfor]
555 
556 [for a in op.args][if a.corba.direction is "out"][else]
557 [if-any a.corba.is_primitive]
558  [a.local.var_name] = [a.corba.arg_name];
559 [else]
560  corba_to_local([a.corba.arg_name], [a.local.var_name]);
561 [endif]
562 [endif][endfor]
563 
564 [if op.return.corba.tk is "tk_void"]
565 [elif op.return.corba.tk is "tk_any"]
566  [op.return.local.retn_type] local_ret;
567  [op.return.corba.retn_type] corba_ret =
568  new [op.return.corba.base_type] ();
569  local_ret =
570 [elif op.return.corba.tk is "tk_struct"]
571  [op.return.local.retn_type] local_ret;
572  [op.return.corba.retn_type] corba_ret =
573  new [op.return.corba.base_type] ();
574  local_ret =
575 [elif op.return.corba.tk is "tk_alias"]
576 [if op.return.corba.deref_tk is "tk_long"]
577  [op.return.local.retn_type] local_ret;
578  [op.return.corba.retn_type] corba_ret;
579  local_ret =
580 [elif op.return.corba.deref_tk is "tk_string"]
581  [op.return.local.retn_type] local_ret;
582  [op.return.corba.retn_type] corba_ret;
583  local_ret =
584 [else]
585  [op.return.local.retn_type] local_ret;
586  [op.return.corba.retn_type] corba_ret =
587  new [op.return.corba.base_type] ();
588  local_ret =
589 [endif]
590 [else]
591  [op.return.local.retn_type] local_ret;
592  [op.return.corba.retn_type] corba_ret;
593  local_ret =
594 [endif]
595  m_impl->[op.name]
596 ([for a in op.args][if-index a is last][a.local.var_name][else][a.local.var_name], [endif][endfor]);
597 
598 [for a in op.args][if a.corba.direction is "in"][else]
599  local_to_corba([a.local.var_name], [a.corba.arg_name]);
600 [endif][endfor]
601 [if op.return.corba.tk is "tk_void"][else]
602 [if op.return.corba.tk is "tk_any"]
603  local_to_corba(local_ret, *corba_ret);
604 [elif op.return.corba.tk is "tk_struct"]
605  local_to_corba(local_ret, *corba_ret);
606 [elif op.return.corba.tk is "tk_alias"]
607 [if op.return.corba.deref_tk is "tk_long"]
608  local_to_corba(local_ret, corba_ret);
609 [elif op.return.corba.deref_tk is "tk_string"]
610  local_to_corba(local_ret, corba_ret);
611 [else]
612  local_to_corba(local_ret, *corba_ret);
613 [endif]
614 [else]
615 [if-any op.return.corba.is_primitive]
616  corba_ret = local_ret;
617 [else]
618  local_to_corba(local_ret, corba_ret);
619 [endif]
620 [endif]
621  return corba_ret;
622 [endif]
623  }
624 [endfor]
625 
626 [for-inv ns in local.servant_ns]
627 }; // namespace [ns]
628 [endfor]
629 
630 extern "C"
631 {
632  void [local.servant_name]CORBAInit(coil::Properties& prop)
633  {
634  doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
635  mgr.registerFactory("[local.servant_name]",
636  doil::New< [local.servant_name_fq] >,
637  doil::Delete< [local.servant_name_fq] >);
638  }
639 };
640 """
641 
642 
643 
644 
645 
646 adapter_h = """\
647 // -*- C++ -*-
648 /*!
649  * @file [local.adapter_h]
650  * @brief [local.adapter_name] CORBA adapter for doil
651  * @date $Date$
652  * @author This file was automatically generated from [idl_fname]
653  * by omniidl/doil backend
654  *
655  * $Id$
656  */
657 #ifndef [local.adapter_include_guard]
658 #define [local.adapter_include_guard]
659 
660 #include <coil/Properties.h>
661 #include <coil/Mutex.h>
662 #include <coil/Guard.h>
663 #include <doil/corba/CORBAManager.h>
664 #include <doil/ImplBase.h>
665 #include <[local.iface_h]>
666 [for inc in inherits]
667 #include <[inc.local.adapter_h]>
668 [endfor]
669 [for inc in include_h]
670 #include <[inc]>
671 [endfor]
672 
673 
674 [for ns in local.adapter_ns]
675 namespace [ns]
676 {
677 [endfor]
678 
679  class [local.adapter_name]
680  : public virtual ::doil::LocalBase,
681 [for inc in inherits]
682  public virtual [inc.local.adapter_name_fq],
683 [endfor]
684  public virtual [local.iface_name_fq]
685 
686  {
687  typedef coil::Mutex Mutex;
688  typedef coil::Guard<Mutex> Guard;
689  public:
690  [local.adapter_name](::CORBA::Object_ptr obj);
691  virtual ~[local.adapter_name]();
692 
693 [for op in operations]
694  virtual [op.return.local.retn_type] [op.name]
695 ([for a in op.args]
696 [if-index a is last][a.local.arg_type] [a.local.arg_name]
697 [else][a.local.arg_type] [a.local.arg_name], [endif]
698 [endfor])
699  throw ([for raise in op.raises]
700 [if-index raise is first]
701 [raise.local.name_fq]
702 [else]
703 ,
704  [raise.local.name_fq]
705 [endif]
706 [endfor]
707 );
708 
709 
710 [endfor]
711 
712  const char* id() {return "[corba.idl_name]";}
713  const char* name() {return m_name.c_str();}
714  void incRef()
715  {
716  Guard guard(m_refcountMutex);
717  ++m_refcount;
718  }
719  void decRef()
720  {
721  Guard guard(m_refcountMutex);
722  --m_refcount;
723  if (m_refcount == 0)
724  delete this;
725  }
726 
727  private:
728  [corba.name_fq]_ptr m_obj;
729  std::string m_name;
730  Mutex m_refcountMutex;
731  int m_refcount;
732  };
733 
734 [for ns in local.adapter_ns]
735 }; // namespace [ns]
736 [endfor]
737 
738 #ifndef [local.servant_include_guard]
739 
740 
741 #endif // [local.servant_include_guard]
742 
743 
744 extern "C"
745 {
746  void [local.adapter_name]CORBAInit(coil::Properties& prop);
747 };
748 
749 #endif // [local.adapter_include_guard]
750 
751 """
752 
753 
754 adapter_cpp = """\
755 // -*- C++ -*-
756 /*!
757  * @file [local.adapter_cpp]
758  * @brief [local.iface_name] CORBA adapter for doil
759  * @date $Date$
760  * @author This file was automatically generated form [idl_fname]
761  * by omniidl/doil backend
762  *
763  * $Id$
764  */
765 
766 #include <doil/ImplBase.h>
767 #include <doil/corba/CORBAManager.h>
768 #include <[local.iface_h_path]>
769 #include <[local.adapter_h_path]>
770 #include <[typeconv_h_path]>
771 #include <doil/corba/BasicTypeConversion.h>
772 
773 [for ns in local.adapter_ns]
774 namespace [ns]
775 {
776 [endfor]
777  /*!
778  * @brief ctor
779  */
780  [local.adapter_name]::[local.adapter_name](::CORBA::Object_ptr obj)
781  : m_obj([corba.name_fq]::_nil()),
782  m_refcount(1)[for inc in inherits],
783  [inc.local.adapter_name_fq](obj)[endfor]
784 
785  {
786  m_obj = [corba.name_fq]::_narrow(obj);
787  if (::CORBA::is_nil(m_obj)) throw std::bad_alloc();
788  m_obj = [corba.name_fq]::_duplicate(m_obj);
789  }
790 
791  /*!
792  * @brief dtor
793  */
794  [local.adapter_name]::~[local.adapter_name]()
795  {
796  ::CORBA::release(m_obj);
797  }
798 
799  [for op in operations]
800 
801  /*!
802  * @brief [op.name]
803  */
804  [op.return.local.retn_type] [local.adapter_name]::[op.name]
805 ([for a in op.args]
806 [if-index a is last][a.local.arg_type] [a.local.arg_name]
807 [else][a.local.arg_type] [a.local.arg_name], [endif]
808 [endfor])
809  throw ([for raise in op.raises]
810 [if-index raise is first]
811 [raise.local.name_fq]
812 [else]
813 ,
814  [raise.local.name_fq]
815 [endif]
816 [endfor]
817 )
818  {
819  // Convert Local to CORBA.
820  // (The direction of the argument is 'in' or 'inout'.)
821 [for a in op.args]
822  [a.corba.base_type] [a.corba.var_name];
823 [endfor]
824 [for a in op.args][if a.local.direction is "out"][else]
825 [if-any a.corba.is_primitive]
826  [a.corba.var_name] = [a.local.arg_name];
827 [else]
828 [if a.local.tk is "tk_objref"]
829  local_to_corba(const_cast< [a.local.var_type] >([a.local.arg_name]), [a.corba.var_name]);
830 [else]
831  local_to_corba([a.local.arg_name], [a.corba.var_name]);
832 [endif]
833 [endif]
834 [endif][endfor]
835 
836  // Execute the method.
837 [if op.return.local.tk is "tk_void"][else]
838  [op.return.corba.retn_type] corba_ret;
839  [op.return.local.retn_type] local_ret;
840  corba_ret = [endif]
841 m_obj->[op.name]
842 ([for a in op.args][if-index a is last][a.corba.var_name][else][a.corba.var_name], [endif][endfor]);
843 
844  // Convert CORBA to Local.
845  // (The direction of the argument is 'out' or 'inout'.)
846 [for a in op.args][if a.local.direction is "in"][else]
847 [if-any a.corba.is_primitive]
848  [a.local.arg_name] = [a.corba.var_name];
849 [else]
850  corba_to_local([a.corba.var_name], [a.local.arg_name]);
851 [endif]
852 [endif][endfor]
853 
854  // Generate the return value.
855 [if op.return.local.tk is "tk_void"][else]
856 [if op.return.local.tk is "tk_objref"]
857  corba_to_local(corba_ret, local_ret);
858 [elif op.return.local.tk is "tk_enum"]
859  corba_to_local(corba_ret, local_ret);
860 [else]
861 [if-any op.return.corba.is_primitive]
862  local_ret = corba_ret;
863 [else]
864 [if op.return.corba.deref_tk is "tk_long"]
865  local_ret = corba_ret;
866 [elif op.return.corba.deref_tk is "tk_string"]
867  corba_to_local(corba_ret, local_ret);
868 [else]
869  corba_to_local(*corba_ret, local_ret);
870 [endif]
871 [endif]
872 [endif]
873 [if op.return.corba.tk is "tk_any"]
874  delete corba_ret;
875 [elif op.return.corba.tk is "tk_struct"]
876  delete corba_ret;
877 [elif op.return.corba.tk is "tk_string"]
878  ::CORBA::string_free(corba_ret);
879 [elif op.return.local.tk is "tk_objref"]
880  ::CORBA::release(corba_ret);
881 [elif op.return.corba.tk is "tk_alias"]
882 [if op.return.corba.deref_tk is "tk_long"]
883 [elif op.return.corba.deref_tk is "tk_string"]
884  ::CORBA::string_free(corba_ret);
885 [else]
886  delete corba_ret;
887 [endif]
888 [endif]
889  return local_ret;
890 [endif]
891  }
892 [endfor]
893 
894 [for ns in local.adapter_ns]
895 }; // namespace [ns]
896 [endfor]
897 
898 extern "C"
899 {
900  void [local.adapter_name]CORBAInit(coil::Properties& prop)
901  {
902  doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
903  mgr.registerAdapterFactory("[local.adapter_name]",
904  doil::New< [local.adapter_name_fq] >,
905  doil::Delete< [local.adapter_name_fq] >);
906  }
907 };
908 
909 """
910 
911 
912 
913 
914 
915 proxy_h = """\
916 // -*- C++ -*-
917 /*!
918  * @file [local.proxy_h]
919  * @brief [local.proxy_name] CORBA proxy for doil
920  * @date $Date$
921  * @author This file was automatically generated from [idl_fname]
922  * by omniidl/doil backend
923  *
924  * $Id$
925  */
926 #ifndef [local.proxy_include_guard]
927 #define [local.proxy_include_guard]
928 
929 #include <coil/Properties.h>
930 #include <coil/Mutex.h>
931 #include <coil/Guard.h>
932 #include <doil/corba/CORBAManager.h>
933 #include <doil/corba/CORBAProxyBase.h>
934 #include <[local.iface_h]>
935 [for inc in inherits]
936 #include <[inc.local.proxy_h]>
937 [endfor]
938 [for inc in include_h]
939 #include <[inc]>
940 [endfor]
941 
942 
943 [for ns in local.proxy_ns]
944 namespace [ns]
945 {
946 [endfor]
947 
948  class [local.proxy_name]
949  : public virtual ::doil::CORBA::CORBAProxyBase,
950 [for inc in inherits]
951  public virtual [inc.local.proxy_name_fq],
952 [endfor]
953  public virtual [local.iface_name_fq]
954 
955  {
956  typedef coil::Mutex Mutex;
957  typedef coil::Guard<Mutex> Guard;
958  public:
959  [local.proxy_name](::CORBA::Object_ptr obj);
960  virtual ~[local.proxy_name]();
961 
962 [for op in operations]
963  virtual [op.return.local.retn_type] [op.name]
964 ([for a in op.args]
965 [if-index a is last][a.local.arg_type] [a.local.arg_name]
966 [else][a.local.arg_type] [a.local.arg_name], [endif]
967 [endfor])
968  throw ([for raise in op.raises]
969 [if-index raise is first]
970 [raise.local.name_fq]
971 [else]
972 ,
973  [raise.local.name_fq]
974 [endif]
975 [endfor]
976 );
977 
978 
979 [endfor]
980 
981  const char* id() {return "[corba.idl_name]";}
982  const char* name() {return m_name.c_str();}
983  void incRef()
984  {
985  Guard guard(m_refcountMutex);
986  ++m_refcount;
987  }
988  void decRef()
989  {
990  Guard guard(m_refcountMutex);
991  --m_refcount;
992  if (m_refcount == 0)
993  delete this;
994  }
995 
996  private:
997  [corba.name_fq]_ptr m_obj;
998  private:
999  std::string m_name;
1000  Mutex m_refcountMutex;
1001  int m_refcount;
1002  };
1003 
1004 [for ns in local.proxy_ns]
1005 }; // namespace [ns]
1006 [endfor]
1007 
1008 #ifndef [local.servant_include_guard]
1009 
1010 
1011 #endif // [local.servant_include_guard]
1012 
1013 
1014 extern "C"
1015 {
1016  void [local.proxy_name]CORBAInit(coil::Properties& prop);
1017 };
1018 
1019 #endif // [local.proxy_include_guard]
1020 
1021 """
1022 
1023 
1024 proxy_cpp = """\
1025 // -*- C++ -*-
1026 /*!
1027  * @file [local.proxy_cpp]
1028  * @brief [local.iface_name] CORBA proxy for doil
1029  * @date $Date$
1030  * @author This file was automatically generated form [idl_fname]
1031  * by omniidl/doil backend
1032  *
1033  * $Id$
1034  */
1035 
1036 #include <doil/corba/CORBAManager.h>
1037 #include <[local.iface_h_path]>
1038 #include <[local.proxy_h_path]>
1039 #include <[typeconv_h_path]>
1040 #include <doil/corba/BasicTypeConversion.h>
1041 
1042 [for ns in local.proxy_ns]
1043 namespace [ns]
1044 {
1045 [endfor]
1046  /*!
1047  * @brief ctor
1048  */
1049  [local.proxy_name]::[local.proxy_name](::CORBA::Object_ptr obj)
1050  : m_obj([corba.name_fq]::_nil()),
1051  m_refcount(1)[for inc in inherits],
1052  [inc.local.proxy_name_fq](obj)[endfor]
1053 // : m_obj([corba.name_fq]::_nil())[for inc in inherits],
1054 // [inc.local.proxy_name_fq](obj)[endfor]
1055 
1056  {
1057  m_obj = [corba.name_fq]::_narrow(obj);
1058  if (::CORBA::is_nil(m_obj)) throw std::bad_alloc();
1059  m_obj = [corba.name_fq]::_duplicate(m_obj);
1060  }
1061 
1062  /*!
1063  * @brief dtor
1064  */
1065  [local.proxy_name]::~[local.proxy_name]()
1066  {
1067  ::CORBA::release(m_obj);
1068  }
1069 
1070  [for op in operations]
1071 
1072  /*!
1073  * @brief [op.name]
1074  */
1075  [op.return.local.retn_type] [local.proxy_name]::[op.name]
1076 ([for a in op.args]
1077 [if-index a is last][a.local.arg_type] [a.local.arg_name]
1078 [else][a.local.arg_type] [a.local.arg_name], [endif]
1079 [endfor])
1080  throw ([for raise in op.raises]
1081 [if-index raise is first]
1082 [raise.local.name_fq]
1083 [else]
1084 ,
1085  [raise.local.name_fq]
1086 [endif]
1087 [endfor]
1088 )
1089  {
1090  // Convert Local to CORBA.
1091  // (The direction of the argument is 'in' or 'inout'.)
1092 [for a in op.args]
1093  [a.corba.base_type] [a.corba.var_name];
1094 [endfor]
1095 [for a in op.args][if a.local.direction is "out"][else]
1096 [if-any a.corba.is_primitive]
1097 // [a.corba.var_name] = [a.local.arg_name];
1098  local_to_corba([a.local.arg_name], [a.corba.var_name]);
1099 [else]
1100 [if a.local.tk is "tk_objref"]
1101  local_to_corba(const_cast< [a.local.var_type] >([a.local.arg_name]), [a.corba.var_name]);
1102 [else]
1103  local_to_corba([a.local.arg_name], [a.corba.var_name]);
1104 [endif]
1105 [endif]
1106 [endif][endfor]
1107 
1108  // Execute the method.
1109 [if op.return.local.tk is "tk_void"][else]
1110  [op.return.corba.retn_type] corba_ret;
1111  [op.return.local.retn_type] local_ret;
1112  corba_ret = [endif]
1113 m_obj->[op.name]
1114 ([for a in op.args][if-index a is last][a.corba.var_name][else][a.corba.var_name], [endif][endfor]);
1115 
1116  // Convert CORBA to Local.
1117  // (The direction of the argument is 'out' or 'inout'.)
1118 [for a in op.args][if a.local.direction is "in"][else]
1119 [if-any a.corba.is_primitive]
1120 // [a.local.arg_name] = [a.corba.var_name];
1121  corba_to_local([a.corba.var_name], [a.local.arg_name]);
1122 [else]
1123  corba_to_local([a.corba.var_name], [a.local.arg_name]);
1124 [endif]
1125 [endif][endfor]
1126 
1127  // Generate the return value.
1128 [if op.return.local.tk is "tk_void"][else]
1129 [if op.return.local.tk is "tk_objref"]
1130  corba_to_local(corba_ret, local_ret);
1131 [elif op.return.local.tk is "tk_enum"]
1132  corba_to_local(corba_ret, local_ret);
1133 [else]
1134 [if-any op.return.corba.is_primitive]
1135 // local_ret = corba_ret;
1136  corba_to_local(corba_ret, local_ret);
1137 [else]
1138 [if op.return.corba.deref_tk is "tk_long"]
1139 // local_ret = corba_ret;
1140  corba_to_local(corba_ret, local_ret);
1141 [elif op.return.corba.deref_tk is "tk_string"]
1142  corba_to_local(corba_ret, local_ret);
1143 [else]
1144  corba_to_local(*corba_ret, local_ret);
1145 [endif]
1146 [endif]
1147 [endif]
1148 [if op.return.corba.tk is "tk_any"]
1149  delete corba_ret;
1150 [elif op.return.corba.tk is "tk_struct"]
1151  delete corba_ret;
1152 [elif op.return.corba.tk is "tk_string"]
1153  ::CORBA::string_free(corba_ret);
1154 [elif op.return.local.tk is "tk_objref"]
1155  ::CORBA::release(corba_ret);
1156 [elif op.return.corba.tk is "tk_alias"]
1157 [if op.return.corba.deref_tk is "tk_long"]
1158 [elif op.return.corba.deref_tk is "tk_string"]
1159  ::CORBA::string_free(corba_ret);
1160 [else]
1161  delete corba_ret;
1162 [endif]
1163 [endif]
1164  return local_ret;
1165 [endif]
1166  }
1167 [endfor]
1168 
1169 [for ns in local.proxy_ns]
1170 }; // namespace [ns]
1171 [endfor]
1172 
1173 extern "C"
1174 {
1175  void [local.proxy_name]CORBAInit(coil::Properties& prop)
1176  {
1177  doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
1178  mgr.registerProxyFactory("[local.proxy_name]",
1179  doil::New< [local.proxy_name_fq] >,
1180  doil::Delete< [local.proxy_name_fq] >);
1181  }
1182 };
1183 
1184 """
1185 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:56