Changeset 4566
- Timestamp:
- Jul 17, 2013 8:20:50 PM (11 years ago)
- Location:
- pjproject/branches/projects/jni/pjsip-apps/src/jni
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jni/pjsip-apps/src/jni/callbacks.c.template
r4549 r4566 3 3 #include "callbacks.h" 4 4 5 /* 6 * Wrapper of pjsua_logging_config callback 7 */ 8 static PjsuaLoggingConfigCallback *pjsua_logging_config_cb = NULL; 9 10 void pjsua_logging_config_callback_proxy(int level, const char *data, int len) 11 { 12 PJ_UNUSED_ARG(len); 13 pjsua_logging_config_cb->on_log(level, data); 14 } 15 16 void setPjsuaLoggingConfigCallback(PjsuaLoggingConfigCallback *callback) 17 { 18 pjsua_logging_config_cb = callback; 19 } 20 21 22 /* 23 * Wrapper of pj_timer_heap_callback 24 */ 25 void pj_timer_heap_callback_proxy(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry) 26 { 27 PjTimerHeapCallback *cb = (PjTimerHeapCallback*)entry->user_data; 28 pj_assert(cb); 29 cb->on_timer(timer_heap, entry); 30 } 31 32 void setPjTimerHeapCallback(pj_timer_entry *entry, PjTimerHeapCallback *callback) 33 { 34 entry->user_data = callback; 35 } 36 37 38 /* 39 * Wrapper of pjsua_callback 40 */ 5 41 static PjsuaCallback* cb = NULL; 6 42 … … 15 51 }; 16 52 17 pjsua_callback* PJSUA_CALLBACK_PROXY= &my_cb_proxy;53 pjsua_callback* pjsua_callback_proxy = &my_cb_proxy; -
pjproject/branches/projects/jni/pjsip-apps/src/jni/callbacks.h.template
r4549 r4566 3 3 #include <pjsua-lib/pjsua.h> 4 4 5 /* 6 * Wrapper of pjsua_logging_config callback 7 */ 8 class PjsuaLoggingConfigCallback { 9 public: 10 virtual void on_log(int level, const char *data) {} 11 virtual ~PjsuaLoggingConfigCallback() {} 12 }; 13 5 14 #ifndef SWIG /* SWIG should ignore these */ 6 class PjsuaCallback; 7 extern void setPjsuaCallback(PjsuaCallback* callback); 8 extern pjsua_callback* PJSUA_CALLBACK_PROXY; 15 extern void pjsua_logging_config_callback_proxy(int level, const char *data, int len); 16 extern void setPjsuaLoggingConfigCallback(PjsuaLoggingConfigCallback *callback); 9 17 #endif 10 18 19 20 /* 21 * Wrapper of pj_timer_heap_callback 22 */ 23 class PjTimerHeapCallback { 24 public: 25 virtual void on_timer(pj_timer_heap_t *timer_heap, pj_timer_entry *entry) {} 26 virtual ~PjTimerHeapCallback() {} 27 }; 28 29 #ifndef SWIG /* SWIG should ignore these */ 30 extern void pj_timer_heap_callback_proxy(pj_timer_heap_t *timer_heap, pj_timer_entry *entry); 31 extern void setPjTimerHeapCallback(pj_timer_entry *entry, PjTimerHeapCallback *callback); 32 #endif 33 34 35 /* 36 * Wrapper of pjsua_callback 37 */ 11 38 class PjsuaCallback { 12 39 public: … … 14 41 virtual ~PjsuaCallback() {} 15 42 }; 43 44 #ifndef SWIG /* SWIG should ignore these */ 45 extern void setPjsuaCallback(PjsuaCallback* callback); 46 extern pjsua_callback* pjsua_callback_proxy; 47 #endif -
pjproject/branches/projects/jni/pjsip-apps/src/jni/callbacks.i
r4557 r4566 5 5 %} 6 6 7 /* 8 * Wrap pjsua_logging_config callback 9 */ 10 %feature("director") PjsuaLoggingConfigCallback; 11 %ignore pjsua_logging_config::cb; 12 %extend pjsua_logging_config { 13 void setCb(PjsuaLoggingConfigCallback* callback) { 14 setPjsuaLoggingConfigCallback(callback); 15 $self->cb = callback? &pjsua_logging_config_callback_proxy : NULL; 16 } 17 } 18 19 20 /* 21 * Wrap pj_timer_heap_callback in pj_timer_entry 22 */ 23 %feature("director") PjTimerHeapCallback; 24 %ignore pj_timer_entry::cb; 25 /* Suppress user_data, app can put user data in PjTimerHeapCallback inherited class */ 26 %ignore pj_timer_entry::user_data; 27 %extend pj_timer_entry { 28 void setCb(PjTimerHeapCallback* callback) { 29 setPjTimerHeapCallback($self, callback); 30 $self->cb = callback? &pj_timer_heap_callback_proxy : NULL; 31 } 32 } 33 34 35 /* 36 * Wrap pjsua_callback 37 */ 7 38 %feature("director") PjsuaCallback; 8 39 %ignore pjsua_callback; 9 40 %ignore pjsua_config::cb; 10 41 %extend pjsua_config { 11 void setCb(PjsuaCallback *pjsuaCb) { 12 $self->cb = *PJSUA_CALLBACK_PROXY; 13 setPjsuaCallback(pjsuaCb); 42 void setCb(PjsuaCallback *callback) { 43 setPjsuaCallback(callback); 44 if (callback) 45 $self->cb = *pjsua_callback_proxy; 46 else 47 pj_bzero(&$self->cb, sizeof($self->cb)); 14 48 } 15 49 } 16 50 51 17 52 %include <callbacks.h> 53 54 /* Ignore these callbacks */ 55 %ignore pjsip_msg_body::print_body; 56 %ignore pjsip_msg_body::clone_data; 57 %ignore pjsip_tx_data::cb; 58 %ignore pjsip_transaction::state_handler; -
pjproject/branches/projects/jni/pjsip-apps/src/jni/header.i
r4558 r4566 1 1 /* $Id$ */ 2 3 /* TODO: 4 * - fix memory leaks in pj_str_t - java String typemaps 5 * - typemap for pj_str_t as output param for callback/director, 6 * e.g: "st_text" param in pjsua_callback::on_call_replace_request() 7 * - workaround for nested struct/union, i.e: moving out inner classes to global scope 8 */ 2 9 3 10 %module (directors="1") pjsua … … 15 22 %rename("%(strip:[pjsua_])s", %$isfunction) ""; 16 23 24 /* Suppress pjsua_schedule_timer2(), app can still use pjsua_schedule_timer() */ 25 %ignore pjsua_schedule_timer2; 26 27 /* Suppress aux function pjsua_resolve_stun_servers(), usually app won't need this 28 * as app can just simply configure STUN server to use STUN. 29 */ 30 %ignore pjsua_resolve_stun_servers; 31 17 32 /* Map 'void *' simply as long, app can use this "long" as index of its real user data */ 18 33 %apply long long { void * }; … … 26 41 %apply bool { pj_bool_t }; 27 42 43 /* Map pjsua_call_dump() output buffer */ 44 %apply (char *STRING, size_t LENGTH) { (char *buffer, unsigned maxlen) }; 45 28 46 /* Map "int*" & "unsigned*" as input & output */ 29 47 %apply unsigned *INOUT { unsigned * }; … … 33 51 %apply int *INOUT { pj_stun_nat_type * }; 34 52 %apply int *INOUT { pjsip_status_code * }; 53 %apply pj_str_t *INOUT { pj_str_t *p_contact }; 54 55 /* Apply array of integer on array of enum */ 35 56 %apply int[ANY] { pjmedia_format_id dec_fmt_id[ANY] }; 36 %apply pj_str_t *INOUT { pj_str_t *p_contact };37 57 38 58 /* Handle members typed array of pj_str_t */ -
pjproject/branches/projects/jni/pjsip-apps/src/jni/hello.java
r4558 r4566 5 5 import java.io.IOException; 6 6 7 import org.pjsip.pjsua.pj_pool_t; 8 import org.pjsip.pjsua.pjsip_rx_data; 9 import org.pjsip.pjsua.pjsip_transport_type_e; 10 11 import org.pjsip.pjsua.pjsua; 12 import org.pjsip.pjsua.pjsua_acc_config; 13 import org.pjsip.pjsua.pjsua_call_info; 14 import org.pjsip.pjsua.pjsua_call_media_status; 15 import org.pjsip.pjsua.pjsua_config; 16 import org.pjsip.pjsua.pjsua_logging_config; 17 import org.pjsip.pjsua.pjsua_transport_config; 18 import org.pjsip.pjsua.PjsuaCallback; 7 import org.pjsip.pjsua.*; 8 9 class app_config { 10 public static int cur_call_id = -1; 11 } 19 12 20 13 class MyPjsuaCallback extends PjsuaCallback { … … 30 23 } 31 24 } 25 26 /* Testing pj_str_t-String map with director */ 32 27 @Override 33 28 public void on_pager(int call_id, String from, String to, String contact, String mime_type, String body) … … 44 39 /* Auto answer */ 45 40 pjsua.call_answer(call_id, 200, null, null); 46 } 47 } 41 app_config.cur_call_id = call_id; 42 } 43 } 44 45 class MyLogger extends PjsuaLoggingConfigCallback { 46 @Override 47 public void on_log(int level, String data) 48 { 49 System.out.print("LOG: " + data); 50 } 51 } 52 53 class MyTimerCallback extends PjTimerHeapCallback { 54 private int _user_data; 55 56 /* Use this class itself to store app user data */ 57 MyTimerCallback(int user_data) { _user_data = user_data; } 58 59 @Override 60 public void on_timer(pj_timer_heap_t timer_heap, pj_timer_entry entry) 61 { 62 System.out.println("======== Timer fired (user data = " + _user_data + ")"); 63 } 64 } 65 48 66 49 67 public class hello { … … 80 98 pjsua_config cfg = new pjsua_config(); 81 99 pjsua.config_default(cfg); 82 /* Setup callback */83 100 cfg.setCb(new MyPjsuaCallback()); 84 status = pjsua.init(cfg, null, null); 101 102 pjsua_logging_config log_cfg = new pjsua_logging_config(); 103 pjsua.logging_config_default(log_cfg); 104 log_cfg.setLevel(4); 105 log_cfg.setCb(new MyLogger()); 106 107 status = pjsua.init(cfg, log_cfg, null); 85 108 if (status != pjsua.PJ_SUCCESS) { 86 109 pj_error_exit("Error inintializing pjsua", status); … … 117 140 /* Make call to the URL. */ 118 141 if (false) { 119 status = pjsua.call_make_call(acc_id[0], "sip:localhost ", null, 0, null, call_id);142 status = pjsua.call_make_call(acc_id[0], "sip:localhost:6000", null, 0, null, call_id); 120 143 if (status != pjsua.PJ_SUCCESS) { 121 144 pj_error_exit("Error making call", status); 122 145 } 146 app_config.cur_call_id = call_id[0]; 147 } 148 149 /* Test timer */ 150 { 151 pj_timer_entry timer = new pj_timer_entry(); 152 timer.setCb(new MyTimerCallback(1234567890)); 153 154 pj_time_val tv = new pj_time_val(); 155 tv.setSec(0); 156 tv.setMsec(1000); 157 158 pjsua.schedule_timer(timer, tv); 123 159 } 124 160 … … 141 177 } else if (userInput.equals("h")) { 142 178 pjsua.call_hangup_all(); 179 app_config.cur_call_id = -1; 143 180 } else if (userInput.equals("c")) { 144 181 /* Test string as output param, it is wrapped as string array */ … … 154 191 } else if (userInput.equals("dd")) { 155 192 pjsua.dump(true); 193 } else if (userInput.equals("dq")) { 194 if (app_config.cur_call_id == -1) { 195 System.out.println("No active call"); 196 continue; 197 } 198 199 byte[] buf = new byte[1024*2]; 200 pjsua.call_dump(app_config.cur_call_id, true, buf, ""); 201 202 /* Build string from byte array, find null terminator first */ 203 int len = 0; 204 while (len < buf.length && buf[len] != 0) ++len; 205 String call_dump = new String(buf, 0, len); 206 207 System.out.println("Statistics of call " + app_config.cur_call_id); 208 System.out.println(call_dump); 156 209 } 157 210 } -
pjproject/branches/projects/jni/pjsip-apps/src/jni/my_typemaps.i
r4558 r4566 214 214 $1->slen = str_len; 215 215 } 216 jenv->ReleaseStringUTFChars($input, str_ptr); 216 217 } 217 218 } -
pjproject/branches/projects/jni/pjsip-apps/src/jni/swig_gen.py
r4563 r4566 13 13 #SOURCE_PATH = PJ_ROOT_PATH + "pjlib-util/include/pjlib-util/scanner.h" 14 14 #SOURCE_PATH = PJ_ROOT_PATH + "pjlib/include/pj/types.h" 15 OUTDIR = "output" if len(sys.argv)<=1 else sys.argv[1] 16 15 17 16 18 # CPP is needed by pycparser. … … 62 64 'pjsip_rx_data_op_key', 63 65 'pjsip_module', 66 'pjsip_uri', 67 'pjsip_uri_vptr', 64 68 'pjmedia_port', 65 69 'pjmedia_transport', … … 72 76 73 77 class MyGen(c_generator.CGenerator): 74 78 75 79 def __init__(self, ast): 76 80 super(MyGen, self).__init__() … … 86 90 if name and not name.startswith(BASE_PREFIX): 87 91 continue 88 92 89 93 if name in self.nodes: 90 94 self.nodes[name].append(ext) … … 94 98 else: 95 99 self.nodes[name] = [ext] 96 100 97 101 # Generate dependencies, they are all APIs to be exported 98 102 for name in self.nodes.keys(): … … 102 106 self._add_dep(name) 103 107 self.deps_frozen = True 104 108 105 109 # Override visit_IdentifierType() to collect "node name" and generate dependencies 106 110 # from this node's children … … 114 118 return False 115 119 return True 116 120 117 121 def _get_node_name(self, node): 118 122 s = getattr(node, 'name', None) … … 135 139 name in self.deps or name in self.deps_pending: 136 140 return 137 141 138 142 if name in FORCE_STRUCT_AS_OPAQUE: 139 143 self.deps.append(name) 140 144 return 141 145 142 146 self.deps_pending.append(name) 143 147 for node in self.nodes[name]: … … 147 151 sys.exit(1) 148 152 self.deps.append(name) 149 153 150 154 # Opaque struct is identified by empty struct member declaration. 151 155 def _is_struct_opaque(self, node): … … 177 181 code = code.replace('typedef enum '+name+' '+name+';\n', '', 1) 178 182 return code 179 180 def _gen_pjsua_callback(self ):183 184 def _gen_pjsua_callback(self, code): 181 185 # init 182 186 cbclass = '' … … 184 188 cbdef = [] 185 189 186 n = self.nodes['pjsua_callback'][0] 187 raw_lines = self._print_node(n).splitlines() 190 raw_lines = code.splitlines() 188 191 for idx, line in enumerate(raw_lines): 189 192 if idx in [0, 1, len(raw_lines)-1]: continue … … 208 211 fstrs[0] = m.group(1).strip() 209 212 fstrs[2] = m.group(3) 210 213 211 214 cbclass += ' virtual ' + ' '.join(fstrs) 212 215 if fstrs[0] == 'void': … … 227 230 228 231 cbdef.append(' &' + fstrs[1]) 229 230 # trail 231 232 232 233 return [cbclass, cbproxy, ',\n'.join(cbdef)+'\n'] 233 234 235 def _process_pjsua_callback(self, name, code): 236 if name != 'pjsua_callback': 237 return code 238 239 cb = self._gen_pjsua_callback(code) 240 241 fout = open(OUTDIR+'/callbacks.h', 'w+') 242 fin = open('callbacks.h.template', 'r') 243 for line in fin: 244 if line.find(r'$PJSUA_CALLBACK_CLASS$') >= 0: 245 fout.write(cb[0]) 246 else: 247 fout.write(line) 248 fin.close() 249 fout.close() 250 251 fout = open(OUTDIR+'/callbacks.c', 'w+') 252 fin = open('callbacks.c.template', 'r') 253 for line in fin: 254 if line.find(r'$PJSUA_CALLBACK_PROXY$') >= 0: 255 fout.write(cb[1]) 256 elif line.find(r'$PJSUA_CALLBACK_DEF$') >= 0: 257 fout.write(cb[2]) 258 else: 259 fout.write(line) 260 fin.close() 261 fout.close() 262 return '' 263 234 264 # Generate code from the specified node. 235 265 def _print_node(self, node): … … 248 278 for node in self.nodes[name]: 249 279 ss += self._print_node(node) 250 s += self._process_opaque_struct(name, ss) 280 281 ss = self._process_opaque_struct(name, ss) 282 ss = self._process_pjsua_callback(name, ss) 283 s += ss 251 284 return s 252 253 def write_pjsua_callback(self, outdir): 254 cb = self._gen_pjsua_callback() 255 256 fout = open(outdir+'/callbacks.h', 'w+') 257 fin = open('callbacks.h.template', 'r') 258 for line in fin: 259 if line.find(r'$PJSUA_CALLBACK_CLASS$') >= 0: 260 fout.write(cb[0]) 261 else: 262 fout.write(line) 263 fin.close() 264 fout.close() 265 266 fout = open(outdir+'/callbacks.c', 'w+') 267 fin = open('callbacks.c.template', 'r') 268 for line in fin: 269 if line.find(r'$PJSUA_CALLBACK_PROXY$') >= 0: 270 fout.write(cb[1]) 271 elif line.find(r'$PJSUA_CALLBACK_DEF$') >= 0: 272 fout.write(cb[2]) 273 else: 274 fout.write(line) 275 fin.close() 276 fout.close() 285 277 286 278 287 # MAIN … … 291 300 # print d 292 301 293 sys.argv.pop(0)294 outdir = sys.argv.pop() if len(sys.argv) else 'output'295 mygen.write_pjsua_callback(outdir)296 297 302 s = mygen.go() 298 303 print s
Note: See TracChangeset
for help on using the changeset viewer.