Changes between Version 11 and Version 12 of pjsip-doc/intro_pjsua2


Ignore:
Timestamp:
Feb 11, 2014 11:38:23 AM (8 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/intro_pjsua2

    v11 v12  
    102102 
    103103 
    104 Using in C++ Application 
    105 ======================== 
    106 As mentioned in previous chapter, a C++ application can use *pjsua2* natively, while at the same time still has access to the lower level objects and the ability to extend the libraries if it needs to. Using the API will be exactly the same as the API reference that is written in this book. 
    107  
    108 Here is a sample complete C++ application to give you some idea about the API. The snippet below initializes the library and creates an account that registers to our pjsip.org SIP server. 
    109  
    110 .. code-block:: c++ 
    111      
    112   #include <pjsua2.hpp> 
    113   #include <iostream> 
    114    
    115   using namespace pj; 
    116    
    117   // Subclass to extend the Account and get notifications etc. 
    118   class MyAccount : public Account { 
    119   public: 
    120       virtual void onRegState(OnRegStateParam &prm) { 
    121           AccountInfo ai = getInfo(); 
    122           std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:") 
    123                     << " code=" << prm.code << std::endl; 
    124       } 
    125   }; 
    126  
    127   int main() 
    128   { 
    129       Endpoint ep; 
    130        
    131       ep.libCreate(); 
    132        
    133       // Initialize endpoint 
    134       EpConfig ep_cfg; 
    135       ep.libInit( ep_cfg ); 
    136        
    137       // Create SIP transport. Error handling sample is shown 
    138       TransportConfig tcfg; 
    139       tcfg.port = 5060; 
    140       try { 
    141           ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg); 
    142       } catch (Error &err) { 
    143           std::cout << err.info() << std::endl; 
    144           return 1; 
    145       } 
    146        
    147       // Start the library (worker threads etc) 
    148       ep.libStart(); 
    149       std::cout << "*** PJSUA2 STARTED ***" << std::endl; 
    150        
    151       // Configure an AccountConfig 
    152       AccountConfig acfg; 
    153       acfg.idUri = "sip:test@pjsip.org"; 
    154       acfg.regConfig.registrarUri = "sip:pjsip.org"; 
    155       AuthCredInfo cred("digest", "*", "test", 0, "secret"); 
    156       acfg.sipConfig.authCreds.push_back( cred ); 
    157        
    158       // Create the account 
    159       MyAccount *acc = new MyAccount; 
    160       acc->create(acfg); 
    161        
    162       // Here we don't have anything else to do.. 
    163       pj_thread_sleep(10000); 
    164        
    165       // Delete the account. This will unregister from server 
    166       delete acc; 
    167        
    168       // This will implicitly shutdown the library 
    169       return 0; 
    170   } 
    171  
    172  
    173 Using in Python Application 
    174 =========================== 
    175  
    176  
    177  
    178 Using in Java Application 
    179 ========================= 
    180  
    181  
    182  
    183  
    184104}}}