skel_wrapper.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #
00004 #  @file skel_wrapper.py
00005 #  @brief CORBA skelton/stub wrapper generator module
00006 #  @date $Date: 2008-03-06 06:51:10 $
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2004-2011
00010 #      Intelligent Systems Research Institute,
00011 #      National Institute of
00012 #          Advanced Industrial Science and Technology (AIST), Japan
00013 #      All rights reserved.
00014 # 
00015 #  $Id: skel_wrapper.py 2521 2014-03-03 07:47:45Z n-ando $
00016 # 
00017 
00018 import yat
00019 import re
00020 import sys
00021 import os
00022 import time
00023 
00024 
00025 #------------------------------------------------------------
00026 # Server Skelton header template
00027 #------------------------------------------------------------
00028 skel_h = """// -*- C++ -*-
00029 /*!
00030  *
00031  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
00032  *
00033  * @file [skel_h]
00034  
00035  * @brief [basename] server skeleton header wrapper code
00036  * @date [date]
00037  
00038  *
00039  */
00040 
00041 #ifndef [skel_h_inc_guard]
00042 
00043 #define [skel_h_inc_guard]
00044 
00045 
00046 
00047 [config_inc]
00048 
00049 #if   defined ORB_IS_TAO
00050 #  include "[include_dir][basename]C.h"
00051 #  include "[include_dir][basename]S.h"
00052 #elif defined ORB_IS_OMNIORB
00053 #  if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
00054 #    undef USE_stub_in_nt_dll
00055 #  endif
00056 #  include "[include_dir][basename].hh"
00057 #elif defined ORB_IS_MICO
00058 #  include "[include_dir][basename].h"
00059 #elif defined ORB_IS_ORBIT2
00060 #  include "[include_dir]/[basename]-cpp-stubs.h"
00061 #  include "[include_dir]/[basename]-cpp-skels.h"
00062 #elif defined ORB_IS_RTORB
00063 #  include "[include_dir][basename].h"
00064 #else
00065 #  error "NO ORB defined"
00066 #endif
00067 
00068 #endif // [skel_h_inc_guard]
00069 
00070 """
00071 
00072 
00073 #------------------------------------------------------------
00074 # Server Skelton source template
00075 #------------------------------------------------------------
00076 skel_cpp = """// -*- C++ -*-
00077 /*!
00078  *
00079  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
00080  *
00081  * @file [skel_cpp]
00082  
00083  * @brief [basename] server skeleton wrapper
00084  * @date [date]
00085  
00086  *
00087  */
00088 
00089 #include "[skel_h]"
00090 
00091 #if defined ORB_IS_TAO
00092 #  include "[include_dir][basename]C.cpp"
00093 #  include "[include_dir][basename]S.cpp"
00094 #elif defined ORB_IS_OMNIORB
00095 #  include "[include_dir][basename]SK.cc"
00096 #  include "[include_dir][basename]DynSK.cc"
00097 #elif defined ORB_IS_MICO
00098 #  include "[include_dir][basename].cc"
00099 #  include "[include_dir][basename]_skel.cc"
00100 #elif defined ORB_IS_ORBIT2
00101 #  include "[include_dir][basename]-cpp-stubs.cc"
00102 #  include "[include_dir][basename]-cpp-skels.cc"
00103 #elif defined ORB_IS_RTORB
00104 [include_openrtm_idl_decls]
00105 #  include "[include_dir][basename]-common.c"
00106 #  include "[include_dir][basename]-stubs.c"
00107 #  include "[include_dir][basename]-skels.c"
00108 #  include "[include_dir][basename]-skelimpl.c"
00109 #else
00110 #  error "NO ORB defined"
00111 #endif
00112 
00113 // end of [skel_cpp]
00114 
00115 """
00116 
00117 #------------------------------------------------------------
00118 # Client Stub header template
00119 #------------------------------------------------------------
00120 stub_h = """// -*- C++ -*-
00121 /*!
00122  *
00123  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
00124  *
00125  * @file [stub_h]
00126  
00127  * @brief [basename] client stub header wrapper code
00128  * @date [date]
00129  
00130  *
00131  */
00132 
00133 #ifndef [stub_h_inc_guard]
00134 
00135 #define [stub_h_inc_guard]
00136 
00137 
00138 
00139 [config_inc]
00140 
00141 #if   defined ORB_IS_TAO
00142 #  include "[include_dir][basename]C.h"
00143 #elif defined ORB_IS_OMNIORB
00144 #  if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
00145 #    undef USE_stub_in_nt_dll
00146 #  endif
00147 #  include "[include_dir][basename].hh"
00148 #elif defined ORB_IS_MICO
00149 #  include "[include_dir][basename].h"
00150 #elif defined ORB_IS_ORBIT2
00151 #  include "[include_dir][basename]-cpp-stubs.h"
00152 #elif defined ORB_IS_RTORB
00153 #  include "[include_dir][basename].h"
00154 #else
00155 #  error "NO ORB defined"
00156 #endif
00157 
00158 #endif // [stub_h_inc_guard]
00159 
00160 """
00161  
00162 #------------------------------------------------------------
00163 # Client Stub soruce template
00164 #------------------------------------------------------------
00165 stub_cpp = """// -*- C++ -*-
00166 /*!
00167  *
00168  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
00169  *
00170  * @file [stub_cpp]
00171  
00172  * @brief [basename] client stub wrapper code
00173  * @date [date]
00174  
00175  *
00176  */
00177 
00178 #include "[stub_h]"
00179 
00180 #if   defined ORB_IS_TAO
00181 #  include "[include_dir][basename]C.cpp"
00182 #elif defined ORB_IS_OMNIORB
00183 #  include "[include_dir][basename]SK.cc"
00184 #  include "[include_dir][basename]DynSK.cc"
00185 #elif defined ORB_IS_MICO
00186 #  include "[include_dir][basename].cc"
00187 #elif defined ORB_IS_ORBIT2
00188 #  include "[include_dir][basename]-cpp-stubs.cc"
00189 #elif defined ORB_IS_RTORB
00190 [include_openrtm_idl_decls]
00191 #  include "[include_dir][basename]-common.c"
00192 #  include "[include_dir][basename]-stubs.c"
00193 #else
00194 #  error "NO ORB defined"
00195 #endif
00196 
00197 // end of [stub_cpp]
00198 
00199 """
00200 
00201 
00202 config_inc = """
00203 #include <[rtm_dir]config_rtc.h>
00204 #undef PACKAGE_BUGREPORT
00205 #undef PACKAGE_NAME
00206 #undef PACKAGE_STRING
00207 #undef PACKAGE_TARNAME
00208 #undef PACKAGE_VERSION
00209 """
00210 
00211 class skel_wrapper:
00212         def __init__(self, idl_fname, skel_suffix = "Skel",
00213                      stub_suffix = "Stub", include_dir = "",
00214                      config_inc = "", output_dir = "./"):
00215                 self.data = {}
00216                 self.data["include_dir"] = include_dir
00217                 self.data["output_dir"] = output_dir
00218                 self.data["idl_fname"] = idl_fname
00219                 m = re.search("\.[iI][dD][lL]$", idl_fname)
00220                 if m:
00221                         basename = idl_fname.replace(m.group(0), "")
00222                 else:
00223                         sys.stderr.write("Invalid IDL file name specified.\n")
00224                         sys.exit(1)
00225                         
00226                 dirname  = os.path.dirname(basename) + "/"
00227                 basename = os.path.basename(basename)
00228                 self.data["basename"] = basename
00229                 self.data["skel_h"]   = basename + skel_suffix + ".h"
00230                 self.data["skel_cpp"] = basename + skel_suffix + ".cpp"
00231                 self.data["stub_h"]   = basename + stub_suffix + ".h"
00232                 self.data["stub_cpp"] = basename + stub_suffix + ".cpp"
00233 
00234                 skel_h_guard = dirname + self.data["skel_h"].replace(".","_")
00235                 skel_h_guard = skel_h_guard.replace("/","_")
00236                 skel_h_guard = skel_h_guard.upper()
00237                 stub_h_guard = dirname + self.data["stub_h"].replace(".","_")
00238                 stub_h_guard = stub_h_guard.replace("/","_")
00239                 stub_h_guard = stub_h_guard.upper()
00240                 self.data["skel_h_inc_guard"] = skel_h_guard
00241                 self.data["stub_h_inc_guard"] = stub_h_guard
00242                 
00243                 self.data["date"] = time.ctime()
00244                 self.data["config_inc"] = config_inc
00245                 if basename == "OpenRTM-aist" :
00246                         self.data["include_openrtm_idl_decls"] = ""
00247                 else:
00248                         self.data["include_openrtm_idl_decls"] = "#  include \"OpenRTM-aist-decls.h\"\n"
00249                 return
00250 
00251         def gen(self, fname, temp_txt):
00252                 data = self.data
00253                 t = yat.Template(temp_txt)
00254                 text = t.generate(data)
00255 
00256                 if os.access(fname, os.F_OK): # file exists
00257                         f = file(fname, "r")
00258                         oldtext = f.read()
00259                         f.close()
00260 
00261                         newtext = re.sub(" \@date.*?\n", "", text)
00262                         oldtext2 = re.sub(" \@date.*?\n", "", oldtext)
00263                         if newtext == oldtext2:
00264                                 print "\"" + fname + \
00265                             "\" exists and contents is same."
00266                                 print "No need to generate the file."
00267                                 return
00268                         else:
00269                                 print "\"", fname, \
00270                             "\" already exists but contents are not same"
00271 
00272                 f = file(fname, "w")
00273                 f.write(text)
00274                 f.close()
00275                 print "\"" + fname + "\"" " was generated."
00276                 return
00277 
00278         def print_skel_h(self):
00279                 fname = self.data["output_dir"] + self.data["skel_h"]
00280                 self.gen(fname, skel_h)
00281                 return
00282 
00283         def print_skel_cpp(self):
00284                 fname = self.data["output_dir"] + self.data["skel_cpp"]
00285                 self.gen(fname, skel_cpp)
00286                 return
00287 
00288         def print_stub_h(self):
00289                 fname = self.data["output_dir"] + self.data["stub_h"]
00290                 self.gen(fname, stub_h)
00291                 return
00292 
00293         def print_stub_cpp(self):
00294                 fname = self.data["output_dir"] + self.data["stub_cpp"]
00295                 self.gen(fname, stub_cpp)
00296                 return
00297 
00298         def print_all(self):
00299                 self.print_skel_h()
00300                 self.print_skel_cpp()
00301                 self.print_stub_h()
00302                 self.print_stub_cpp()
00303                 return
00304 
00305         def generate(self):
00306                 self.print_all()
00307 
00308 
00309 if __name__ == "__main__":
00310         w = skel_wrapper("Hoge.idl", "_Skel", "_Stub", "rtm/idl/", "")
00311         w.generate()


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