Changes between Initial Version and Version 1 of pjsip-doc/getting_started


Ignore:
Timestamp:
Feb 11, 2014 11:40:45 AM (10 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/getting_started

    v1 v1  
     1{{{ 
     2#!rst 
     3Getting Started 
     4****************************** 
     5 
     6Building PJSUA2 
     7====================== 
     8The PJSUA2 C++ library will be built by default by PJSIP build system. 
     9 
     10Building Python and Java SWIG Modules 
     11====================================== 
     12The SWIG modules for Python and Java are built by invoking ``make`` manually from ``pjsip-apps/src/swig`` directory. 
     13 
     14 
     15Using in C++ Application 
     16======================== 
     17As 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. 
     18 
     19Here 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. 
     20 
     21.. code-block:: c++ 
     22     
     23  #include <pjsua2.hpp> 
     24  #include <iostream> 
     25   
     26  using namespace pj; 
     27   
     28  // Subclass to extend the Account and get notifications etc. 
     29  class MyAccount : public Account { 
     30  public: 
     31      virtual void onRegState(OnRegStateParam &prm) { 
     32          AccountInfo ai = getInfo(); 
     33          std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:") 
     34                    << " code=" << prm.code << std::endl; 
     35      } 
     36  }; 
     37 
     38  int main() 
     39  { 
     40      Endpoint ep; 
     41       
     42      ep.libCreate(); 
     43       
     44      // Initialize endpoint 
     45      EpConfig ep_cfg; 
     46      ep.libInit( ep_cfg ); 
     47       
     48      // Create SIP transport. Error handling sample is shown 
     49      TransportConfig tcfg; 
     50      tcfg.port = 5060; 
     51      try { 
     52          ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg); 
     53      } catch (Error &err) { 
     54          std::cout << err.info() << std::endl; 
     55          return 1; 
     56      } 
     57       
     58      // Start the library (worker threads etc) 
     59      ep.libStart(); 
     60      std::cout << "*** PJSUA2 STARTED ***" << std::endl; 
     61       
     62      // Configure an AccountConfig 
     63      AccountConfig acfg; 
     64      acfg.idUri = "sip:test@pjsip.org"; 
     65      acfg.regConfig.registrarUri = "sip:pjsip.org"; 
     66      AuthCredInfo cred("digest", "*", "test", 0, "secret"); 
     67      acfg.sipConfig.authCreds.push_back( cred ); 
     68       
     69      // Create the account 
     70      MyAccount *acc = new MyAccount; 
     71      acc->create(acfg); 
     72       
     73      // Here we don't have anything else to do.. 
     74      pj_thread_sleep(10000); 
     75       
     76      // Delete the account. This will unregister from server 
     77      delete acc; 
     78       
     79      // This will implicitly shutdown the library 
     80      return 0; 
     81  } 
     82 
     83 
     84Using in Python Application 
     85=========================== 
     86 
     87 
     88 
     89Using in Java Application 
     90========================= 
     91 
     92 
     93 
     94 
     95}}}