template.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- python -*-
00003 #
00004 #  @file template.py
00005 #  @brief doil servant class template
00006 #  @date $Date$
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2008
00010 #      Task-intelligence Research Group,
00011 #      Intelligent Systems Research Institute,
00012 #      National Institute of
00013 #          Advanced Industrial Science and Technology (AIST), Japan
00014 #      All rights reserved.
00015 # 
00016 #  $Id$
00017 # 
00018 
00019 
00020 # doil type conversion header
00021 typeconv_h = """\
00022 // -*- C++ -*-
00023 /*!
00024  * @file TypeConversion.h
00025  * @brief doil-CORBA type conversion
00026  * @date $Date$
00027  * @author This file was automatically generated from [idl_fname] 
00028  *         by omniidl/doil backend
00029  *
00030  * $Id$
00031  */
00032 
00033 #ifndef [typeconv_include_guard] 
00034 #define [typeconv_include_guard] 
00035 
00036 //
00037 [for inc in include_h]
00038 #include <[inc]>
00039 [endfor]
00040 
00041 #include <[types_h_path]>
00042 
00043 [for decl in declarations]
00044 [decl]
00045 [endfor]
00046 
00047 #endif // [typeconv_include_guard]
00048 
00049 """
00050 typeconv_cpp = """\
00051 // -*- C++ -*-
00052 /*!
00053  * @file TypeConversion.h
00054  * @brief doil-CORBA type conversion
00055  * @date $Date$
00056  * @author This file was automatically generated from [idl_fname] 
00057  *         by omniidl/doil backend
00058  *
00059  * $Id$
00060  */
00061 
00062 #include <doil/corba/BasicTypeConversion.h>
00063 #include <[typeconv_h_path]>
00064 #include <doil/corba/SeqTypeConversion.h>
00065 #include <doil/corba/CORBAManager.h>
00066 
00067 [for node in tree]
00068 [if node.corba.decl_type is "interface"]
00069 #include <[node.local.iface_h_path]>
00070 [endif]
00071 [endfor]
00072 
00073 [for impl in implementations]
00074 [impl]
00075 [endfor]
00076 
00077 // end of TypeConversion
00078 
00079 """
00080 
00081 
00082 #------------------------------------------------------------
00083 # object conversion declaration
00084 object_conv_h = """\
00085 // corba object -> local object
00086 bool
00087 corba_to_local([corba.name_fq]_ptr _from,
00088                [local.iface_name_fq]* _to);
00089 
00090 // local object -> corba object
00091 bool
00092 local_to_corba([local.iface_name_fq]* _from,
00093                [corba.name_fq]_ptr _to);
00094 
00095 """
00096 
00097 #------------------------------------------------------------
00098 # object conversion implementation
00099 object_conv_cpp = """\
00100 // corba object -> local object
00101 bool
00102 corba_to_local([corba.name_fq]_ptr _from,
00103                [local.iface_name_fq]* _to)
00104 {
00105   doil::LocalBase* lobj;
00106   lobj = doil::CORBA::CORBAManager::instance().toLocal((::CORBA::Object_ptr&)_from);
00107   if (lobj == NULL) return false;
00108   _to = dynamic_cast< [local.iface_name_fq]* >(lobj);
00109   if (_to == NULL) return false;
00110   return true;
00111 }
00112 
00113 // local object -> corba object
00114 bool
00115 local_to_corba([local.iface_name_fq]* _from,
00116                [corba.name_fq]_ptr _to)
00117 {
00118   CORBA::Object_ptr obj;
00119   obj = doil::CORBA::CORBAManager::instance().toReference((doil::LocalBase*)_from);
00120   _to = [corba.name_fq]::_narrow(obj);
00121   if (CORBA::is_nil(_to)) return false;
00122   return true;
00123 }
00124 
00125 """
00126 
00127 #------------------------------------------------------------
00128 # object declaration
00129 struct_conv_h = """\
00130 // struct corba -> local
00131 bool
00132 corba_to_local(const [corba.name_fq]& _from,
00133                [local.name_fq]& _to);
00134 
00135 // struct local -> corba
00136 bool
00137 local_to_corba(const [local.name_fq]& _from,
00138                [corba.name_fq]& _to);
00139 
00140 """
00141 #------------------------------------------------------------
00142 # struct conversion declaration
00143 struct_conv_cpp = """\
00144 // struct corba -> local
00145 bool
00146 corba_to_local(const [corba.name_fq]& _from,
00147                [local.name_fq]& _to)
00148 {
00149 [for mem in members]
00150 [if mem.corba.tk is "tk_objref"]
00151   if (!corba_to_local(([mem.corba.base_type]&)_from.[mem.corba.member_name],
00152                       _to.[mem.local.member_name]))
00153 [else]
00154   if (!corba_to_local(_from.[mem.corba.member_name],
00155                       _to.[mem.local.member_name]))
00156 [endif]
00157      return false;
00158 [endfor]
00159   return true;
00160 }
00161 
00162 // struct local -> corba
00163 bool
00164 local_to_corba(const [local.name_fq]& _from,
00165                [corba.name_fq]& _to)
00166 {
00167 [for mem in members]
00168 [if mem.corba.tk is "tk_objref"]
00169   if (!local_to_corba(_from.[mem.local.member_name],
00170                       ([mem.corba.base_type]&)_to.[mem.corba.member_name]))
00171 [else]
00172   if (!local_to_corba(_from.[mem.local.member_name],
00173                       _to.[mem.corba.member_name]))
00174 [endif]
00175      return false;
00176 [endfor]
00177   return true;
00178 }
00179 
00180 """
00181 
00182 #------------------------------------------------------------
00183 # union conversion declaration
00184 union_conv_h = """\
00185 // union corba -> local
00186 bool
00187 corba_to_local(const [local.name_fq]& _from,
00188                [corba.name_fq]& _to);
00189 
00190 // union local -> corba
00191 bool
00192 corba_to_local(const [corba.name_fq]& _from,
00193                [local.name_fq]& _to);
00194 
00195 """
00196 
00197 #------------------------------------------------------------
00198 # union conversion implementation
00199 union_conv_cpp = """\
00200 // union corba -> local
00201 bool
00202 corba_to_local(const [corba.name_fq]& _from,
00203                [local.name_fq]& _to)
00204 {
00205   switch (_from._d())
00206     {
00207 [for cas in cases]
00208      case [cas.corba.discriminator_fq] :
00209        {
00210          [cas.local.case_type] l[cas.local.case_member];
00211          [cas.corba.case_type] c[cas.corba.case_member];
00212          c[cas.corba.case_member] = _from.[cas.corba.case_member]();
00213          corba_to_local(c[cas.corba.case_member], l[cas.local.case_member]);
00214          _to.set_[cas.local.case_member](l[cas.local.case_member]);
00215          break;
00216        }
00217 [endfor]
00218       default:
00219         return false;
00220     }
00221   return true;
00222 }
00223 
00224 // union local -> corba
00225 bool
00226 local_to_corba(const [local.name_fq]& _from,
00227                [corba.name_fq]& _to)
00228 {
00229   switch (_from.get_type())
00230     {
00231 [for cas in cases]
00232     case [cas.local.discriminator_fq] :
00233       {
00234         [cas.corba.case_type] c[cas.corba.case_member];
00235         [cas.local.case_type] l[cas.local.case_member];
00236         l[cas.local.case_member] = _from.get_[cas.corba.case_member]();
00237         local_to_corba(l[cas.local.case_member], c[cas.corba.case_member]);
00238         _to.[cas.local.case_member](c[cas.corba.case_member]);
00239         break;
00240       }
00241 [endfor]
00242       default:
00243         return false;
00244     }
00245   return true;
00246 }
00247 
00248 """
00249 
00250 #------------------------------------------------------------
00251 # enum conversion declaration
00252 enum_conv_h = """\
00253 // enum corba -> local
00254 inline bool
00255 corba_to_local(const [corba.name_fq]& _from,
00256                [local.name_fq]& _to)
00257 {
00258   _to = [local.name_fq]((long)_from);
00259   return true;
00260 }
00261 
00262 // enum local -> corba
00263 inline bool
00264 local_to_corba(const [local.name_fq]& _from,
00265                [corba.name_fq]& _to)
00266 {
00267   _to = [corba.name_fq]((long)_from);
00268   return true;
00269 }
00270 
00271 """
00272 
00273 #------------------------------------------------------------
00274 # enum conversion implementation
00275 enum_conv_cpp = """\
00276 """
00277 
00278 exception_conv_h = """\
00279 // exxception corba -> local
00280 bool
00281 corba_to_local(const [local.name_fq]& _from,
00282                [corba.name_fq]& _to);
00283 
00284 // exception local -> corba
00285 bool
00286 corba_to_local(const [corba.name_fq]& _from,
00287                [local.name_fq]& _to);
00288 
00289 """
00290 exception_conv_cpp = """\
00291 // exception corba -> local
00292 bool
00293 corba_to_local(const [corba.name_fq]& _from,
00294                [local.name_fq]& _to)
00295 {
00296 [for mem in members]
00297   if (!corba_to_local(_from.[mem.corba.member_name],
00298                       _to.[mem.local.member_name]))
00299      return false;
00300 [endfor]
00301   return true;
00302 }
00303 
00304 // exception local -> corba
00305 bool
00306 local_to_corba(const [local.name_fq]& _from,
00307                [corba.name_fq]& _to)
00308 {
00309 [for mem in members]
00310   if (!local_to_corba(_from.[mem.local.member_name],
00311                       _to.[mem.corba.member_name]))
00312      return false;
00313 [endfor]
00314   return true;
00315 }
00316 
00317 """
00318 
00319 #------------------------------------------------------------
00320 # typedef conversion declaration
00321 typedef_decl_h = """\
00322 [if corba.tk is "tk_alias"][elif corba.tk is "tk_string"][elif corba.tk is "tk_long"][else]
00323 // typedef corba -> local : [corba.tk] 
00324 bool
00325 corba_to_local(const [corba.derived_type_fq]& _from,
00326                [local.derived_type_fq]& _to);
00327 
00328 // typedef local -> corba : [corba.tk] 
00329 bool
00330 local_to_corba(const [local.derived_type_fq]& _from,
00331                [corba.derived_type_fq]& _to);
00332 
00333 [endif]
00334 """
00335 #------------------------------------------------------------
00336 # typedef conversion implementation
00337 typedef_dec_cpp = """\
00338 [if corba.tk is "tk_alias"][elif corba.tk is "tk_string"][elif corba.tk is "tk_long"][else]
00339 // typedef corba -> local : [corba.tk] 
00340 bool
00341 corba_to_local(const [corba.derived_type_fq]& _from,
00342                [local.derived_type_fq]& _to)
00343 {
00344 [if corba.tk is "tk_sequence"]
00345   return corba_to_local_seq< [corba.derived_type_fq],
00346                              [corba.element_type_fq],
00347                              [local.derived_type_fq],
00348                              [local.element_type_fq] >(_from, _to);
00349 [elif corba.tk is "tk_enum"]
00350   _to = [corba.derived_type_fq]((long)_from);
00351   return true;
00352 [elif corba.tk is "tk_string"]
00353   return corba_to_local((const [corba.base_type])_from,
00354                         ([local.base_type]&)_to);
00355 [else]
00356 [if-any corba.is_primitive]
00357   _to = _from;
00358 [else]
00359   return corba_to_local((const [corba.base_type])_from,
00360                         ([local.base_type]&)_to);
00361 [endif]
00362 [endif]
00363 }
00364 
00365 // typedef local -> corba : [corba.tk] 
00366 bool
00367 local_to_corba(const [local.derived_type_fq]& _from,
00368                [corba.derived_type_fq]& _to)
00369 {
00370 [if corba.tk is "tk_sequence"]
00371   return local_to_corba_seq< [local.derived_type_fq],
00372                              [local.element_type_fq],
00373                              [corba.derived_type_fq],
00374                              [corba.element_type_fq] >(_from, _to);
00375 [elif corba.tk is "tk_enum"]
00376   _to = [corba.derived_type]((CORBA::Long)rhs);
00377   return true;
00378 [elif corba.tk is "tk_string"]
00379   return local_to_corba((const [local.base_type]&)_from,
00380                         ([corba.base_type])_to);
00381 [else]
00382 [if-any corba.is_primitive]
00383   _to = _from;
00384 [else]
00385   return local_to_corba(([local.base_type])_from,
00386                         ([corba.base_type]&)_to);
00387 [endif]
00388 [endif]
00389 }
00390 [endif]
00391 """
00392 
00393 
00394 
00395 #------------------------------------------------------------
00396 # doil servant header file template
00397 #
00398 # Given keys.
00399 # - servant_name   : doil servant class name
00400 # - iface_name : interface class name to be delegated by this servant
00401 # - include_guard  : include guard definition name
00402 # - fq_POA_name    : fully qualified POA name
00403 # - operations     : operation definitions
00404 #
00405 servant_h = """\
00406 // -*- C++ -*-
00407 /*!
00408  * @file [local.servant_h] 
00409  * @brief [local.servant_name] CORBA servant for doil
00410  * @date $Date$
00411  * @author This file was automatically generated from [idl_fname]
00412  *         by omniidl/doil backend
00413  *
00414  * $Id$
00415  */
00416 #ifndef [local.servant_include_guard] 
00417 #define [local.servant_include_guard] 
00418 
00419 #include <coil/Properties.h>
00420 #include <doil/corba/CORBAServantBase.h>
00421 #include <doil/corba/BasicTypeConversion.h>
00422 [for inc in include_h]
00423 #include <[inc]>
00424 [endfor]
00425 [for inc in inherits]
00426 #include <[inc.local.servant_h]>
00427 [endfor]
00428 
00429 #include <[types_h_path]>
00430 
00431 namespace doil
00432 {
00433   class ImplBase;
00434 };
00435 
00436 // interface class forward declaration
00437 [for ns in local.iface_ns]
00438 namespace [ns] 
00439 {
00440 [endfor]
00441   class [local.iface_name];
00442 [for-inv ns in local.iface_ns]
00443 }; // namespace [ns]
00444 
00445 [endfor]
00446 
00447 
00448 [for ns in local.servant_ns]
00449 namespace [ns] 
00450 {
00451 [endfor]
00452 
00453   class [local.servant_name] 
00454    : public virtual [corba.name_poa],
00455 [for inc in inherits]
00456      public virtual [inc.local.servant_name_fq],
00457 [endfor]
00458      public virtual ::doil::CORBA::CORBAServantBase
00459   {
00460   public:
00461     [local.servant_name](doil::ImplBase* impl);
00462     virtual ~[local.servant_name]();
00463 
00464 [for op in operations]
00465     virtual [op.return.corba.retn_type] [op.name]
00466 ([for a in op.args]
00467 [if-index a is last][a.corba.arg_type] [a.corba.arg_name]
00468 [else][a.corba.arg_type] [a.corba.arg_name], [endif]
00469 [endfor]);
00470 [endfor]
00471 
00472   private:
00473     [local.iface_name_fq]* m_impl;
00474   };
00475 
00476 [for-inv ns in local.servant_ns]
00477 }; // namespace [ns] 
00478 [endfor]
00479 
00480 extern "C"
00481 {
00482   void [local.servant_name]CORBAInit(coil::Properties& prop);
00483 };
00484 
00485 #endif // [local.servant_include_guard]
00486 
00487 """
00488 
00489 #
00490 # doil servant code file template
00491 #
00492 # Given keys.
00493 # - servant_name   : doil servant class name
00494 # - iface_name : interface class name to be delegated by this servant
00495 # - include_guard  : include guard definition name
00496 # - fq_POA_name    : fully qualified POA name
00497 # - operations     : operation definitions
00498 #
00499 servant_cpp = """\
00500 // -*- C++ -*-
00501 /*!
00502  * @file [local.servant_cpp] 
00503  * @brief [local.iface_name] CORBA servant for doil
00504  * @date $Date$
00505  * @author This file was automatically generated from [idl_fname]
00506  *         by omniidl/doil backend
00507  *
00508  * $Id$
00509  */
00510 
00511 #include <doil/ImplBase.h>
00512 #include <doil/corba/CORBAManager.h>
00513 #include <[local.iface_h_path]>
00514 #include <[local.servant_h_path]>
00515 #include <[typeconv_h_path]>
00516 
00517 [for ns in local.servant_ns]
00518 namespace [ns] 
00519 {
00520 [endfor]
00521   /*!
00522    * @brief ctor
00523    */ 
00524   [local.servant_name]::[local.servant_name](doil::ImplBase* impl)
00525    : ::doil::CORBA::CORBAServantBase(impl), m_impl(NULL)[for inc in inherits],
00526      [inc.local.servant_name_fq](impl)[endfor] 
00527   {
00528     m_impl = dynamic_cast< [local.iface_name_fq]* >(impl);
00529     if (m_impl == NULL) throw std::bad_alloc();
00530     m_impl->incRef();
00531   }
00532 
00533   /*!
00534    * @brief dtor
00535    */ 
00536   [local.servant_name]::~[local.servant_name]()
00537   {
00538     m_impl->decRef();
00539   }
00540 
00541   [for op in operations]
00542 
00543   /*!
00544    * @brief [op.name] 
00545    */ 
00546   [op.return.corba.retn_type] [local.servant_name]::[op.name]
00547 ([for a in op.args]
00548 [if-index a is last][a.corba.arg_type] [a.corba.arg_name]
00549 [else][a.corba.arg_type] [a.corba.arg_name], [endif]
00550 [endfor])
00551   {
00552 [for a in op.args]
00553     [a.local.var_type] [a.local.var_name];
00554 [endfor]
00555 
00556 [for a in op.args][if a.corba.direction is "out"][else]
00557 [if-any a.corba.is_primitive]
00558     [a.local.var_name] = [a.corba.arg_name];
00559 [else]
00560     corba_to_local([a.corba.arg_name], [a.local.var_name]);
00561 [endif]
00562 [endif][endfor]
00563 
00564 [if op.return.corba.tk is "tk_void"]
00565 [elif op.return.corba.tk is "tk_any"]
00566     [op.return.local.retn_type] local_ret;
00567     [op.return.corba.retn_type] corba_ret = 
00568         new [op.return.corba.base_type] ();
00569     local_ret =
00570 [elif op.return.corba.tk is "tk_struct"]
00571     [op.return.local.retn_type] local_ret;
00572     [op.return.corba.retn_type] corba_ret = 
00573         new [op.return.corba.base_type] ();
00574     local_ret =
00575 [elif op.return.corba.tk is "tk_alias"]
00576 [if op.return.corba.deref_tk is "tk_long"]
00577     [op.return.local.retn_type] local_ret;
00578     [op.return.corba.retn_type] corba_ret;
00579     local_ret =
00580 [elif op.return.corba.deref_tk is "tk_string"]
00581     [op.return.local.retn_type] local_ret;
00582     [op.return.corba.retn_type] corba_ret;
00583     local_ret =
00584 [else]
00585     [op.return.local.retn_type] local_ret;
00586     [op.return.corba.retn_type] corba_ret = 
00587         new [op.return.corba.base_type] ();
00588     local_ret =
00589 [endif]
00590 [else]
00591     [op.return.local.retn_type] local_ret;
00592     [op.return.corba.retn_type] corba_ret;
00593     local_ret = 
00594 [endif]
00595         m_impl->[op.name]
00596 ([for a in op.args][if-index a is last][a.local.var_name][else][a.local.var_name], [endif][endfor]);
00597 
00598 [for a in op.args][if a.corba.direction is "in"][else]
00599     local_to_corba([a.local.var_name], [a.corba.arg_name]);
00600 [endif][endfor]
00601 [if op.return.corba.tk is "tk_void"][else]
00602 [if op.return.corba.tk is "tk_any"]
00603     local_to_corba(local_ret, *corba_ret);
00604 [elif op.return.corba.tk is "tk_struct"]
00605     local_to_corba(local_ret, *corba_ret);
00606 [elif op.return.corba.tk is "tk_alias"]
00607 [if op.return.corba.deref_tk is "tk_long"]
00608     local_to_corba(local_ret, corba_ret);
00609 [elif op.return.corba.deref_tk is "tk_string"]
00610     local_to_corba(local_ret, corba_ret);
00611 [else]
00612     local_to_corba(local_ret, *corba_ret);
00613 [endif]
00614 [else]
00615 [if-any op.return.corba.is_primitive]
00616     corba_ret = local_ret;
00617 [else]
00618     local_to_corba(local_ret, corba_ret);
00619 [endif]
00620 [endif]
00621     return corba_ret;
00622 [endif]
00623   }
00624 [endfor]
00625 
00626 [for-inv ns in local.servant_ns]
00627 }; // namespace [ns] 
00628 [endfor]
00629 
00630 extern "C"
00631 {
00632   void [local.servant_name]CORBAInit(coil::Properties& prop)
00633   {
00634     doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
00635     mgr.registerFactory("[local.servant_name]",
00636                         doil::New< [local.servant_name_fq] >,
00637                         doil::Delete< [local.servant_name_fq] >);
00638   }
00639 };
00640 """
00641 
00642 
00643 
00644 
00645 
00646 adapter_h = """\
00647 // -*- C++ -*-
00648 /*!
00649  * @file [local.adapter_h] 
00650  * @brief [local.adapter_name] CORBA adapter for doil
00651  * @date $Date$
00652  * @author This file was automatically generated from [idl_fname] 
00653  *         by omniidl/doil backend
00654  *
00655  * $Id$
00656  */
00657 #ifndef [local.adapter_include_guard] 
00658 #define [local.adapter_include_guard] 
00659 
00660 #include <coil/Properties.h>
00661 #include <coil/Mutex.h>
00662 #include <coil/Guard.h>
00663 #include <doil/corba/CORBAManager.h>
00664 #include <doil/ImplBase.h>
00665 #include <[local.iface_h]>
00666 [for inc in inherits]
00667 #include <[inc.local.adapter_h]>
00668 [endfor]
00669 [for inc in include_h]
00670 #include <[inc]>
00671 [endfor]
00672 
00673 
00674 [for ns in local.adapter_ns]
00675 namespace [ns] 
00676 {
00677 [endfor]
00678 
00679   class [local.adapter_name] 
00680   : public virtual ::doil::LocalBase,
00681 [for inc in inherits]
00682     public virtual [inc.local.adapter_name_fq],
00683 [endfor]
00684     public virtual [local.iface_name_fq]
00685 
00686   {
00687     typedef coil::Mutex Mutex;
00688     typedef coil::Guard<Mutex> Guard;
00689   public:
00690     [local.adapter_name](::CORBA::Object_ptr obj);
00691     virtual ~[local.adapter_name]();
00692 
00693 [for op in operations]
00694     virtual [op.return.local.retn_type] [op.name]
00695 ([for a in op.args]
00696 [if-index a is last][a.local.arg_type] [a.local.arg_name]
00697 [else][a.local.arg_type] [a.local.arg_name], [endif]
00698 [endfor])
00699       throw ([for raise in op.raises]
00700 [if-index raise is first]
00701 [raise.local.name_fq]
00702 [else]
00703 ,
00704              [raise.local.name_fq]
00705 [endif]
00706 [endfor]
00707 );
00708 
00709 
00710 [endfor]
00711 
00712     const char* id() {return "[corba.idl_name]";}
00713     const char* name() {return m_name.c_str();}
00714     void incRef()
00715     {
00716       Guard guard(m_refcountMutex);
00717       ++m_refcount;
00718     }
00719     void decRef()
00720     {
00721       Guard guard(m_refcountMutex);
00722       --m_refcount;
00723       if (m_refcount == 0)
00724         delete this;
00725     }
00726 
00727   private:
00728     [corba.name_fq]_ptr m_obj;
00729     std::string m_name;
00730     Mutex m_refcountMutex;
00731     int m_refcount;
00732   };
00733 
00734 [for ns in local.adapter_ns]
00735 }; // namespace [ns] 
00736 [endfor]
00737 
00738 #ifndef [local.servant_include_guard] 
00739 
00740 
00741 #endif // [local.servant_include_guard]
00742 
00743 
00744 extern "C"
00745 {
00746   void [local.adapter_name]CORBAInit(coil::Properties& prop);
00747 };
00748 
00749 #endif // [local.adapter_include_guard]
00750 
00751 """
00752 
00753 
00754 adapter_cpp = """\
00755 // -*- C++ -*-
00756 /*!
00757  * @file [local.adapter_cpp] 
00758  * @brief [local.iface_name] CORBA adapter for doil
00759  * @date $Date$
00760  * @author This file was automatically generated form [idl_fname] 
00761  *         by omniidl/doil backend
00762  *
00763  * $Id$
00764  */
00765 
00766 #include <doil/ImplBase.h>
00767 #include <doil/corba/CORBAManager.h>
00768 #include <[local.iface_h_path]>
00769 #include <[local.adapter_h_path]>
00770 #include <[typeconv_h_path]>
00771 #include <doil/corba/BasicTypeConversion.h>
00772 
00773 [for ns in local.adapter_ns]
00774 namespace [ns] 
00775 {
00776 [endfor]
00777   /*!
00778    * @brief ctor
00779    */ 
00780   [local.adapter_name]::[local.adapter_name](::CORBA::Object_ptr obj)
00781    : m_obj([corba.name_fq]::_nil()),
00782      m_refcount(1)[for inc in inherits],
00783      [inc.local.adapter_name_fq](obj)[endfor]
00784 
00785   {
00786     m_obj = [corba.name_fq]::_narrow(obj);
00787     if (::CORBA::is_nil(m_obj)) throw std::bad_alloc();
00788     m_obj = [corba.name_fq]::_duplicate(m_obj);
00789   }
00790 
00791   /*!
00792    * @brief dtor
00793    */ 
00794   [local.adapter_name]::~[local.adapter_name]()
00795   {
00796     ::CORBA::release(m_obj);
00797   }
00798 
00799   [for op in operations]
00800 
00801   /*!
00802    * @brief [op.name] 
00803    */ 
00804   [op.return.local.retn_type] [local.adapter_name]::[op.name]
00805 ([for a in op.args]
00806 [if-index a is last][a.local.arg_type] [a.local.arg_name]
00807 [else][a.local.arg_type] [a.local.arg_name], [endif]
00808 [endfor])
00809       throw ([for raise in op.raises]
00810 [if-index raise is first]
00811 [raise.local.name_fq]
00812 [else]
00813 ,
00814              [raise.local.name_fq]
00815 [endif]
00816 [endfor]
00817 )
00818   {
00819     // Convert Local to CORBA.
00820     // (The direction of the argument is 'in' or 'inout'.)
00821 [for a in op.args]
00822     [a.corba.base_type] [a.corba.var_name];
00823 [endfor]
00824 [for a in op.args][if a.local.direction is "out"][else]
00825 [if-any a.corba.is_primitive]
00826     [a.corba.var_name] = [a.local.arg_name];
00827 [else]
00828 [if a.local.tk is "tk_objref"]
00829     local_to_corba(const_cast< [a.local.var_type] >([a.local.arg_name]), [a.corba.var_name]);
00830 [else]
00831     local_to_corba([a.local.arg_name], [a.corba.var_name]);
00832 [endif]
00833 [endif]
00834 [endif][endfor]
00835 
00836     // Execute the method. 
00837 [if op.return.local.tk is "tk_void"][else]
00838     [op.return.corba.retn_type] corba_ret;
00839     [op.return.local.retn_type] local_ret;
00840     corba_ret = [endif]
00841 m_obj->[op.name]
00842 ([for a in op.args][if-index a is last][a.corba.var_name][else][a.corba.var_name], [endif][endfor]);
00843 
00844     // Convert CORBA to Local.
00845     // (The direction of the argument is 'out' or 'inout'.)
00846 [for a in op.args][if a.local.direction is "in"][else]
00847 [if-any a.corba.is_primitive]
00848     [a.local.arg_name] = [a.corba.var_name];
00849 [else]
00850     corba_to_local([a.corba.var_name], [a.local.arg_name]);
00851 [endif]
00852 [endif][endfor]
00853 
00854     // Generate the return value.
00855 [if op.return.local.tk is "tk_void"][else]
00856 [if op.return.local.tk is "tk_objref"]
00857     corba_to_local(corba_ret, local_ret);
00858 [elif op.return.local.tk is "tk_enum"]
00859     corba_to_local(corba_ret, local_ret);
00860 [else]
00861 [if-any op.return.corba.is_primitive]
00862     local_ret = corba_ret;
00863 [else]
00864 [if op.return.corba.deref_tk is "tk_long"]
00865     local_ret = corba_ret;
00866 [elif op.return.corba.deref_tk is "tk_string"]
00867     corba_to_local(corba_ret, local_ret);
00868 [else]
00869     corba_to_local(*corba_ret, local_ret);
00870 [endif]
00871 [endif]
00872 [endif]
00873 [if op.return.corba.tk is "tk_any"]
00874     delete corba_ret; 
00875 [elif op.return.corba.tk is "tk_struct"]
00876     delete corba_ret; 
00877 [elif op.return.corba.tk is "tk_string"]
00878     ::CORBA::string_free(corba_ret); 
00879 [elif op.return.local.tk is "tk_objref"]
00880     ::CORBA::release(corba_ret);
00881 [elif op.return.corba.tk is "tk_alias"]
00882 [if op.return.corba.deref_tk is "tk_long"]
00883 [elif op.return.corba.deref_tk is "tk_string"]
00884     ::CORBA::string_free(corba_ret); 
00885 [else]
00886     delete corba_ret; 
00887 [endif]
00888 [endif]
00889     return local_ret;
00890 [endif]
00891   }
00892 [endfor]
00893 
00894 [for ns in local.adapter_ns]
00895 }; // namespace [ns] 
00896 [endfor]
00897 
00898 extern "C"
00899 {
00900   void [local.adapter_name]CORBAInit(coil::Properties& prop)
00901   {
00902     doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
00903     mgr.registerAdapterFactory("[local.adapter_name]",
00904                         doil::New< [local.adapter_name_fq] >,
00905                         doil::Delete< [local.adapter_name_fq] >);
00906   }
00907 };
00908 
00909 """
00910 
00911 
00912 
00913 
00914 
00915 proxy_h = """\
00916 // -*- C++ -*-
00917 /*!
00918  * @file [local.proxy_h] 
00919  * @brief [local.proxy_name] CORBA proxy for doil
00920  * @date $Date$
00921  * @author This file was automatically generated from [idl_fname] 
00922  *         by omniidl/doil backend
00923  *
00924  * $Id$
00925  */
00926 #ifndef [local.proxy_include_guard] 
00927 #define [local.proxy_include_guard] 
00928 
00929 #include <coil/Properties.h>
00930 #include <coil/Mutex.h>
00931 #include <coil/Guard.h>
00932 #include <doil/corba/CORBAManager.h>
00933 #include <doil/corba/CORBAProxyBase.h>
00934 #include <[local.iface_h]>
00935 [for inc in inherits]
00936 #include <[inc.local.proxy_h]>
00937 [endfor]
00938 [for inc in include_h]
00939 #include <[inc]>
00940 [endfor]
00941 
00942 
00943 [for ns in local.proxy_ns]
00944 namespace [ns] 
00945 {
00946 [endfor]
00947 
00948   class [local.proxy_name] 
00949   : public virtual ::doil::CORBA::CORBAProxyBase,
00950 [for inc in inherits]
00951     public virtual [inc.local.proxy_name_fq],
00952 [endfor]
00953     public virtual [local.iface_name_fq]
00954 
00955   {
00956     typedef coil::Mutex Mutex;
00957     typedef coil::Guard<Mutex> Guard;
00958   public:
00959     [local.proxy_name](::CORBA::Object_ptr obj);
00960     virtual ~[local.proxy_name]();
00961 
00962 [for op in operations]
00963     virtual [op.return.local.retn_type] [op.name]
00964 ([for a in op.args]
00965 [if-index a is last][a.local.arg_type] [a.local.arg_name]
00966 [else][a.local.arg_type] [a.local.arg_name], [endif]
00967 [endfor])
00968       throw ([for raise in op.raises]
00969 [if-index raise is first]
00970 [raise.local.name_fq]
00971 [else]
00972 ,
00973              [raise.local.name_fq]
00974 [endif]
00975 [endfor]
00976 );
00977 
00978 
00979 [endfor]
00980 
00981     const char* id() {return "[corba.idl_name]";}
00982     const char* name() {return m_name.c_str();}
00983     void incRef()
00984     {
00985       Guard guard(m_refcountMutex);
00986       ++m_refcount;
00987     }
00988     void decRef()
00989     {
00990       Guard guard(m_refcountMutex);
00991       --m_refcount;
00992       if (m_refcount == 0)
00993         delete this;
00994     }
00995 
00996   private:
00997     [corba.name_fq]_ptr m_obj;
00998   private:
00999     std::string m_name;
01000     Mutex m_refcountMutex;
01001     int m_refcount;
01002   };
01003 
01004 [for ns in local.proxy_ns]
01005 }; // namespace [ns] 
01006 [endfor]
01007 
01008 #ifndef [local.servant_include_guard] 
01009 
01010 
01011 #endif // [local.servant_include_guard]
01012 
01013 
01014 extern "C"
01015 {
01016   void [local.proxy_name]CORBAInit(coil::Properties& prop);
01017 };
01018 
01019 #endif // [local.proxy_include_guard]
01020 
01021 """
01022 
01023 
01024 proxy_cpp = """\
01025 // -*- C++ -*-
01026 /*!
01027  * @file [local.proxy_cpp] 
01028  * @brief [local.iface_name] CORBA proxy for doil
01029  * @date $Date$
01030  * @author This file was automatically generated form [idl_fname] 
01031  *         by omniidl/doil backend
01032  *
01033  * $Id$
01034  */
01035 
01036 #include <doil/corba/CORBAManager.h>
01037 #include <[local.iface_h_path]>
01038 #include <[local.proxy_h_path]>
01039 #include <[typeconv_h_path]>
01040 #include <doil/corba/BasicTypeConversion.h>
01041 
01042 [for ns in local.proxy_ns]
01043 namespace [ns] 
01044 {
01045 [endfor]
01046   /*!
01047    * @brief ctor
01048    */ 
01049   [local.proxy_name]::[local.proxy_name](::CORBA::Object_ptr obj)
01050    : m_obj([corba.name_fq]::_nil()),
01051      m_refcount(1)[for inc in inherits],
01052      [inc.local.proxy_name_fq](obj)[endfor]
01053 //   : m_obj([corba.name_fq]::_nil())[for inc in inherits],
01054 //     [inc.local.proxy_name_fq](obj)[endfor]
01055 
01056   {
01057     m_obj = [corba.name_fq]::_narrow(obj);
01058     if (::CORBA::is_nil(m_obj)) throw std::bad_alloc();
01059     m_obj = [corba.name_fq]::_duplicate(m_obj);
01060   }
01061 
01062   /*!
01063    * @brief dtor
01064    */ 
01065   [local.proxy_name]::~[local.proxy_name]()
01066   {
01067     ::CORBA::release(m_obj);
01068   }
01069 
01070   [for op in operations]
01071 
01072   /*!
01073    * @brief [op.name] 
01074    */ 
01075   [op.return.local.retn_type] [local.proxy_name]::[op.name]
01076 ([for a in op.args]
01077 [if-index a is last][a.local.arg_type] [a.local.arg_name]
01078 [else][a.local.arg_type] [a.local.arg_name], [endif]
01079 [endfor])
01080       throw ([for raise in op.raises]
01081 [if-index raise is first]
01082 [raise.local.name_fq]
01083 [else]
01084 ,
01085              [raise.local.name_fq]
01086 [endif]
01087 [endfor]
01088 )
01089   {
01090     // Convert Local to CORBA.
01091     // (The direction of the argument is 'in' or 'inout'.)
01092 [for a in op.args]
01093     [a.corba.base_type] [a.corba.var_name];
01094 [endfor]
01095 [for a in op.args][if a.local.direction is "out"][else]
01096 [if-any a.corba.is_primitive]
01097 //    [a.corba.var_name] = [a.local.arg_name];
01098     local_to_corba([a.local.arg_name], [a.corba.var_name]);
01099 [else]
01100 [if a.local.tk is "tk_objref"]
01101     local_to_corba(const_cast< [a.local.var_type] >([a.local.arg_name]), [a.corba.var_name]);
01102 [else]
01103     local_to_corba([a.local.arg_name], [a.corba.var_name]);
01104 [endif]
01105 [endif]
01106 [endif][endfor]
01107 
01108     // Execute the method. 
01109 [if op.return.local.tk is "tk_void"][else]
01110     [op.return.corba.retn_type] corba_ret;
01111     [op.return.local.retn_type] local_ret;
01112     corba_ret = [endif]
01113 m_obj->[op.name]
01114 ([for a in op.args][if-index a is last][a.corba.var_name][else][a.corba.var_name], [endif][endfor]);
01115 
01116     // Convert CORBA to Local.
01117     // (The direction of the argument is 'out' or 'inout'.)
01118 [for a in op.args][if a.local.direction is "in"][else]
01119 [if-any a.corba.is_primitive]
01120 //    [a.local.arg_name] = [a.corba.var_name];
01121     corba_to_local([a.corba.var_name], [a.local.arg_name]);
01122 [else]
01123     corba_to_local([a.corba.var_name], [a.local.arg_name]);
01124 [endif]
01125 [endif][endfor]
01126 
01127     // Generate the return value.
01128 [if op.return.local.tk is "tk_void"][else]
01129 [if op.return.local.tk is "tk_objref"]
01130     corba_to_local(corba_ret, local_ret);
01131 [elif op.return.local.tk is "tk_enum"]
01132     corba_to_local(corba_ret, local_ret);
01133 [else]
01134 [if-any op.return.corba.is_primitive]
01135 //    local_ret = corba_ret;
01136     corba_to_local(corba_ret, local_ret);
01137 [else]
01138 [if op.return.corba.deref_tk is "tk_long"]
01139 //    local_ret = corba_ret;
01140     corba_to_local(corba_ret, local_ret);
01141 [elif op.return.corba.deref_tk is "tk_string"]
01142     corba_to_local(corba_ret, local_ret);
01143 [else]
01144     corba_to_local(*corba_ret, local_ret);
01145 [endif]
01146 [endif]
01147 [endif]
01148 [if op.return.corba.tk is "tk_any"]
01149     delete corba_ret; 
01150 [elif op.return.corba.tk is "tk_struct"]
01151     delete corba_ret; 
01152 [elif op.return.corba.tk is "tk_string"]
01153     ::CORBA::string_free(corba_ret); 
01154 [elif op.return.local.tk is "tk_objref"]
01155     ::CORBA::release(corba_ret);
01156 [elif op.return.corba.tk is "tk_alias"]
01157 [if op.return.corba.deref_tk is "tk_long"]
01158 [elif op.return.corba.deref_tk is "tk_string"]
01159     ::CORBA::string_free(corba_ret); 
01160 [else]
01161     delete corba_ret; 
01162 [endif]
01163 [endif]
01164     return local_ret;
01165 [endif]
01166   }
01167 [endfor]
01168 
01169 [for ns in local.proxy_ns]
01170 }; // namespace [ns] 
01171 [endfor]
01172 
01173 extern "C"
01174 {
01175   void [local.proxy_name]CORBAInit(coil::Properties& prop)
01176   {
01177     doil::CORBA::CORBAManager& mgr(doil::CORBA::CORBAManager::instance());
01178     mgr.registerProxyFactory("[local.proxy_name]",
01179                         doil::New< [local.proxy_name_fq] >,
01180                         doil::Delete< [local.proxy_name_fq] >);
01181   }
01182 };
01183 
01184 """
01185 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17