- Timestamp:
- Jun 29, 2013 1:14:27 AM (11 years ago)
- Location:
- pjproject/branches/projects/jni/pjsip-apps/src/jni
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jni/pjsip-apps/src/jni
-
Property
svn:ignore
set to
output
yacctab.py
lextab.py
*.log
-
Property
svn:ignore
set to
-
pjproject/branches/projects/jni/pjsip-apps/src/jni/swig_gen.py
r4541 r4549 3 3 #!/usr/bin/python 4 4 5 #import re6 import sys #, os, traceback5 import re 6 import sys, os #, traceback 7 7 from collections import OrderedDict 8 8 from pycparser import parse_file, c_ast, c_generator … … 57 57 'pjmedia_transport', 58 58 'pjsua_media_transport', 59 'pjsua_callback' 59 'pjsua_callback', 60 'pjmedia_stream' 60 61 ] 61 62 62 63 FORCE_EXPORT = [ 64 'pjsip_event', 65 'pjsip_transaction', 66 'pjmedia_sdp_session', 63 67 #'pj_str' # plain export result doesn't work! 64 68 ] … … 101 105 if not self.deps_frozen: 102 106 for name in n.names: self._add_dep(name) 103 return ' '.join(n.names)107 return super(MyGen, self).visit_IdentifierType(n) 104 108 105 109 def _check_video(self, name): … … 129 133 return 130 134 131 if name in FORCE_STRUCT_AS_OPAQUE :135 if name in FORCE_STRUCT_AS_OPAQUE and (not name == 'pjsua_callback'): 132 136 self.deps.append(name) 133 137 return … … 171 175 return code 172 176 177 def _gen_pjsua_callback(self): 178 # init 179 cbclass = '' 180 cbproxy = '' 181 cbdef = [] 182 183 n = self.nodes['pjsua_callback'][0] 184 raw_lines = self._print_node(n).splitlines() 185 for idx, line in enumerate(raw_lines): 186 if idx in [0, 1, len(raw_lines)-1]: continue 187 fstrs = [] 188 # pointer to function type format 189 m = re.match('\s+(.*)\(\*(.*)\)(\(.*\));', line) 190 if m: 191 fstrs = [m.group(1).strip(), m.group(2), m.group(3)] 192 else: 193 # typedef'd format 194 m = re.match('\s+(.*)\s+(.*);', line) 195 if (not m) or (not self.nodes.has_key(m.group(1))): 196 cbdef.append(' NULL') 197 continue 198 fstrs = ['', m.group(2), ''] 199 n = self.nodes[m.group(1)][0] 200 raw = self._print_node(n) 201 m = re.match('typedef\s+(.*)\(\*(.*)\)(\(.*\));', raw) 202 if not m: 203 cbdef.append(' NULL') 204 continue 205 fstrs[0] = m.group(1).strip() 206 fstrs[2] = m.group(3) 207 208 cbclass += ' virtual ' + ' '.join(fstrs) 209 if fstrs[0] == 'void': 210 cbclass += ' {}\n' 211 elif fstrs[1] == 'on_create_media_transport': 212 cbclass += ' { return base_tp; }\n' 213 elif fstrs[1] == 'on_call_redirected': 214 cbclass += ' { return PJSIP_REDIRECT_STOP; }\n' 215 else: 216 cbclass += ' { return 0; }\n' 217 218 cbproxy += 'static ' + ' '.join(fstrs) 219 params = re.findall('(\w+)[,\)]', fstrs[2]) 220 if fstrs[0] == 'void': 221 cbproxy += ' { cb->'+fstrs[1]+'('+','.join(params)+'); }\n' 222 else: 223 cbproxy += ' { return cb->'+fstrs[1]+'('+','.join(params)+'); }\n' 224 225 cbdef.append(' &' + fstrs[1]) 226 227 # trail 228 229 return [cbclass, cbproxy, ',\n'.join(cbdef)+'\n'] 230 173 231 # Generate code from the specified node. 174 232 def _print_node(self, node): … … 189 247 s += self._process_opaque_struct(name, ss) 190 248 return s 249 250 def write_pjsua_callback(self, outdir): 251 cb = self._gen_pjsua_callback() 252 253 fout = open(outdir+'/callbacks.h', 'w+') 254 fin = open('callbacks.h.template', 'r') 255 for line in fin: 256 if line.find(r'$PJSUA_CALLBACK_CLASS$') >= 0: 257 fout.write(cb[0]) 258 else: 259 fout.write(line) 260 fin.close() 261 fout.close() 262 263 fout = open(outdir+'/callbacks.c', 'w+') 264 fin = open('callbacks.c.template', 'r') 265 for line in fin: 266 if line.find(r'$PJSUA_CALLBACK_PROXY$') >= 0: 267 fout.write(cb[1]) 268 elif line.find(r'$PJSUA_CALLBACK_DEF$') >= 0: 269 fout.write(cb[2]) 270 else: 271 fout.write(line) 272 fin.close() 273 fout.close() 191 274 192 275 # MAIN … … 205 288 # print d 206 289 290 sys.argv.pop(0) 291 outdir = sys.argv.pop() if len(sys.argv) else 'output' 292 mygen.write_pjsua_callback(outdir) 293 207 294 s = mygen.go() 208 295 print s 296
Note: See TracChangeset
for help on using the changeset viewer.