skel_wrapper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # @file skel_wrapper.py
5 # @brief CORBA skelton/stub wrapper generator module
6 # @date $Date: 2008-03-06 06:51:10 $
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2004-2011
10 # Intelligent Systems Research Institute,
11 # National Institute of
12 # Advanced Industrial Science and Technology (AIST), Japan
13 # All rights reserved.
14 #
15 # $Id: skel_wrapper.py 2521 2014-03-03 07:47:45Z n-ando $
16 #
17 
18 import yat
19 import re
20 import sys
21 import os
22 import time
23 
24 
25 #------------------------------------------------------------
26 # Server Skelton header template
27 #------------------------------------------------------------
28 skel_h = """// -*- C++ -*-
29 /*!
30  *
31  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
32  *
33  * @file [skel_h]
34 
35  * @brief [basename] server skeleton header wrapper code
36  * @date [date]
37 
38  *
39  */
40 
41 #ifndef [skel_h_inc_guard]
42 
43 #define [skel_h_inc_guard]
44 
45 
46 
47 [config_inc]
48 
49 #if defined ORB_IS_TAO
50 # include "[include_dir][basename]C.h"
51 # include "[include_dir][basename]S.h"
52 #elif defined ORB_IS_OMNIORB
53 # if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
54 # undef USE_stub_in_nt_dll
55 # endif
56 # include "[include_dir][basename].hh"
57 #elif defined ORB_IS_MICO
58 # include "[include_dir][basename].h"
59 #elif defined ORB_IS_ORBIT2
60 # include "[include_dir]/[basename]-cpp-stubs.h"
61 # include "[include_dir]/[basename]-cpp-skels.h"
62 #elif defined ORB_IS_RTORB
63 # include "[include_dir][basename].h"
64 #else
65 # error "NO ORB defined"
66 #endif
67 
68 #endif // [skel_h_inc_guard]
69 
70 """
71 
72 
73 #------------------------------------------------------------
74 # Server Skelton source template
75 #------------------------------------------------------------
76 skel_cpp = """// -*- C++ -*-
77 /*!
78  *
79  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
80  *
81  * @file [skel_cpp]
82 
83  * @brief [basename] server skeleton wrapper
84  * @date [date]
85 
86  *
87  */
88 
89 #include "[skel_h]"
90 
91 #if defined ORB_IS_TAO
92 # include "[include_dir][basename]C.cpp"
93 # include "[include_dir][basename]S.cpp"
94 #elif defined ORB_IS_OMNIORB
95 # include "[include_dir][basename]SK.cc"
96 # include "[include_dir][basename]DynSK.cc"
97 #elif defined ORB_IS_MICO
98 # include "[include_dir][basename].cc"
99 # include "[include_dir][basename]_skel.cc"
100 #elif defined ORB_IS_ORBIT2
101 # include "[include_dir][basename]-cpp-stubs.cc"
102 # include "[include_dir][basename]-cpp-skels.cc"
103 #elif defined ORB_IS_RTORB
104 [include_openrtm_idl_decls]
105 # include "[include_dir][basename]-common.c"
106 # include "[include_dir][basename]-stubs.c"
107 # include "[include_dir][basename]-skels.c"
108 # include "[include_dir][basename]-skelimpl.c"
109 #else
110 # error "NO ORB defined"
111 #endif
112 
113 // end of [skel_cpp]
114 
115 """
116 
117 #------------------------------------------------------------
118 # Client Stub header template
119 #------------------------------------------------------------
120 stub_h = """// -*- C++ -*-
121 /*!
122  *
123  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
124  *
125  * @file [stub_h]
126 
127  * @brief [basename] client stub header wrapper code
128  * @date [date]
129 
130  *
131  */
132 
133 #ifndef [stub_h_inc_guard]
134 
135 #define [stub_h_inc_guard]
136 
137 
138 
139 [config_inc]
140 
141 #if defined ORB_IS_TAO
142 # include "[include_dir][basename]C.h"
143 #elif defined ORB_IS_OMNIORB
144 # if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
145 # undef USE_stub_in_nt_dll
146 # endif
147 # include "[include_dir][basename].hh"
148 #elif defined ORB_IS_MICO
149 # include "[include_dir][basename].h"
150 #elif defined ORB_IS_ORBIT2
151 # include "[include_dir][basename]-cpp-stubs.h"
152 #elif defined ORB_IS_RTORB
153 # include "[include_dir][basename].h"
154 #else
155 # error "NO ORB defined"
156 #endif
157 
158 #endif // [stub_h_inc_guard]
159 
160 """
161 
162 #------------------------------------------------------------
163 # Client Stub soruce template
164 #------------------------------------------------------------
165 stub_cpp = """// -*- C++ -*-
166 /*!
167  *
168  * THIS FILE IS GENERATED AUTOMATICALLY!! DO NOT EDIT!!
169  *
170  * @file [stub_cpp]
171 
172  * @brief [basename] client stub wrapper code
173  * @date [date]
174 
175  *
176  */
177 
178 #include "[stub_h]"
179 
180 #if defined ORB_IS_TAO
181 # include "[include_dir][basename]C.cpp"
182 #elif defined ORB_IS_OMNIORB
183 # include "[include_dir][basename]SK.cc"
184 # include "[include_dir][basename]DynSK.cc"
185 #elif defined ORB_IS_MICO
186 # include "[include_dir][basename].cc"
187 #elif defined ORB_IS_ORBIT2
188 # include "[include_dir][basename]-cpp-stubs.cc"
189 #elif defined ORB_IS_RTORB
190 [include_openrtm_idl_decls]
191 # include "[include_dir][basename]-common.c"
192 # include "[include_dir][basename]-stubs.c"
193 #else
194 # error "NO ORB defined"
195 #endif
196 
197 // end of [stub_cpp]
198 
199 """
200 
201 
202 config_inc = """
203 #include <[rtm_dir]config_rtc.h>
204 #undef PACKAGE_BUGREPORT
205 #undef PACKAGE_NAME
206 #undef PACKAGE_STRING
207 #undef PACKAGE_TARNAME
208 #undef PACKAGE_VERSION
209 """
210 
212  def __init__(self, idl_fname, skel_suffix = "Skel",
213  stub_suffix = "Stub", include_dir = "",
214  config_inc = "", output_dir = "./"):
215  self.data = {}
216  self.data["include_dir"] = include_dir
217  self.data["output_dir"] = output_dir
218  self.data["idl_fname"] = idl_fname
219  m = re.search("\.[iI][dD][lL]$", idl_fname)
220  if m:
221  basename = idl_fname.replace(m.group(0), "")
222  else:
223  sys.stderr.write("Invalid IDL file name specified.\n")
224  sys.exit(1)
225 
226  dirname = os.path.dirname(basename) + "/"
227  basename = os.path.basename(basename)
228  self.data["basename"] = basename
229  self.data["skel_h"] = basename + skel_suffix + ".h"
230  self.data["skel_cpp"] = basename + skel_suffix + ".cpp"
231  self.data["stub_h"] = basename + stub_suffix + ".h"
232  self.data["stub_cpp"] = basename + stub_suffix + ".cpp"
233 
234  skel_h_guard = dirname + self.data["skel_h"].replace(".","_")
235  skel_h_guard = skel_h_guard.replace("/","_")
236  skel_h_guard = skel_h_guard.upper()
237  stub_h_guard = dirname + self.data["stub_h"].replace(".","_")
238  stub_h_guard = stub_h_guard.replace("/","_")
239  stub_h_guard = stub_h_guard.upper()
240  self.data["skel_h_inc_guard"] = skel_h_guard
241  self.data["stub_h_inc_guard"] = stub_h_guard
242 
243  self.data["date"] = time.ctime()
244  self.data["config_inc"] = config_inc
245  if basename == "OpenRTM-aist" :
246  self.data["include_openrtm_idl_decls"] = ""
247  else:
248  self.data["include_openrtm_idl_decls"] = "# include \"OpenRTM-aist-decls.h\"\n"
249  return
250 
251  def gen(self, fname, temp_txt):
252  data = self.data
253  t = yat.Template(temp_txt)
254  text = t.generate(data)
255 
256  if os.access(fname, os.F_OK): # file exists
257  f = file(fname, "r")
258  oldtext = f.read()
259  f.close()
260 
261  newtext = re.sub(" \@date.*?\n", "", text)
262  oldtext2 = re.sub(" \@date.*?\n", "", oldtext)
263  if newtext == oldtext2:
264  print "\"" + fname + \
265  "\" exists and contents is same."
266  print "No need to generate the file."
267  return
268  else:
269  print "\"", fname, \
270  "\" already exists but contents are not same"
271 
272  f = file(fname, "w")
273  f.write(text)
274  f.close()
275  print "\"" + fname + "\"" " was generated."
276  return
277 
278  def print_skel_h(self):
279  fname = self.data["output_dir"] + self.data["skel_h"]
280  self.gen(fname, skel_h)
281  return
282 
283  def print_skel_cpp(self):
284  fname = self.data["output_dir"] + self.data["skel_cpp"]
285  self.gen(fname, skel_cpp)
286  return
287 
288  def print_stub_h(self):
289  fname = self.data["output_dir"] + self.data["stub_h"]
290  self.gen(fname, stub_h)
291  return
292 
293  def print_stub_cpp(self):
294  fname = self.data["output_dir"] + self.data["stub_cpp"]
295  self.gen(fname, stub_cpp)
296  return
297 
298  def print_all(self):
299  self.print_skel_h()
300  self.print_skel_cpp()
301  self.print_stub_h()
302  self.print_stub_cpp()
303  return
304 
305  def generate(self):
306  self.print_all()
307 
308 
309 if __name__ == "__main__":
310  w = skel_wrapper("Hoge.idl", "_Skel", "_Stub", "rtm/idl/", "")
311  w.generate()
def __init__(self, idl_fname, skel_suffix="Skel", stub_suffix="Stub", include_dir="", config_inc="", output_dir="./")
def gen(self, fname, temp_txt)


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