Changeset 972 for pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
- Timestamp:
- Feb 18, 2007 11:49:14 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.