Ignore:
Timestamp:
May 3, 2007 1:31:21 PM (17 years ago)
Author:
bennylp
Message:

Implemented ticket #246, #247, #261, #268, #250 for Symbian

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp

    r1245 r1246  
    4545 
    4646// 
     47// Destination URI (to make call, or to subscribe presence) 
     48// 
     49#define SIP_DST_URI     "sip:192.168.0.70:5061" 
     50 
     51// 
    4752// Account 
    4853// 
     
    5964 
    6065 
     66// 
     67// Globals 
     68// 
     69static pjsua_acc_id g_acc_id = PJSUA_INVALID_ID; 
     70static pjsua_call_id g_call_id = PJSUA_INVALID_ID; 
     71static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID; 
    6172 
    6273 
     
    7081    PJ_UNUSED_ARG(rdata); 
    7182 
     83    if (g_call_id != PJSUA_INVALID_ID) { 
     84        pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL); 
     85        return; 
     86    } 
     87     
    7288    pjsua_call_get_info(call_id, &ci); 
    7389 
     
    7692                         ci.remote_info.ptr)); 
    7793 
     94    g_call_id = call_id; 
     95     
    7896    /* Automatically answer incoming calls with 200/OK */ 
    7997    pjsua_call_answer(call_id, 200, NULL, NULL); 
     
    88106 
    89107    pjsua_call_get_info(call_id, &ci); 
     108     
     109    if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { 
     110        if (call_id == g_call_id) 
     111            g_call_id = PJSUA_INVALID_ID; 
     112    } else { 
     113        if (g_call_id == PJSUA_INVALID_ID) 
     114            g_call_id = call_id; 
     115    } 
     116     
    90117    PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, 
    91118                         (int)ci.state_text.slen, 
     
    108135 
    109136 
     137/* Handler on buddy state changed. */ 
     138static void on_buddy_state(pjsua_buddy_id buddy_id) 
     139{ 
     140    pjsua_buddy_info info; 
     141    pjsua_buddy_get_info(buddy_id, &info); 
     142 
     143    PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", 
     144              (int)info.uri.slen, 
     145              info.uri.ptr, 
     146              (int)info.status_text.slen, 
     147              info.status_text.ptr)); 
     148} 
     149 
     150 
     151/* Incoming IM message (i.e. MESSAGE request)!  */ 
     152static void on_pager(pjsua_call_id call_id, const pj_str_t *from,  
     153                     const pj_str_t *to, const pj_str_t *contact, 
     154                     const pj_str_t *mime_type, const pj_str_t *text) 
     155{ 
     156    /* Note: call index may be -1 */ 
     157    PJ_UNUSED_ARG(call_id); 
     158    PJ_UNUSED_ARG(to); 
     159    PJ_UNUSED_ARG(contact); 
     160    PJ_UNUSED_ARG(mime_type); 
     161 
     162    PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s", 
     163              (int)from->slen, from->ptr, 
     164              (int)text->slen, text->ptr)); 
     165} 
     166 
     167 
     168/* Received typing indication  */ 
     169static void on_typing(pjsua_call_id call_id, const pj_str_t *from, 
     170                      const pj_str_t *to, const pj_str_t *contact, 
     171                      pj_bool_t is_typing) 
     172{ 
     173    PJ_UNUSED_ARG(call_id); 
     174    PJ_UNUSED_ARG(to); 
     175    PJ_UNUSED_ARG(contact); 
     176 
     177    PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s", 
     178              (int)from->slen, from->ptr, 
     179              (is_typing?"is typing..":"has stopped typing"))); 
     180} 
     181 
     182 
     183/* Call transfer request status. */ 
     184static void on_call_transfer_status(pjsua_call_id call_id, 
     185                                    int status_code, 
     186                                    const pj_str_t *status_text, 
     187                                    pj_bool_t final, 
     188                                    pj_bool_t *p_cont) 
     189{ 
     190    PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s", 
     191              call_id, status_code, 
     192              (int)status_text->slen, status_text->ptr, 
     193              (final ? "[final]" : ""))); 
     194 
     195    if (status_code/100 == 2) { 
     196        PJ_LOG(3,(THIS_FILE,  
     197                  "Call %d: call transfered successfully, disconnecting call", 
     198                  call_id)); 
     199        pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL); 
     200        *p_cont = PJ_FALSE; 
     201    } 
     202} 
     203 
     204 
     205/* Notification that call is being replaced. */ 
     206static void on_call_replaced(pjsua_call_id old_call_id, 
     207                             pjsua_call_id new_call_id) 
     208{ 
     209    pjsua_call_info old_ci, new_ci; 
     210 
     211    pjsua_call_get_info(old_call_id, &old_ci); 
     212    pjsua_call_get_info(new_call_id, &new_ci); 
     213 
     214    PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by " 
     215                         "call %d with %.*s", 
     216                         old_call_id,  
     217                         (int)old_ci.remote_info.slen, old_ci.remote_info.ptr, 
     218                         new_call_id, 
     219                         (int)new_ci.remote_info.slen, new_ci.remote_info.ptr)); 
     220} 
     221 
     222 
    110223/* Logging callback */ 
    111224static void log_writer(int level, const char *buf, unsigned len) 
     
    126239 * url may contain URL to call. 
    127240 */ 
    128 static pj_status_t app_startup(char *url) 
    129 { 
    130     pjsua_acc_id acc_id = 0; 
     241static pj_status_t app_startup() 
     242{ 
    131243    pj_status_t status; 
    132244 
     
    139251        pjsua_perror(THIS_FILE, "pjsua_create() error", status); 
    140252        return status; 
    141     } 
    142  
    143     /* If argument is specified, it's got to be a valid SIP URL */ 
    144     if (url) { 
    145         status = pjsua_verify_sip_url(url); 
    146         if (status != PJ_SUCCESS) { 
    147                 pjsua_perror(THIS_FILE, "Invalid URL", status); 
    148                 return status; 
    149         } 
    150253    } 
    151254 
     
    162265        cfg.cb.on_call_media_state = &on_call_media_state; 
    163266        cfg.cb.on_call_state = &on_call_state; 
     267        cfg.cb.on_buddy_state = &on_buddy_state; 
     268        cfg.cb.on_pager = &on_pager; 
     269        cfg.cb.on_typing = &on_typing; 
     270        cfg.cb.on_call_transfer_status = &on_call_transfer_status; 
     271        cfg.cb.on_call_replaced = &on_call_replaced; 
    164272 
    165273        if (SIP_PROXY) { 
     
    200308        } 
    201309         
    202         pjsua_acc_add_local(tid, PJ_TRUE, &acc_id); 
     310        pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id); 
    203311    } 
    204312 
     
    225333        cfg.cred_info[0].data = pj_str(SIP_PASSWD); 
    226334 
    227         status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id); 
     335        status = pjsua_acc_add(&cfg, PJ_TRUE, &g_acc_id); 
    228336        if (status != PJ_SUCCESS) { 
    229337                pjsua_perror(THIS_FILE, "Error adding account", status); 
     
    233341    } 
    234342 
    235     /* If URL is specified, make call to the URL. */ 
    236     if (url != NULL) { 
    237         pj_str_t uri = pj_str(url); 
    238         status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL); 
    239         if (status != PJ_SUCCESS) { 
    240                 pjsua_perror(THIS_FILE, "Error making call", status); 
    241                 pjsua_destroy(); 
    242                 return status; 
    243         } 
    244                          
    245     } 
    246  
     343    if (SIP_DST_URI) { 
     344        pjsua_buddy_config bcfg; 
     345     
     346        pjsua_buddy_config_default(&bcfg); 
     347        bcfg.uri = pj_str(SIP_DST_URI); 
     348        bcfg.subscribe = PJ_FALSE; 
     349         
     350        pjsua_buddy_add(&bcfg, &g_buddy_id); 
     351    } 
    247352    return PJ_SUCCESS; 
    248353} 
     
    308413                "  D    Dump all states (detail)\n" 
    309414                "  P    Dump pool factory\n" 
     415                "  m    Make call\n" 
     416                "  a    Answer call\n" 
    310417                "  h    Hangup all calls\n" 
     418                "  s    Subscribe to buddy presence\n" 
     419                "  S    Unsubscribe buddy presence\n" 
     420                "  o    Set account online\n" 
     421                "  O    Set account offline\n" 
    311422                "  q    Quit\n")); 
    312423} 
     
    316427{ 
    317428        TKeyCode kc = con_->KeyCode(); 
    318  
     429        pj_bool_t reschedule = PJ_TRUE; 
     430         
    319431        switch (kc) { 
    320432        case 'q': 
    321433                asw_->AsyncStop(); 
     434                reschedule = PJ_FALSE; 
    322435                break; 
    323436        case 'D': 
    324437        case 'd': 
    325438                pjsua_dump(kc == 'D'); 
    326                 Run(); 
    327439                break; 
    328440        case 'P': 
    329441                pj_pool_factory_dump(&pjsua_var.cp.factory, PJ_TRUE); 
    330442                break; 
     443        case 'm': 
     444                if (g_call_id != PJSUA_INVALID_ID) { 
     445                        PJ_LOG(3,(THIS_FILE, "Another call is active"));         
     446                        break; 
     447                } 
     448         
     449                if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) { 
     450                        pj_str_t dst = pj_str(SIP_DST_URI); 
     451                        pjsua_call_make_call(g_acc_id, &dst, 0, NULL, 
     452                                             NULL, &g_call_id); 
     453                } else { 
     454                        PJ_LOG(3,(THIS_FILE, "Invalid SIP URI")); 
     455                } 
     456                break; 
     457        case 'a': 
     458                if (g_call_id != PJSUA_INVALID_ID) 
     459                        pjsua_call_answer(g_call_id, 200, NULL, NULL); 
     460                break; 
    331461        case 'h': 
    332462                pjsua_call_hangup_all(); 
    333                 Run(); 
     463                break; 
     464        case 's': 
     465        case 'S': 
     466                if (g_buddy_id != PJSUA_INVALID_ID) 
     467                        pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s'); 
     468                break; 
     469        case 'o': 
     470        case 'O': 
     471                pjsua_acc_set_online_status(g_acc_id, kc=='o'); 
    334472                break; 
    335473        default: 
    336474                PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", 
    337475                          kc, kc)); 
     476                break; 
     477        } 
     478 
     479        PrintMenu(); 
     480         
     481        if (reschedule) 
    338482                Run(); 
    339                 break; 
    340         } 
    341  
    342         PrintMenu(); 
    343483} 
    344484 
     
    349489         
    350490        // Initialize pjsua 
    351         status  = app_startup("sip:192.168.0.77"); 
     491        status  = app_startup(); 
    352492        if (status != PJ_SUCCESS) 
    353493                return status; 
Note: See TracChangeset for help on using the changeset viewer.