Ignore:
Timestamp:
Feb 19, 2006 1:38:06 AM (18 years ago)
Author:
bennylp
Message:

Initial SIMPLE implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua/pjsua_core.c

    r184 r197  
    8080 
    8181    pj_list_init(&pjsua.inv_list); 
     82 
     83    /* Init server presence subscription list: */ 
     84     
     85    pj_list_init(&pjsua.pres_srv_list); 
     86 
    8287} 
    8388 
     
    392397 
    393398 
    394 static int PJ_THREAD_FUNC pjsua_worker_thread(void *arg) 
     399static int PJ_THREAD_FUNC pjsua_poll(void *arg) 
    395400{ 
    396401    PJ_UNUSED_ARG(arg); 
    397402 
    398     while (!pjsua.quit_flag) { 
     403    do { 
    399404        pj_time_val timeout = { 0, 10 }; 
    400405        pjsip_endpt_handle_events (pjsua.endpt, &timeout); 
    401     } 
     406    } while (!pjsua.quit_flag); 
    402407 
    403408    return 0; 
     
    436441 
    437442 
    438     /* Init PJSIP and all the modules: */ 
     443    /* Init PJSIP : */ 
    439444 
    440445    status = init_stack(); 
     
    444449        return status; 
    445450    } 
     451 
     452 
     453    /* Init core SIMPLE module : */ 
     454 
     455    pjsip_evsub_init_module(pjsua.endpt); 
     456 
     457    /* Init presence module: */ 
     458 
     459    pjsip_pres_init_module( pjsua.endpt, pjsip_evsub_instance()); 
     460 
     461 
     462    /* Init pjsua presence handler: */ 
     463 
     464    pjsua_pres_init(); 
    446465 
    447466 
     
    610629 
    611630    for (i=0; i<pjsua.thread_cnt; ++i) { 
    612         status = pj_thread_create( pjsua.pool, "pjsua", &pjsua_worker_thread, 
     631        status = pj_thread_create( pjsua.pool, "pjsua", &pjsua_poll, 
    613632                                   NULL, 0, 0, &pjsua.threads[i]); 
    614633        if (status != PJ_SUCCESS) { 
     
    636655 
    637656 
    638  
     657    PJ_LOG(3,(THIS_FILE, "PJSUA version %s started", PJ_VERSION)); 
    639658    return PJ_SUCCESS; 
    640659} 
    641660 
     661 
     662/* Sleep with polling */ 
     663static void busy_sleep(unsigned msec) 
     664{ 
     665    pj_time_val timeout, now; 
     666 
     667    pj_gettimeofday(&timeout); 
     668    timeout.msec += msec; 
     669    pj_time_val_normalize(&timeout); 
     670 
     671    do { 
     672        pjsua_poll(NULL); 
     673        pj_gettimeofday(&now); 
     674    } while (PJ_TIME_VAL_LT(now, timeout)); 
     675} 
    642676 
    643677/* 
     
    648682    int i; 
    649683 
    650     /* Unregister, if required: */ 
    651     if (pjsua.regc) { 
    652  
    653         pjsua_regc_update(0); 
    654  
    655         /* Wait for some time to allow unregistration to complete: */ 
    656  
    657         pj_thread_sleep(500); 
    658     } 
    659  
    660684    /* Signal threads to quit: */ 
    661  
    662685    pjsua.quit_flag = 1; 
    663686 
    664  
    665     /* Shutdown pjmedia-codec: */ 
    666  
    667     pjmedia_codec_deinit(); 
    668  
    669  
    670     /* Destroy sound framework:  
    671      * (this should be done in pjmedia_shutdown()) 
    672      */ 
    673     pj_snd_deinit(); 
    674  
    675687    /* Wait worker threads to quit: */ 
    676  
    677688    for (i=0; i<pjsua.thread_cnt; ++i) { 
    678689         
     
    684695    } 
    685696 
     697 
     698    /* Terminate all calls. */ 
     699    pjsua_inv_shutdown(); 
     700 
     701    /* Terminate all presence subscriptions. */ 
     702    pjsua_pres_shutdown(); 
     703 
     704    /* Unregister, if required: */ 
     705    if (pjsua.regc) { 
     706        pjsua_regc_update(0); 
     707    } 
     708 
     709    /* Wait for some time to allow unregistration to complete: */ 
     710    PJ_LOG(4,(THIS_FILE, "Shutting down...")); 
     711    busy_sleep(1000); 
     712 
     713    /* Shutdown pjmedia-codec: */ 
     714    pjmedia_codec_deinit(); 
     715 
     716    /* Destroy sound framework:  
     717     * (this should be done in pjmedia_shutdown()) 
     718     */ 
     719    pj_snd_deinit(); 
     720 
    686721    /* Destroy endpoint. */ 
    687722 
Note: See TracChangeset for help on using the changeset viewer.