Ignore:
Timestamp:
Oct 25, 2013 10:34:38 AM (10 years ago)
Author:
bennylp
Message:

Re #1519: Implementation of Account API, with inheritance approach:

  • With small demo app (samples/pjsua2_demo.cpp)
  • Endpoint changed to use inheritance approach too
  • Simple account registration demo and callback works
  • Further tests will be done in high level app (Python GUI?)
  • Temporary build setting fixes (Makefile) to allow linking with pjsua2 and libstdc++
  • Temporary hacks in Makefile to ignore other build targets to speed up build. This should be fixed during integration.

Issues:

  • incomplete Endpoint::on_incoming_subscribe() implementation. There is no Account::presNotify() yet.
  • incomplete Endpoint::on_pager2(), on_pager_status2(), to handle call's pager rather than account's pager
  • some SWIGTYPE (unknown type by Swig) still unresolved
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp

    r4608 r4638  
    4343 
    4444/** 
    45  * Argument to EpCallback::onNatDetectionComplete() callback. 
     45 * Argument to Endpoint::onNatDetectionComplete() callback. 
    4646 */ 
    4747struct OnNatDetectionCompleteParam 
     
    7373 
    7474/** 
    75  * Argument to EpCallback::onNatCheckStunServersComplete() callback. 
     75 * Argument to Endpoint::onNatCheckStunServersComplete() callback. 
    7676 */ 
    7777struct OnNatCheckStunServersCompleteParam 
     
    104104 
    105105/** 
    106  * Parameter of EpCallback::OnTimer() callback. 
     106 * Parameter of Endpoint::onTimer() callback. 
    107107 */ 
    108108struct OnTimerParam 
     
    121121 
    122122/** 
    123  * Parameter of EpCallback::onTransportState() callback. 
     123 * Parameter of Endpoint::onTransportState() callback. 
    124124 */ 
    125125struct OnTransportStateParam 
     
    142142 
    143143/** 
    144  * Parameter of EpCallback::onSelectAccount() callback. 
     144 * Parameter of Endpoint::onSelectAccount() callback. 
    145145 */ 
    146146struct OnSelectAccountParam 
     
    159159    int                 accountIndex; 
    160160}; 
    161  
    162 ////////////////////////////////////////////////////////////////////////////// 
    163  
    164 /** 
    165  * Interface for receiving callbacks from the library. Application inherits 
    166  * this class and specify the instance when calling Endpoint::libInit(). 
    167  */ 
    168 class EpCallback 
    169 { 
    170 public: 
    171     /** Virtual destructor */ 
    172     virtual ~EpCallback() {} 
    173  
    174     /** 
    175      * Callback when the Endpoint has finished performing NAT type 
    176      * detection that is initiated with Endpoint::natDetectType(). 
    177      * 
    178      * @param prm       Callback parameters containing the detection 
    179      *                  result. 
    180      */ 
    181     virtual void onNatDetectionComplete( 
    182                         const OnNatDetectionCompleteParam &prm) 
    183     {} 
    184  
    185     /** 
    186      * Callback when the Endpoint has finished performing STUN server 
    187      * checking that is initiated with Endpoint::natCheckStunServers(). 
    188      * 
    189      * @param prm       Callback parameters. 
    190      */ 
    191     virtual void onNatCheckStunServersComplete( 
    192                         const OnNatCheckStunServersCompleteParam &prm) 
    193     {} 
    194  
    195     /** 
    196      * This callback is called when transport state has changed. 
    197      * 
    198      * @param prm       Callback parameters. 
    199      */ 
    200     virtual void onTransportState( 
    201                         const OnTransportStateParam &prm) 
    202     {} 
    203  
    204     /** 
    205      * Callback when a timer has fired. The timer was scheduled by 
    206      * Endpoint::utilTimerSchedule(). 
    207      * 
    208      * @param prm       Callback parameters. 
    209      */ 
    210     virtual void onTimer(const OnTimerParam &prm) 
    211     {} 
    212  
    213     /** 
    214      * This callback can be used by application to override the account 
    215      * to be used to handle an incoming message. Initially, the account to 
    216      * be used will be calculated automatically by the library. This initial 
    217      * account will be used if application does not implement this callback, 
    218      * or application sets an invalid account upon returning from this 
    219      * callback. 
    220      * 
    221      * Note that currently the incoming messages requiring account assignment 
    222      * are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback 
    223      * may be called before the callback of the SIP event itself, i.e: 
    224      * incoming call, pager, subscription, or unsolicited-event. 
    225      * 
    226      * @param prm       Callback parameters. 
    227      */ 
    228     virtual void onSelectAccount(OnSelectAccountParam &prm) 
    229     {} 
    230 }; 
    231  
    232161 
    233162////////////////////////////////////////////////////////////////////////////// 
     
    313242     * 
    314243     * If this is enabled, the library will respond 200/OK to the NOTIFY 
    315      * request and forward the request to EpCallback.onMwiInfo() callback. 
     244     * request and forward the request to Endpoint::onMwiInfo() callback. 
    316245     * 
    317246     * See also AccountMwiConfig.enabled. 
     
    407336 
    408337    /** 
    409      * Custom log writer, if required. If specified, the instance of LogWriter 
    410      * must be kept alive througout the duration of the application. 
     338     * Custom log writer, if required. This instance will be destroyed 
     339     * by the endpoint when the endpoint is destroyed. 
    411340     */ 
    412341    LogWriter           *writer; 
     
    655584public: 
    656585    /** Retrieve the singleton instance of the endpoint */ 
    657     static Endpoint &instance(); 
    658  
    659     /* For testing */ 
    660     void testException() throw(Error); 
     586    static Endpoint &instance() throw(Error); 
     587 
     588    /** Default constructor */ 
     589    Endpoint(); 
     590 
     591    /** Virtual destructor */ 
     592    virtual ~Endpoint(); 
    661593 
    662594 
     
    688620     * 
    689621     * @param prmEpConfig       Endpoint configurations 
    690      * @param prmCb             Optional callback to receive events from the 
    691      *                          library. If specified, this instance must be 
    692      *                          kept alive throughout the lifetime of the 
    693      *                          library. 
    694      */ 
    695     void libInit( const EpConfig &prmEpConfig, 
    696                   EpCallback *prmCb = NULL) throw(Error); 
     622     */ 
     623    void libInit( const EpConfig &prmEpConfig) throw(Error); 
    697624 
    698625    /** 
     
    770697    /** 
    771698     * Schedule a timer with the specified interval and user data. When the 
    772      * interval elapsed, EpCallback::OnTimer() callback will be 
     699     * interval elapsed, Endpoint::onTimer() callback will be 
    773700     * called. Note that the callback may be executed by different thread, 
    774701     * depending on whether worker thread is enabled or not. 
     
    803730     * This is a utility function to detect NAT type in front of this endpoint. 
    804731     * Once invoked successfully, this function will complete asynchronously 
    805      * and report the result in EpCallback::onNatDetectionComplete(). 
     732     * and report the result in Endpoint::onNatDetectionComplete(). 
    806733     * 
    807734     * After NAT has been detected and the callback is called, application can 
     
    817744     * Get the NAT type as detected by #natDetectType() function. This 
    818745     * function will only return useful NAT type after #natDetectType() 
    819      * has completed successfully and EpCallback::onNatDetectionComplete() 
     746     * has completed successfully and Endpoint::onNatDetectionComplete() 
    820747     * callback has been called. 
    821748     * 
     
    926853    void transportClose(TransportId id) throw(Error); 
    927854 
     855public: 
     856    /* 
     857     * Overrideables callbacks 
     858     */ 
     859 
     860    /** 
     861     * Callback when the Endpoint has finished performing NAT type 
     862     * detection that is initiated with Endpoint::natDetectType(). 
     863     * 
     864     * @param prm       Callback parameters containing the detection 
     865     *                  result. 
     866     */ 
     867    virtual void onNatDetectionComplete( 
     868                        const OnNatDetectionCompleteParam &prm) 
     869    {} 
     870 
     871    /** 
     872     * Callback when the Endpoint has finished performing STUN server 
     873     * checking that is initiated with Endpoint::natCheckStunServers(). 
     874     * 
     875     * @param prm       Callback parameters. 
     876     */ 
     877    virtual void onNatCheckStunServersComplete( 
     878                        const OnNatCheckStunServersCompleteParam &prm) 
     879    {} 
     880 
     881    /** 
     882     * This callback is called when transport state has changed. 
     883     * 
     884     * @param prm       Callback parameters. 
     885     */ 
     886    virtual void onTransportState( 
     887                        const OnTransportStateParam &prm) 
     888    {} 
     889 
     890    /** 
     891     * Callback when a timer has fired. The timer was scheduled by 
     892     * Endpoint::utilTimerSchedule(). 
     893     * 
     894     * @param prm       Callback parameters. 
     895     */ 
     896    virtual void onTimer(const OnTimerParam &prm) 
     897    {} 
     898 
     899    /** 
     900     * This callback can be used by application to override the account 
     901     * to be used to handle an incoming message. Initially, the account to 
     902     * be used will be calculated automatically by the library. This initial 
     903     * account will be used if application does not implement this callback, 
     904     * or application sets an invalid account upon returning from this 
     905     * callback. 
     906     * 
     907     * Note that currently the incoming messages requiring account assignment 
     908     * are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback 
     909     * may be called before the callback of the SIP event itself, i.e: 
     910     * incoming call, pager, subscription, or unsolicited-event. 
     911     * 
     912     * @param prm       Callback parameters. 
     913     */ 
     914    virtual void onSelectAccount(OnSelectAccountParam &prm) 
     915    {} 
     916 
    928917 
    929918private: 
    930     /* Anybody else can't instantiate Endpoint */ 
    931     Endpoint(); 
    932  
    933 private: 
    934     /* Custom writer, if any */ 
    935     LogWriter   *writer; 
    936     EpCallback  *epCallback; 
    937  
    938     /* 
    939      * Callbacks (static) 
    940      */ 
     919    static Endpoint     *instance_;     // static instance 
     920    LogWriter           *writer;        // Custom writer, if any 
     921 
     922    /* Endpoint static callbacks */ 
    941923    static void logFunc(int level, const char *data, int len); 
    942924    static void stun_resolve_cb(const pj_stun_resolve_result *result); 
     
    947929                                   pjsip_transport_state state, 
    948930                                   const pjsip_transport_state_info *info); 
     931 
     932private: 
     933    /* 
     934     * Account 
     935     */ 
     936    static Account      *lookupAcc(int acc_id, const char *op); 
     937 
     938    /* static callbacks */ 
     939    static void on_incoming_call(pjsua_acc_id acc_id, 
     940                                 pjsua_call_id call_id, 
     941                                 pjsip_rx_data *rdata); 
     942    static void on_reg_started(pjsua_acc_id acc_id, 
     943                               pj_bool_t renew); 
     944    static void on_reg_state2(pjsua_acc_id acc_id, 
     945                              pjsua_reg_info *info); 
     946    static void on_incoming_subscribe(pjsua_acc_id acc_id, 
     947                                      pjsua_srv_pres *srv_pres, 
     948                                      pjsua_buddy_id buddy_id, 
     949                                      const pj_str_t *from, 
     950                                      pjsip_rx_data *rdata, 
     951                                      pjsip_status_code *code, 
     952                                      pj_str_t *reason, 
     953                                      pjsua_msg_data *msg_data); 
     954    static void on_pager2(pjsua_call_id call_id, 
     955                          const pj_str_t *from, 
     956                          const pj_str_t *to, 
     957                          const pj_str_t *contact, 
     958                          const pj_str_t *mime_type, 
     959                          const pj_str_t *body, 
     960                          pjsip_rx_data *rdata, 
     961                          pjsua_acc_id acc_id); 
     962    static void on_pager_status2(pjsua_call_id call_id, 
     963                                 const pj_str_t *to, 
     964                                 const pj_str_t *body, 
     965                                 void *user_data, 
     966                                 pjsip_status_code status, 
     967                                 const pj_str_t *reason, 
     968                                 pjsip_tx_data *tdata, 
     969                                 pjsip_rx_data *rdata, 
     970                                 pjsua_acc_id acc_id); 
     971    static void on_typing2(pjsua_call_id call_id, 
     972                           const pj_str_t *from, 
     973                           const pj_str_t *to, 
     974                           const pj_str_t *contact, 
     975                           pj_bool_t is_typing, 
     976                           pjsip_rx_data *rdata, 
     977                           pjsua_acc_id acc_id); 
     978    static void on_mwi_info(pjsua_acc_id acc_id, 
     979                            pjsua_mwi_info *mwi_info); 
    949980}; 
    950981 
Note: See TracChangeset for help on using the changeset viewer.