Changeset 972 for pjproject/trunk
- Timestamp:
- Feb 18, 2007 11:49:14 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/py_pjsua
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
r934 r972 37 37 g_rec_port = 0 38 38 39 # Utility: display PJ error and exit 40 # 41 def err_exit(title, rc): 42 py_pjsua.perror(THIS_FILE, title, rc) 43 exit(1) 44 45 46 # Logging function (also callback, called by pjsua-lib) 47 # 48 def log_cb(level, str, len): 49 if level <= C_LOG_LEVEL: 50 print str, 51 52 def write_log(level, str): 53 log_cb(level, str + "\n", 0) 54 55 39 56 # Utility to get call info 40 57 # … … 85 102 def on_reg_state(acc_id): 86 103 acc_info = py_pjsua.acc_get_info(acc_id) 104 if acc_info.has_registration != 0: 105 cmd = "registration" 106 else: 107 cmd = "unregistration" 87 108 if acc_info.status != 0 and acc_info.status != 200: 88 write_log(3, "Account (un)registrationfailed: rc=" + `acc_info.status` + " " + acc_info.status_text)89 else: 90 write_log(3, "Account successfully (un)registered")109 write_log(3, "Account " + cmd + " failed: rc=" + `acc_info.status` + " " + acc_info.status_text) 110 else: 111 write_log(3, "Account " + cmd + " success") 91 112 92 113 … … 123 144 write_log(3, "IM indication: " + strfrom + " " + str_t) 124 145 125 # on call transfer status146 # Received the status of previous call transfer request 126 147 # 127 148 def on_call_transfer_status(call_id,status_code,status_text,final,p_cont): … … 137 158 p_cont = 0 138 159 139 # oncall transfer request160 # Callback on incoming call transfer request 140 161 # 141 162 def on_call_transfer_request(call_id, dst, code): 142 163 write_log(3, "Call transfer request from " + `call_id` + " to " + dst + " with code " + `code`) 143 144 # Utility: display PJ error and exit145 #146 def err_exit(title, rc):147 py_pjsua.perror(THIS_FILE, title, rc)148 exit(1)149 150 151 # Logging function (also callback, called by pjsua-lib)152 #153 def log_cb(level, str, len):154 if level <= C_LOG_LEVEL:155 print str,156 157 def write_log(level, str):158 log_cb(level, str + "\n", 0)159 160 164 161 165 # … … 330 334 331 335 def conf_list(): 332 333 334 336 ports = None 335 336 337 print "Conference ports : " 337 338 339 338 ports = py_pjsua.enum_conf_ports() 340 339 … … 401 400 else: 402 401 write_log(3, "No current call") 403 402 404 403 def xfer_call(): 405 404 global g_current_call … … 507 506 508 507 508 # Print account and buddy list 509 def print_acc_buddy_list(): 510 global g_acc_id 511 512 acc_ids = py_pjsua.enum_accs() 513 print "Account list:" 514 for acc_id in acc_ids: 515 acc_info = py_pjsua.acc_get_info(acc_id) 516 if acc_info.has_registration == 0: 517 acc_status = acc_info.status_text 518 else: 519 acc_status = `acc_info.status` + "/" + acc_info.status_text + " (expires=" + `acc_info.expires` + ")" 520 521 if acc_id == g_acc_id: 522 print " *", 523 else: 524 print " ", 525 526 print "[" + `acc_id` + "] " + acc_info.acc_uri + ": " + acc_status 527 print " Presence status: ", 528 if acc_info.online_status != 0: 529 print "Online" 530 else: 531 print "Invisible" 532 533 if py_pjsua.get_buddy_count() > 0: 534 print "" 535 print "Buddy list:" 536 buddy_ids = py_pjsua.enum_buddies() 537 for buddy_id in buddy_ids: 538 bi = py_pjsua.buddy_get_info(buddy_id) 539 print " [" + `buddy_id` + "] " + bi.status_text + " " + bi.uri 540 541 509 542 # Print application menu 510 543 # 511 544 def print_menu(): 545 print "" 546 print ">>>" 547 print_acc_buddy_list() 512 548 print """ 513 549 +============================================================================+ … … 525 561 | X Xfer with Replaces | | | 526 562 | | cl List ports | d Dump status | 527 | | cc Connect port | 563 | | cc Connect port | dd Dump detail | 528 564 | | cd Disconnect port | | 529 565 | | +p Add file player | | 530 566 |------------------------------+ +r Add file recorder | | 531 567 | q Quit application | | | 532 +============================================================================+ 533 """534 print " Choice:",568 +============================================================================+""" 569 print "You have " + `py_pjsua.call_get_count()` + " active call(s)" 570 print ">>>", 535 571 536 572 # Menu … … 592 628 continue 593 629 630 bc.uri = bc.uri.replace("\n", "") 594 631 bc.subscribe = 1 595 632 status, buddy_id = py_pjsua.buddy_add(bc) … … 714 751 py_pjsua.acc_set_registration(g_acc_id, 0) 715 752 elif choice[0] == "d": 716 717 write_log(3, "Start dumping application states : ") 718 write_log(3, "Dumping invite sessions : ") 719 720 if py_pjsua.call_get_count() == 0: 721 write_log(3, " - no sessions -") 722 else: 723 for i in range(0, g_ua_cfg.max_calls): 724 if py_pjsua.call_is_active(i): 725 buf = py_pjsua.call_dump(i, 1, 1024, " ") 726 write_log(3, buf) 727 py_pjsua.pres_dump(1) 728 write_log(3, "Dump complete") 753 py_pjsua.dump(choice[1] == "d") 729 754 elif choice[0] == "a": 730 755 if g_current_call != py_pjsua.PJSUA_INVALID_ID: -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r945 r972 28 28 /* LIB BASE */ 29 29 30 static PyObject* obj_reconfigure_logging; 31 static PyObject* obj_logging_init; 30 static PyObject* obj_log_cb; 32 31 static long thread_id; 33 32 34 /* 35 * cb_reconfigure_logging 33 #define ENTER_PYTHON() PyGILState_STATE state = PyGILState_Ensure() 34 #define LEAVE_PYTHON() PyGILState_Release(state) 35 36 /* 37 * cb_log_cb 36 38 * declares method for reconfiguring logging process for callback struct 37 39 */ 38 static void cb_ reconfigure_logging(int level, const char *data, pj_size_t len)40 static void cb_log_cb(int level, const char *data, pj_size_t len) 39 41 { 40 42 41 if (PyCallable_Check(obj_reconfigure_logging))42 {43 PyObject_CallFunctionObjArgs(44 obj_reconfigure_logging, Py_BuildValue("i",level),45 PyString_FromString(data), Py_BuildValue("i",len), NULL46 );47 }48 }49 50 51 /*52 * cb_logging_init53 * declares method logging_init for callback struct54 */55 static void cb_logging_init(int level, const char *data, pj_size_t len)56 {57 43 /* Ignore if this callback is called from alien thread context, 58 44 * or otherwise it will crash Python. … … 61 47 return; 62 48 63 if (PyCallable_Check(obj_logging_init)) 64 { 65 49 if (PyCallable_Check(obj_log_cb)) 50 { 51 ENTER_PYTHON(); 52 66 53 PyObject_CallFunctionObjArgs( 67 obj_log ging_init, Py_BuildValue("i",level),54 obj_log_cb, Py_BuildValue("i",level), 68 55 PyString_FromString(data), Py_BuildValue("i",len), NULL 69 56 ); 57 58 LEAVE_PYTHON(); 70 59 } 71 60 } … … 196 185 { 197 186 pjsip_event_Object * obj; 198 199 obj = 200 (pjsip_event_Object *)PyType_GenericNew(&pjsip_event_Type, 201 NULL, NULL); 187 188 ENTER_PYTHON(); 189 190 obj = (pjsip_event_Object *)PyType_GenericNew(&pjsip_event_Type, 191 NULL, NULL); 202 192 203 193 obj->event = e; … … 206 196 g_obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL 207 197 ); 208 198 199 LEAVE_PYTHON(); 209 200 } 210 201 } … … 220 211 if (PyCallable_Check(g_obj_callback->on_incoming_call)) 221 212 { 222 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) 223 PyType_GenericNew(&pjsip_rx_data_Type, 213 pjsip_rx_data_Object * obj; 214 215 ENTER_PYTHON(); 216 217 obj = (pjsip_rx_data_Object *)PyType_GenericNew(&pjsip_rx_data_Type, 224 218 NULL, NULL); 225 219 obj->rdata = rdata; … … 232 226 NULL 233 227 ); 228 229 LEAVE_PYTHON(); 234 230 } 235 231 } … … 244 240 if (PyCallable_Check(g_obj_callback->on_call_media_state)) 245 241 { 242 ENTER_PYTHON(); 243 246 244 PyObject_CallFunction(g_obj_callback->on_call_media_state,"i",call_id); 245 246 LEAVE_PYTHON(); 247 247 } 248 248 } … … 257 257 pjsip_status_code *code) 258 258 { 259 PyObject * ret;260 int cd;261 259 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) 262 260 { 261 PyObject * ret; 262 int cd; 263 264 ENTER_PYTHON(); 265 263 266 ret = PyObject_CallFunctionObjArgs( 264 267 g_obj_callback->on_call_transfer_request, … … 275 278 } 276 279 } 280 281 LEAVE_PYTHON(); 277 282 } 278 283 } … … 292 297 pj_bool_t *p_cont) 293 298 { 294 PyObject * ret;295 int cnt;296 299 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) 297 300 { 301 PyObject * ret; 302 int cnt; 303 304 ENTER_PYTHON(); 305 298 306 ret = PyObject_CallFunctionObjArgs( 299 307 g_obj_callback->on_call_transfer_status, … … 312 320 } 313 321 } 322 323 LEAVE_PYTHON(); 314 324 } 315 325 } … … 326 336 pj_str_t *st_text) 327 337 { 328 PyObject * ret;329 PyObject * txt;330 int cd;331 338 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) 332 339 { 333 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) 334 PyType_GenericNew(&pjsip_rx_data_Type, 340 PyObject * ret; 341 PyObject * txt; 342 int cd; 343 pjsip_rx_data_Object * obj; 344 345 ENTER_PYTHON(); 346 347 obj = (pjsip_rx_data_Object *)PyType_GenericNew(&pjsip_rx_data_Type, 335 348 NULL, NULL); 336 349 obj->rdata = rdata; … … 353 366 } 354 367 } 368 369 LEAVE_PYTHON(); 355 370 } 356 371 } … … 367 382 if (PyCallable_Check(g_obj_callback->on_call_replaced)) 368 383 { 384 ENTER_PYTHON(); 385 369 386 PyObject_CallFunctionObjArgs( 370 387 g_obj_callback->on_call_replaced, … … 373 390 NULL 374 391 ); 392 393 LEAVE_PYTHON(); 375 394 } 376 395 } … … 385 404 if (PyCallable_Check(g_obj_callback->on_reg_state)) 386 405 { 406 ENTER_PYTHON(); 407 387 408 PyObject_CallFunction(g_obj_callback->on_reg_state,"i",acc_id); 409 410 LEAVE_PYTHON(); 388 411 } 389 412 } … … 398 421 if (PyCallable_Check(g_obj_callback->on_buddy_state)) 399 422 { 423 ENTER_PYTHON(); 424 400 425 PyObject_CallFunction(g_obj_callback->on_buddy_state,"i",buddy_id); 426 427 LEAVE_PYTHON(); 401 428 } 402 429 } … … 412 439 if (PyCallable_Check(g_obj_callback->on_pager)) 413 440 { 441 ENTER_PYTHON(); 442 414 443 PyObject_CallFunctionObjArgs( 415 444 g_obj_callback->on_pager,Py_BuildValue("i",call_id), … … 420 449 PyString_FromStringAndSize(body->ptr, body->slen), NULL 421 450 ); 451 452 LEAVE_PYTHON(); 422 453 } 423 454 } … … 433 464 const pj_str_t *reason) 434 465 { 435 436 PyObject * obj = PyType_GenericNew(user_data, NULL, NULL);437 466 if (PyCallable_Check(g_obj_callback->on_pager)) 438 467 { 468 PyObject * obj_user_data; 469 470 ENTER_PYTHON(); 471 472 obj_user_data = Py_BuildValue("i", user_data); 473 439 474 PyObject_CallFunctionObjArgs( 440 g_obj_callback->on_pager,Py_BuildValue("i",call_id), 475 g_obj_callback->on_pager_status, 476 Py_BuildValue("i",call_id), 441 477 PyString_FromStringAndSize(to->ptr, to->slen), 442 PyString_FromStringAndSize(body->ptr, body->slen),obj, 443 Py_BuildValue("i",status),PyString_FromStringAndSize(reason->ptr, 444 reason->slen),NULL 478 PyString_FromStringAndSize(body->ptr, body->slen), 479 obj_user_data, 480 Py_BuildValue("i",status), 481 PyString_FromStringAndSize(reason->ptr,reason->slen), 482 NULL 445 483 ); 484 485 LEAVE_PYTHON(); 446 486 } 447 487 } … … 458 498 if (PyCallable_Check(g_obj_callback->on_typing)) 459 499 { 500 ENTER_PYTHON(); 501 460 502 PyObject_CallFunctionObjArgs( 461 503 g_obj_callback->on_typing,Py_BuildValue("i",call_id), … … 465 507 Py_BuildValue("i",is_typing),NULL 466 508 ); 509 510 LEAVE_PYTHON(); 467 511 } 468 512 } … … 1300 1344 void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list) 1301 1345 { 1302 int i;1346 pj_list_init(hdr); 1303 1347 1304 1348 if (PyList_Check(py_hdr_list)) { 1305 pj_list_init(hdr);1349 int i; 1306 1350 1307 1351 for (i = 0; i < PyList_Size(py_hdr_list); i++) … … 1867 1911 cfg.log_filename.ptr = PyString_AsString(log->log_filename); 1868 1912 cfg.log_filename.slen = strlen(cfg.log_filename.ptr); 1869 Py_XDECREF(obj_ reconfigure_logging);1870 obj_ reconfigure_logging= log->cb;1871 Py_INCREF(obj_ reconfigure_logging);1872 cfg.cb = &cb_ reconfigure_logging;1913 Py_XDECREF(obj_log_cb); 1914 obj_log_cb = log->cb; 1915 Py_INCREF(obj_log_cb); 1916 cfg.cb = &cb_log_cb; 1873 1917 status = pjsua_reconfigure_logging(&cfg); 1874 1918 } else { … … 2087 2131 cfg_log.log_filename.ptr = PyString_AsString(log_cfg->log_filename); 2088 2132 cfg_log.log_filename.slen = strlen(cfg_log.log_filename.ptr); 2089 Py_XDECREF(obj_log ging_init);2090 obj_log ging_init= log_cfg->cb;2091 Py_INCREF(obj_log ging_init);2092 cfg_log.cb = &cb_log ging_init;2133 Py_XDECREF(obj_log_cb); 2134 obj_log_cb = log_cfg->cb; 2135 Py_INCREF(obj_log_cb); 2136 cfg_log.cb = &cb_log_cb; 2093 2137 p_cfg_log = &cfg_log; 2094 2138 } else { … … 7863 7907 } 7864 7908 7909 7910 /* 7911 * py_pjsua_dump 7912 * Dump application states. 7913 */ 7914 static PyObject *py_pjsua_dump(PyObject *pSelf, PyObject *pArgs) 7915 { 7916 unsigned old_decor; 7917 char buf[1024]; 7918 int detail; 7919 7920 if (!PyArg_ParseTuple(pArgs, "i", &detail)) 7921 { 7922 return NULL; 7923 } 7924 7925 PJ_LOG(3,(THIS_FILE, "Start dumping application states:")); 7926 7927 old_decor = pj_log_get_decor(); 7928 pj_log_set_decor(old_decor & (PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR)); 7929 7930 if (detail) 7931 pj_dump_config(); 7932 7933 pjsip_endpt_dump(pjsua_get_pjsip_endpt(), detail); 7934 pjmedia_endpt_dump(pjsua_get_pjmedia_endpt()); 7935 pjsip_tsx_layer_dump(detail); 7936 pjsip_ua_dump(detail); 7937 7938 7939 /* Dump all invite sessions: */ 7940 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:")); 7941 7942 if (pjsua_call_get_count() == 0) { 7943 7944 PJ_LOG(3,(THIS_FILE, " - no sessions -")); 7945 7946 } else { 7947 unsigned i, max; 7948 7949 max = pjsua_call_get_max_count(); 7950 for (i=0; i<max; ++i) { 7951 if (pjsua_call_is_active(i)) { 7952 pjsua_call_dump(i, detail, buf, sizeof(buf), " "); 7953 PJ_LOG(3,(THIS_FILE, "%s", buf)); 7954 } 7955 } 7956 } 7957 7958 /* Dump presence status */ 7959 pjsua_pres_dump(detail); 7960 7961 pj_log_set_decor(old_decor); 7962 PJ_LOG(3,(THIS_FILE, "Dump complete")); 7963 7964 Py_INCREF(Py_None); 7965 return Py_None; 7966 } 7967 7968 7865 7969 static char pjsua_call_get_max_count_doc[] = 7866 7970 "int py_pjsua.call_get_max_count () " … … 8356 8460 pjsua_call_dump_doc 8357 8461 }, 8358 8462 { 8463 "dump", py_pjsua_dump, METH_VARARGS, "Dump application state" 8464 }, 8359 8465 8360 8466 … … 8374 8480 8375 8481 8482 PyEval_InitThreads(); 8483 8376 8484 if (PyType_Ready(&callback_Type) < 0) 8377 8485 return;
Note: See TracChangeset
for help on using the changeset viewer.