Ignore:
Timestamp:
Nov 27, 2013 9:37:32 AM (10 years ago)
Author:
nanang
Message:

Re #1519: Added presence API in pjsua2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp

    r4644 r4657  
    1919#include <pjsua2/account.hpp> 
    2020#include <pjsua2/endpoint.hpp> 
     21#include <pjsua2/presence.hpp> 
    2122#include <pj/ctype.h> 
    2223#include "util.hpp" 
     
    446447    regConfig.firstRetryIntervalSec = prm.reg_first_retry_interval; 
    447448    regConfig.delayBeforeRefreshSec = prm.reg_delay_before_refresh; 
    448     regConfig.dropCallsOnFail   = prm.drop_calls_on_reg_fail; 
     449    regConfig.dropCallsOnFail   = PJ2BOOL(prm.drop_calls_on_reg_fail); 
    449450    regConfig.unregWaitSec      = prm.unreg_timeout; 
    450451    regConfig.proxyUse          = prm.reg_use_proxy; 
     
    484485    sipConfig.contactParams     = pj2Str(prm.contact_params); 
    485486    sipConfig.contactUriParams  = pj2Str(prm.contact_uri_params); 
    486     sipConfig.authInitialEmpty  = prm.auth_pref.initial_auth; 
     487    sipConfig.authInitialEmpty  = PJ2BOOL(prm.auth_pref.initial_auth); 
    487488    sipConfig.authInitialAlgorithm = pj2Str(prm.auth_pref.algorithm); 
    488489    sipConfig.transportId       = prm.transport_id; 
     
    504505        hdr = hdr->next; 
    505506    } 
    506     presConfig.publishEnabled   = prm.publish_enabled; 
    507     presConfig.publishQueue     = prm.publish_opt.queue_request; 
     507    presConfig.publishEnabled   = PJ2BOOL(prm.publish_enabled); 
     508    presConfig.publishQueue     = PJ2BOOL(prm.publish_opt.queue_request); 
    508509    presConfig.publishShutdownWaitMsec = prm.unpublish_max_wait_time_msec; 
    509510    presConfig.pidfTupleId      = pj2Str(prm.pidf_tuple_id); 
    510511 
    511512    // AccountMwiConfig 
    512     mwiConfig.enabled           = prm.mwi_enabled; 
     513    mwiConfig.enabled           = PJ2BOOL(prm.mwi_enabled); 
    513514    mwiConfig.expirationSec     = prm.mwi_expires; 
    514515 
     
    517518    natConfig.mediaStunUse      = prm.media_stun_use; 
    518519    if (prm.ice_cfg_use == PJSUA_ICE_CONFIG_USE_CUSTOM) { 
    519         natConfig.iceEnabled = prm.ice_cfg.enable_ice; 
     520        natConfig.iceEnabled = PJ2BOOL(prm.ice_cfg.enable_ice); 
    520521        natConfig.iceMaxHostCands = prm.ice_cfg.ice_max_host_cands; 
    521         natConfig.iceAggressiveNomination = prm.ice_cfg.ice_opt.aggressive; 
     522        natConfig.iceAggressiveNomination = PJ2BOOL(prm.ice_cfg.ice_opt.aggressive); 
    522523        natConfig.iceNominatedCheckDelayMsec = prm.ice_cfg.ice_opt.nominated_check_delay; 
    523524        natConfig.iceWaitNominationTimeoutMsec = prm.ice_cfg.ice_opt.controlled_agent_want_nom_timeout; 
    524         natConfig.iceNoRtcp     = prm.ice_cfg.ice_no_rtcp; 
    525         natConfig.iceAlwaysUpdate = prm.ice_cfg.ice_always_update; 
     525        natConfig.iceNoRtcp     = PJ2BOOL(prm.ice_cfg.ice_no_rtcp); 
     526        natConfig.iceAlwaysUpdate = PJ2BOOL(prm.ice_cfg.ice_always_update); 
    526527    } else { 
    527528        pjsua_media_config default_mcfg; 
     
    530531            mcfg = &default_mcfg; 
    531532        } 
    532         natConfig.iceEnabled    = mcfg->enable_ice; 
     533        natConfig.iceEnabled    = PJ2BOOL(mcfg->enable_ice); 
    533534        natConfig.iceMaxHostCands= mcfg->ice_max_host_cands; 
    534         natConfig.iceAggressiveNomination = mcfg->ice_opt.aggressive; 
     535        natConfig.iceAggressiveNomination = PJ2BOOL(mcfg->ice_opt.aggressive); 
    535536        natConfig.iceNominatedCheckDelayMsec = mcfg->ice_opt.nominated_check_delay; 
    536537        natConfig.iceWaitNominationTimeoutMsec = mcfg->ice_opt.controlled_agent_want_nom_timeout; 
    537         natConfig.iceNoRtcp     = mcfg->ice_no_rtcp; 
    538         natConfig.iceAlwaysUpdate = mcfg->ice_always_update; 
     538        natConfig.iceNoRtcp     = PJ2BOOL(mcfg->ice_no_rtcp); 
     539        natConfig.iceAlwaysUpdate = PJ2BOOL(mcfg->ice_always_update); 
    539540    } 
    540541 
    541542    if (prm.turn_cfg_use == PJSUA_TURN_CONFIG_USE_CUSTOM) { 
    542         natConfig.turnEnabled   = prm.turn_cfg.enable_turn; 
     543        natConfig.turnEnabled   = PJ2BOOL(prm.turn_cfg.enable_turn); 
    543544        natConfig.turnServer    = pj2Str(prm.turn_cfg.turn_server); 
    544545        natConfig.turnConnType  = prm.turn_cfg.turn_conn_type; 
     
    552553            mcfg = &default_mcfg; 
    553554        } 
    554         natConfig.turnEnabled   = mcfg->enable_turn; 
     555        natConfig.turnEnabled   = PJ2BOOL(mcfg->enable_turn); 
    555556        natConfig.turnServer    = pj2Str(mcfg->turn_server); 
    556557        natConfig.turnConnType  = mcfg->turn_conn_type; 
     
    571572    // AccountMediaConfig 
    572573    mediaConfig.transportConfig.fromPj(prm.rtp_cfg); 
    573     mediaConfig.lockCodecEnabled= prm.lock_codec; 
     574    mediaConfig.lockCodecEnabled= PJ2BOOL(prm.lock_codec); 
    574575#if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0) 
    575     mediaConfig.streamKaEnabled = prm.use_stream_ka; 
     576    mediaConfig.streamKaEnabled = PJ2BOOL(prm.use_stream_ka); 
    576577#else 
    577578    mediaConfig.streamKaEnabled = false; 
     
    582583 
    583584    // AccountVideoConfig 
    584     videoConfig.autoShowIncoming        = prm.vid_in_auto_show; 
    585     videoConfig.autoTransmitOutgoing    = prm.vid_out_auto_transmit; 
     585    videoConfig.autoShowIncoming        = PJ2BOOL(prm.vid_in_auto_show); 
     586    videoConfig.autoTransmitOutgoing    = PJ2BOOL(prm.vid_out_auto_transmit); 
    586587    videoConfig.windowFlags             = prm.vid_wnd_flags; 
    587588    videoConfig.defaultCaptureDevice    = prm.vid_cap_dev; 
     
    623624} 
    624625 
    625  
    626 /////////////////////////////////////////////////////////////////////////////// 
    627  
    628 AccountPresenceStatus::AccountPresenceStatus() 
    629 : isOnline(false), activity(PJRPID_ACTIVITY_UNKNOWN) 
    630 { 
    631 } 
    632626 
    633627/////////////////////////////////////////////////////////////////////////////// 
     
    662656     */ 
    663657    if (isValid() && pjsua_get_state() < PJSUA_STATE_CLOSING) { 
     658        // Cleanup buddies in the buddy list 
     659        while(buddyList.size() > 0) { 
     660            Buddy *b = buddyList[0]; 
     661            delete b; 
     662        } 
     663 
    664664        PJSUA2_CHECK_EXPR( pjsua_acc_set_user_data(id, NULL) ); 
    665665        PJSUA2_CHECK_EXPR( pjsua_acc_del(id) ); 
     
    724724 
    725725void 
    726 Account::setOnlineStatus(const AccountPresenceStatus &pres_st) throw(Error) 
     726Account::setOnlineStatus(const PresenceStatus &pres_st) throw(Error) 
    727727{ 
    728728    pjrpid_element pj_rpid; 
     
    734734    pj_rpid.note        = str2Pj(pres_st.note); 
    735735 
    736     PJSUA2_CHECK_EXPR( pjsua_acc_set_online_status2(id, pres_st.isOnline, 
    737                                                     &pj_rpid) ); 
     736    PJSUA2_CHECK_EXPR( pjsua_acc_set_online_status2( 
     737                            id, pres_st.status == PJSUA_BUDDY_STATUS_ONLINE, 
     738                            &pj_rpid) ); 
    738739} 
    739740 
     
    743744} 
    744745 
     746void Account::presNotify(const PresNotifyParam &prm) throw(Error) 
     747{ 
     748    pj_str_t pj_state_str   = str2Pj(prm.stateStr); 
     749    pj_str_t pj_reason      = str2Pj(prm.reason); 
     750    pjsua_msg_data msg_data; 
     751    prm.txOption.toPj(msg_data); 
     752 
     753    PJSUA2_CHECK_EXPR( pjsua_pres_notify(id, (pjsua_srv_pres*)prm.srvPres, 
     754                                         prm.state, &pj_state_str, 
     755                                         &pj_reason, prm.withBody, 
     756                                         &msg_data) ); 
     757} 
     758 
     759const BuddyVector& Account::enumBuddies() const throw(Error) 
     760{ 
     761    return buddyList; 
     762} 
     763 
     764Buddy* Account::findBuddy(string uri, FindBuddyMatch *buddy_match) const 
     765                throw(Error) 
     766{ 
     767    if (!buddy_match) { 
     768        static FindBuddyMatch def_bm; 
     769        buddy_match = &def_bm; 
     770    } 
     771 
     772    for (unsigned i = 0; i < buddyList.size(); i++) { 
     773        if (buddy_match->match(uri, *buddyList[i])) 
     774            return buddyList[i]; 
     775    } 
     776    PJSUA2_RAISE_ERROR(PJ_ENOTFOUND); 
     777} 
     778 
     779void Account::addBuddy(Buddy *buddy) 
     780{ 
     781    pj_assert(buddy); 
     782 
     783    buddyList.push_back(buddy); 
     784} 
     785 
     786void Account::removeBuddy(Buddy *buddy) 
     787{ 
     788    pj_assert(buddy); 
     789 
     790    BuddyVector::iterator it; 
     791    for (it = buddyList.begin(); it != buddyList.end(); it++) { 
     792        if (*it == buddy) { 
     793            buddyList.erase(it); 
     794            return; 
     795        } 
     796    } 
     797 
     798    pj_assert(!"Bug! Buddy to be removed is not in the buddy list!"); 
     799} 
Note: See TracChangeset for help on using the changeset viewer.