Changeset 5801


Ignore:
Timestamp:
May 31, 2018 9:58:00 AM (6 years ago)
Author:
nanang
Message:

Fix #2117: Add PJSUA2 API Account::shutdown() to avoid race condition between Account derived class destructor and onRegState callback.

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua2/account.hpp

    r5800 r5801  
    15101510     * Destructor. Note that if the account is deleted, it will also delete 
    15111511     * the corresponding account in the PJSUA-LIB. 
     1512     * 
     1513     * If application implements a derived class, the derived class should 
     1514     * call shutdown() in the beginning stage in its destructor, or 
     1515     * alternatively application should call shutdown() before deleting 
     1516     * the derived class instance. This is to avoid race condition between 
     1517     * the derived class destructor and Account callbacks. 
    15121518     */ 
    15131519    virtual ~Account(); 
     
    15151521    /** 
    15161522     * Create the account. 
     1523     * 
     1524     * If application implements a derived class, the derived class should 
     1525     * call shutdown() in the beginning stage in its destructor, or 
     1526     * alternatively application should call shutdown() before deleting 
     1527     * the derived class instance. This is to avoid race condition between 
     1528     * the derived class destructor and Account callbacks. 
    15171529     * 
    15181530     * @param cfg               The account config. 
     
    15211533    void create(const AccountConfig &cfg, 
    15221534                bool make_default=false) throw(Error); 
     1535 
     1536    /** 
     1537     * Shutdown the account. This will initiate unregistration if needed, 
     1538     * and delete the corresponding account in the PJSUA-LIB. 
     1539     * 
     1540     * If application implements a derived class, the derived class should 
     1541     * call this method in the beginning stage in its destructor, or 
     1542     * alternatively application should call this method before deleting 
     1543     * the derived class instance. This is to avoid race condition between 
     1544     * the derived class destructor and Account callbacks. 
     1545     */ 
     1546    void shutdown(); 
    15231547 
    15241548    /** 
     
    15421566     * Set this as default account to be used when incoming and outgoing 
    15431567     * requests don't match any accounts. 
    1544      * 
    1545      * @return                  PJ_SUCCESS on success. 
    15461568     */ 
    15471569    void setDefault() throw(Error); 
     
    16451667    Buddy* findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const 
    16461668                    throw(Error); 
    1647  
    1648     /** 
    1649      * An internal function to add a Buddy to Account buddy list. 
    1650      * This function must never be used by application. 
    1651      */ 
    1652     void addBuddy(Buddy *buddy); 
    1653  
    1654     /** 
    1655      * An internal function to remove a Buddy from Account buddy list. 
    1656      * This function must never be used by application. 
    1657      */ 
    1658     void removeBuddy(Buddy *buddy); 
    16591669 
    16601670public: 
     
    17631773    { PJ_UNUSED_ARG(prm); } 
    17641774 
    1765 protected: 
     1775 
     1776private: 
    17661777    friend class Endpoint; 
     1778    friend class Buddy; 
     1779 
     1780    /** 
     1781     * An internal function to add a Buddy to Account buddy list. 
     1782     * This method is used by Buddy::create(). 
     1783     */ 
     1784    void addBuddy(Buddy *buddy); 
     1785 
     1786    /** 
     1787     * An internal function to remove a Buddy from Account buddy list. 
     1788     * This method is used by Buddy::~Buddy(). 
     1789     */ 
     1790    void removeBuddy(Buddy *buddy); 
     1791 
    17671792 
    17681793private: 
  • pjproject/trunk/pjsip/src/pjsua2/account.cpp

    r5800 r5801  
    820820     * PJSUA library. 
    821821     */ 
     822    shutdown(); 
     823} 
     824 
     825void Account::create(const AccountConfig &acc_cfg, 
     826                     bool make_default) throw(Error) 
     827{ 
     828    pjsua_acc_config pj_acc_cfg; 
     829     
     830    acc_cfg.toPj(pj_acc_cfg); 
     831    pj_acc_cfg.user_data = (void*)this; 
     832    PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) ); 
     833} 
     834 
     835void Account::shutdown() 
     836{ 
    822837    if (isValid() && pjsua_get_state() < PJSUA_STATE_CLOSING) { 
    823838        // Cleanup buddies in the buddy list 
     
    835850} 
    836851 
    837 void Account::create(const AccountConfig &acc_cfg, 
    838                      bool make_default) throw(Error) 
    839 { 
    840     pjsua_acc_config pj_acc_cfg; 
    841      
    842     acc_cfg.toPj(pj_acc_cfg); 
    843     pj_acc_cfg.user_data = (void*)this; 
    844     PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) ); 
    845 } 
    846  
    847852void Account::modify(const AccountConfig &acc_cfg) throw(Error) 
    848853{ 
Note: See TracChangeset for help on using the changeset viewer.