Changeset 3829


Ignore:
Timestamp:
Oct 19, 2011 12:45:05 PM (12 years ago)
Author:
bennylp
Message:

Fixed #1216: New pjsua_destroy2() API to allow shutting down the library without sending any outgoing messages

Location:
pjproject/branches/1.x
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjsip-apps/src/pjsua/pjsua_app.c

    r3804 r3829  
    51195119    } 
    51205120 
    5121     status = pjsua_destroy(); 
     5121    status = pjsua_destroy2(1); 
    51225122 
    51235123    pj_bzero(&app_config, sizeof(app_config)); 
  • pjproject/branches/1.x/pjsip/include/pjsua-lib/pjsua.h

    r3762 r3829  
    12951295 
    12961296/** 
     1297 * Flags to be given to pjsua_destroy2() 
     1298 */ 
     1299typedef enum pjsua_destroy_flag 
     1300{ 
     1301    /** 
     1302     * Do not invoke any networking functions. 
     1303     */ 
     1304    PJSUA_DESTROY_NO_NETWORK = 1 
     1305 
     1306} pjsua_destroy_flag; 
     1307 
     1308/** 
    12971309 * Use this function to initialize pjsua config. 
    12981310 * 
     
    14301442 * keep track of it's state. 
    14311443 * 
     1444 * @see pjsua_destroy2() 
     1445 * 
    14321446 * @return              PJ_SUCCESS on success, or the appropriate error code. 
    14331447 */ 
    14341448PJ_DECL(pj_status_t) pjsua_destroy(void); 
     1449 
     1450 
     1451/** 
     1452 * Variant of destroy with additional flags. 
     1453 * 
     1454 * @param flags         Combination of pjsua_destroy_flag enumeration. 
     1455 * 
     1456 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     1457 */ 
     1458PJ_DECL(pj_status_t) pjsua_destroy2(unsigned flags); 
    14351459 
    14361460 
  • pjproject/branches/1.x/pjsip/include/pjsua-lib/pjsua_internal.h

    r3749 r3829  
    464464 * Shutdown presence. 
    465465 */ 
    466 void pjsua_pres_shutdown(void); 
     466void pjsua_pres_shutdown(unsigned flags); 
    467467 
    468468/** 
     
    479479 *  Send un-PUBLISH 
    480480 */ 
    481 void pjsua_pres_unpublish(pjsua_acc *acc); 
     481void pjsua_pres_unpublish(pjsua_acc *acc, unsigned flags); 
    482482 
    483483/** 
    484484 * Terminate server subscription for the account  
    485485 */ 
    486 void pjsua_pres_delete_acc(int acc_id); 
     486void pjsua_pres_delete_acc(int acc_id, unsigned flags); 
    487487 
    488488/** 
     
    519519 * Destroy pjsua media subsystem. 
    520520 */ 
    521 pj_status_t pjsua_media_subsys_destroy(void); 
     521pj_status_t pjsua_media_subsys_destroy(unsigned flags); 
    522522 
    523523/** 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_acc.c

    r3770 r3829  
    583583 
    584584    /* Delete server presence subscription */ 
    585     pjsua_pres_delete_acc(acc_id); 
     585    pjsua_pres_delete_acc(acc_id, 0); 
    586586 
    587587    /* Release account pool */ 
     
    802802        acc->cfg.publish_enabled = cfg->publish_enabled; 
    803803        if (!acc->cfg.publish_enabled) 
    804             pjsua_pres_unpublish(acc); 
     804            pjsua_pres_unpublish(acc, 0); 
    805805        else 
    806806            update_reg = PJ_TRUE; 
     
    19961996        } 
    19971997 
    1998         pjsua_pres_unpublish(&pjsua_var.acc[acc_id]); 
     1998        pjsua_pres_unpublish(&pjsua_var.acc[acc_id], 0); 
    19991999 
    20002000        status = pjsip_regc_unregister(pjsua_var.acc[acc_id].regc, &tdata); 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_core.c

    r3594 r3829  
    12841284 * Destroy pjsua. 
    12851285 */ 
    1286 PJ_DEF(pj_status_t) pjsua_destroy(void) 
     1286PJ_DEF(pj_status_t) pjsua_destroy2(unsigned flags) 
    12871287{ 
    12881288    int i;  /* Must be signed */ 
     
    13031303        unsigned max_wait; 
    13041304 
    1305         PJ_LOG(4,(THIS_FILE, "Shutting down...")); 
     1305        PJ_LOG(4,(THIS_FILE, "Shutting down, flags=%d...", flags)); 
    13061306 
    13071307        /* Terminate all calls. */ 
    1308         pjsua_call_hangup_all(); 
     1308        if ((flags & PJSUA_DESTROY_NO_NETWORK) == 0) { 
     1309            pjsua_call_hangup_all(); 
     1310        } 
    13091311 
    13101312        /* Set all accounts to offline */ 
     
    13171319 
    13181320        /* Terminate all presence subscriptions. */ 
    1319         pjsua_pres_shutdown(); 
     1321        pjsua_pres_shutdown(flags); 
    13201322 
    13211323        /* Destroy media (to shutdown media transports etc) */ 
    1322         pjsua_media_subsys_destroy(); 
     1324        pjsua_media_subsys_destroy(flags); 
    13231325 
    13241326        /* Wait for sometime until all publish client sessions are done 
     
    13341336        } 
    13351337         
     1338        /* No need to wait if we didn't send anything */ 
     1339        if (flags & PJSUA_DESTROY_NO_NETWORK) { 
     1340            max_wait = 0; 
     1341        } 
     1342 
    13361343        /* Second stage, wait for unpublications to complete */ 
    13371344        for (i=0; i<(int)(max_wait/50); ++i) { 
     
    13631370                continue; 
    13641371 
    1365             if (pjsua_var.acc[i].regc) { 
     1372            if (pjsua_var.acc[i].regc && (flags & PJSUA_DESTROY_NO_NETWORK)==0) 
     1373            { 
    13661374                pjsua_acc_set_registration(i, PJ_FALSE); 
    13671375            } 
     
    13881396        } 
    13891397         
     1398        /* No need to wait if we didn't send anything */ 
     1399        if (flags & PJSUA_DESTROY_NO_NETWORK) { 
     1400            max_wait = 0; 
     1401        } 
     1402 
    13901403        /* Second stage, wait for unregistrations to complete */ 
    13911404        for (i=0; i<(int)(max_wait/50); ++i) { 
     
    14081421         * transports shutdown to complete:  
    14091422         */ 
    1410         if (i < 20) 
     1423        if (i < 20 && (flags & PJSUA_DESTROY_NO_NETWORK) == 0) { 
    14111424            busy_sleep(1000 - i*50); 
     1425        } 
    14121426 
    14131427        PJ_LOG(4,(THIS_FILE, "Destroying...")); 
     
    14671481    /* Done. */ 
    14681482    return PJ_SUCCESS; 
     1483} 
     1484 
     1485 
     1486PJ_DEF(pj_status_t) pjsua_destroy(void) 
     1487{ 
     1488    return pjsua_destroy2(0); 
    14691489} 
    14701490 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c

    r3816 r3829  
    659659 * Destroy pjsua media subsystem. 
    660660 */ 
    661 pj_status_t pjsua_media_subsys_destroy(void) 
     661pj_status_t pjsua_media_subsys_destroy(unsigned flags) 
    662662{ 
    663663    unsigned i; 
     
    699699        } 
    700700        if (pjsua_var.calls[i].med_tp && pjsua_var.calls[i].med_tp_auto_del) { 
     701            /* TODO: check if we're not allowed to send to network in the 
     702             *       "flags", and if so do not do TURN allocation... 
     703             */ 
     704            PJ_UNUSED_ARG(flags); 
    701705            pjmedia_transport_close(pjsua_var.calls[i].med_tp); 
    702706        } 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_pres.c

    r3604 r3829  
    12781278 
    12791279/* Unpublish presence publication */ 
    1280 void pjsua_pres_unpublish(pjsua_acc *acc) 
     1280void pjsua_pres_unpublish(pjsua_acc *acc, unsigned flags) 
    12811281{ 
    12821282    if (acc->publish_sess) { 
     
    12841284 
    12851285        acc->online_status = PJ_FALSE; 
    1286         send_publish(acc->index, PJ_FALSE); 
     1286 
     1287        if ((flags & PJSUA_DESTROY_NO_NETWORK) == 0) { 
     1288            send_publish(acc->index, PJ_FALSE); 
     1289        } 
     1290 
    12871291        /* By ticket #364, don't destroy the session yet (let the callback 
    12881292           destroy it) 
     
    12971301 
    12981302/* Terminate server subscription for the account */ 
    1299 void pjsua_pres_delete_acc(int acc_id) 
     1303void pjsua_pres_delete_acc(int acc_id, unsigned flags) 
    13001304{ 
    13011305    pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
     
    13191323        pjsip_pres_set_status(uapres->sub, &pres_status); 
    13201324 
    1321         if (pjsip_pres_notify(uapres->sub,  
    1322                               PJSIP_EVSUB_STATE_TERMINATED, NULL, 
    1323                               &reason, &tdata)==PJ_SUCCESS) 
    1324         { 
    1325             pjsip_pres_send_request(uapres->sub, tdata); 
     1325        if ((flags & PJSUA_DESTROY_NO_NETWORK) == 0) { 
     1326            if (pjsip_pres_notify(uapres->sub, 
     1327                                  PJSIP_EVSUB_STATE_TERMINATED, NULL, 
     1328                                  &reason, &tdata)==PJ_SUCCESS) 
     1329            { 
     1330                pjsip_pres_send_request(uapres->sub, tdata); 
     1331            } 
     1332        } else { 
     1333            pjsip_pres_terminate(uapres->sub, PJ_FALSE); 
    13261334        } 
    13271335 
     
    13341342 
    13351343    /* Terminate presence publication, if any */ 
    1336     pjsua_pres_unpublish(acc); 
     1344    pjsua_pres_unpublish(acc, flags); 
    13371345} 
    13381346 
     
    22532261 * Shutdown presence. 
    22542262 */ 
    2255 void pjsua_pres_shutdown(void) 
     2263void pjsua_pres_shutdown(unsigned flags) 
    22562264{ 
    22572265    unsigned i; 
     
    22672275        if (!pjsua_var.acc[i].valid) 
    22682276            continue; 
    2269         pjsua_pres_delete_acc(i); 
     2277        pjsua_pres_delete_acc(i, flags); 
    22702278    } 
    22712279 
     
    22742282    } 
    22752283 
    2276     refresh_client_subscriptions(); 
    2277  
    2278     for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
    2279         if (pjsua_var.acc[i].valid) 
    2280             pjsua_pres_update_acc(i, PJ_FALSE); 
    2281     } 
    2282 } 
     2284    if ((flags & PJSUA_DESTROY_NO_NETWORK) == 0) { 
     2285        refresh_client_subscriptions(); 
     2286 
     2287        for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     2288            if (pjsua_var.acc[i].valid) 
     2289                pjsua_pres_update_acc(i, PJ_FALSE); 
     2290        } 
     2291    } 
     2292} 
Note: See TracChangeset for help on using the changeset viewer.