Ignore:
Timestamp:
Feb 18, 2007 11:49:14 PM (17 years ago)
Author:
bennylp
Message:

Fixed various bugs in Python module

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py

    r934 r972  
    3737g_rec_port = 0 
    3838 
     39# Utility: display PJ error and exit 
     40# 
     41def 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# 
     48def log_cb(level, str, len): 
     49    if level <= C_LOG_LEVEL: 
     50        print str, 
     51 
     52def write_log(level, str): 
     53    log_cb(level, str + "\n", 0) 
     54 
     55 
    3956# Utility to get call info 
    4057# 
     
    85102def on_reg_state(acc_id): 
    86103        acc_info = py_pjsua.acc_get_info(acc_id) 
     104        if acc_info.has_registration != 0: 
     105                cmd = "registration" 
     106        else: 
     107                cmd = "unregistration" 
    87108        if acc_info.status != 0 and acc_info.status != 200: 
    88                 write_log(3, "Account (un)registration failed: 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") 
    91112 
    92113 
     
    123144        write_log(3, "IM indication: " + strfrom + " " + str_t) 
    124145 
    125 # on call transfer status 
     146# Received the status of previous call transfer request 
    126147# 
    127148def on_call_transfer_status(call_id,status_code,status_text,final,p_cont): 
     
    137158                p_cont = 0 
    138159 
    139 # on call transfer request 
     160# Callback on incoming call transfer request 
    140161#                
    141162def on_call_transfer_request(call_id, dst, code): 
    142163        write_log(3, "Call transfer request from " + `call_id` + " to " + dst + " with code " + `code`) 
    143  
    144 # Utility: display PJ error and exit 
    145 # 
    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  
    160164 
    161165# 
     
    330334 
    331335def conf_list(): 
    332          
    333          
    334336        ports = None 
    335  
    336337        print "Conference ports : " 
    337  
    338          
    339338        ports = py_pjsua.enum_conf_ports() 
    340339 
     
    401400        else: 
    402401                write_log(3, "No current call") 
    403                  
     402 
    404403def xfer_call(): 
    405404        global g_current_call 
     
    507506 
    508507 
     508# Print account and buddy list 
     509def 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                 
    509542# Print application menu 
    510543# 
    511544def print_menu(): 
     545        print "" 
     546        print ">>>" 
     547        print_acc_buddy_list() 
    512548        print """ 
    513549+============================================================================+ 
     
    525561|  X  Xfer with Replaces       |                          |                  | 
    526562|                              | cl  List ports           |  d  Dump status  | 
    527 |                              | cc  Connect port         |                  | 
     563|                              | cc  Connect port         | dd  Dump detail  | 
    528564|                              | cd  Disconnect port      |                  | 
    529565|                              | +p  Add file player      |                  | 
    530566|------------------------------+ +r  Add file recorder    |                  | 
    531567|  q  Quit application         |                          |                  | 
    532 +============================================================================+ 
    533         """ 
    534         print "Choice: ",  
     568+============================================================================+""" 
     569        print "You have " + `py_pjsua.call_get_count()` + " active call(s)" 
     570        print ">>>",  
    535571 
    536572# Menu 
     
    592628                                continue 
    593629             
     630                        bc.uri = bc.uri.replace("\n", "") 
    594631                        bc.subscribe = 1 
    595632                        status, buddy_id = py_pjsua.buddy_add(bc) 
     
    714751                                py_pjsua.acc_set_registration(g_acc_id, 0) 
    715752                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") 
    729754                elif choice[0] == "a": 
    730755                        if g_current_call != py_pjsua.PJSUA_INVALID_ID:                          
Note: See TracChangeset for help on using the changeset viewer.