Changeset 5686 for pjproject


Ignore:
Timestamp:
Nov 9, 2017 1:49:06 AM (7 years ago)
Author:
ming
Message:

Fixed #2058: New PJSUA API to register a transport factory

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5677 r5686  
    27612761 
    27622762/** 
     2763 * Register transport factory that has been created by application. 
     2764 * This function is useful if application wants to implement custom SIP 
     2765 * transport and use it with pjsua. 
     2766 * 
     2767 * @param tf            Transport factory instance. 
     2768 * @param p_id          Optional pointer to receive transport ID. 
     2769 * 
     2770 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     2771 */ 
     2772PJ_DEF(pj_status_t) pjsua_tpfactory_register( pjsip_tpfactory *tf, 
     2773                                              pjsua_transport_id *p_id); 
     2774 
     2775/** 
    27632776 * Enumerate all transports currently created in the system. This function 
    27642777 * will return all transport IDs, and application may then call  
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r5649 r5686  
    20692069    } 
    20702070    pjsua_acc_on_tp_state_changed(tp, state, info); 
     2071} 
     2072 
     2073/* Set transport state callback */ 
     2074static void set_tp_state_cb() 
     2075{ 
     2076    pjsip_tp_state_callback tpcb; 
     2077    pjsip_tpmgr *tpmgr; 
     2078 
     2079    tpmgr = pjsip_endpt_get_tpmgr(pjsua_var.endpt); 
     2080    tpcb = pjsip_tpmgr_get_state_cb(tpmgr); 
     2081 
     2082    if (tpcb != &on_tp_state_callback) { 
     2083        pjsua_var.old_tp_cb = tpcb; 
     2084        pjsip_tpmgr_set_state_cb(tpmgr, &on_tp_state_callback); 
     2085    } 
    20712086} 
    20722087 
     
    24522467 
    24532468    /* Set transport state callback */ 
    2454     { 
    2455         pjsip_tp_state_callback tpcb; 
    2456         pjsip_tpmgr *tpmgr; 
    2457  
    2458         tpmgr = pjsip_endpt_get_tpmgr(pjsua_var.endpt); 
    2459         tpcb = pjsip_tpmgr_get_state_cb(tpmgr); 
    2460  
    2461         if (tpcb != &on_tp_state_callback) { 
    2462             pjsua_var.old_tp_cb = tpcb; 
    2463             pjsip_tpmgr_set_state_cb(tpmgr, &on_tp_state_callback); 
    2464         } 
    2465     } 
     2469    set_tp_state_cb(); 
    24662470 
    24672471    /* Return the ID */ 
     
    25042508    pjsua_var.tpdata[id].local_name = tp->local_name; 
    25052509    pjsua_var.tpdata[id].data.tp = tp; 
     2510 
     2511    /* Set transport state callback */ 
     2512    set_tp_state_cb(); 
     2513 
     2514    /* Return the ID */ 
     2515    if (p_id) *p_id = id; 
     2516 
     2517    PJSUA_UNLOCK(); 
     2518 
     2519    return PJ_SUCCESS; 
     2520} 
     2521 
     2522 
     2523/* 
     2524 * Register transport factory that has been created by application. 
     2525 */ 
     2526PJ_DEF(pj_status_t) pjsua_tpfactory_register( pjsip_tpfactory *tf, 
     2527                                              pjsua_transport_id *p_id) 
     2528{ 
     2529    unsigned id; 
     2530 
     2531    PJSUA_LOCK(); 
     2532 
     2533    /* Find empty transport slot */ 
     2534    for (id=0; id < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++id) { 
     2535        if (pjsua_var.tpdata[id].data.ptr == NULL) 
     2536            break; 
     2537    } 
     2538 
     2539    if (id == PJ_ARRAY_SIZE(pjsua_var.tpdata)) { 
     2540        pjsua_perror(THIS_FILE, "Error creating transport", PJ_ETOOMANY); 
     2541        PJSUA_UNLOCK(); 
     2542        return PJ_ETOOMANY; 
     2543    } 
     2544 
     2545    /* Save the transport */ 
     2546    pjsua_var.tpdata[id].type = (pjsip_transport_type_e) tf->type; 
     2547    pjsua_var.tpdata[id].local_name = tf->addr_name; 
     2548    pjsua_var.tpdata[id].data.factory = tf; 
     2549 
     2550    /* Set transport state callback */ 
     2551    set_tp_state_cb(); 
    25062552 
    25072553    /* Return the ID */ 
Note: See TracChangeset for help on using the changeset viewer.