Ignore:
Timestamp:
Mar 22, 2012 11:29:20 AM (12 years ago)
Author:
nanang
Message:

Close #1466 (using PJLIB outside PJSUA-LIB context):

  • static reference counter for PJLIB init/shutdown.
  • implemented atexit() in PJMEDIA and PJSIP level: pjmedia_endpt_atexit() & pjsip_endpt_atexit().
  • updated pjmedia/transport_srtp.c, pjsip/sip_timer.c, and pjsip/sip_replaces.c to use the new atexit() functions.
  • API change: pjmedia_srtp_init_lib() now requires 'pjmedia_endpt' param.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjmedia/src/pjmedia/endpoint.c

    r3957 r3986  
    2424#include <pj/assert.h> 
    2525#include <pj/ioqueue.h> 
     26#include <pj/lock.h> 
    2627#include <pj/log.h> 
    2728#include <pj/os.h> 
     
    5758 
    5859 
     60/* List of media endpoint exit callback. */ 
     61typedef struct exit_cb 
     62{ 
     63    PJ_DECL_LIST_MEMBER             (struct exit_cb); 
     64    pjmedia_endpt_exit_callback     func; 
     65} exit_cb; 
     66 
     67 
    5968/** Concrete declaration of media endpoint. */ 
    6069struct pjmedia_endpt 
     
    8695    /** Is telephone-event enable */ 
    8796    pj_bool_t             has_telephone_event; 
     97 
     98    /** List of exit callback. */ 
     99    exit_cb               exit_cb_list; 
    88100}; 
    89101 
     
    129141        goto on_error; 
    130142 
     143    /* Initialize exit callback list. */ 
     144    pj_list_init(&endpt->exit_cb_list); 
     145 
    131146    /* Create ioqueue if none is specified. */ 
    132147    if (endpt->ioqueue == NULL) { 
     
    189204PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt) 
    190205{ 
     206    exit_cb *ecb; 
    191207    unsigned i; 
    192208 
     
    202218            endpt->thread[i] = NULL; 
    203219        } 
     220    } 
     221 
     222    /* Call all registered exit callbacks */ 
     223    ecb = endpt->exit_cb_list.next; 
     224    while (ecb != &endpt->exit_cb_list) { 
     225        (*ecb->func)(endpt); 
     226        ecb = ecb->next; 
    204227    } 
    205228 
     
    629652    return PJ_SUCCESS; 
    630653} 
     654 
     655PJ_DEF(pj_status_t) pjmedia_endpt_atexit( pjmedia_endpt *endpt, 
     656                                          pjmedia_endpt_exit_callback func) 
     657{ 
     658    exit_cb *new_cb; 
     659 
     660    PJ_ASSERT_RETURN(endpt && func, PJ_EINVAL); 
     661 
     662    if (endpt->quit_flag) 
     663        return PJ_EINVALIDOP; 
     664 
     665    new_cb = PJ_POOL_ZALLOC_T(endpt->pool, exit_cb); 
     666    new_cb->func = func; 
     667 
     668    pj_enter_critical_section(); 
     669    pj_list_push_back(&endpt->exit_cb_list, new_cb); 
     670    pj_leave_critical_section(); 
     671 
     672    return PJ_SUCCESS; 
     673} 
Note: See TracChangeset for help on using the changeset viewer.