Ignore:
Timestamp:
Feb 7, 2006 12:34:11 PM (18 years ago)
Author:
bennylp
Message:

Initial implementation of invite session abstraction, and updated pjsua for the new framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_transaction.c

    r130 r139  
    3232 
    3333#define THIS_FILE   "sip_transaction.c" 
     34 
     35#if 0 
     36#define TSX_TRACE_(expr)    PJ_LOG(3,expr) 
     37#else 
     38#define TSX_TRACE_(expr) 
     39#endif 
     40 
    3441 
    3542/***************************************************************************** 
     
    505512    pj_mutex_lock(mod_tsx_layer.mutex); 
    506513 
    507     /* Check if no transaction with the same key exists. */ 
    508     PJ_ASSERT_ON_FAIL(pj_hash_get( mod_tsx_layer.htable,  
    509                                    &tsx->transaction_key.ptr, 
    510                                    tsx->transaction_key.slen,  
    511                                    &tsx->hashed_key) == NULL, 
    512                         { 
    513                             pj_mutex_unlock(mod_tsx_layer.mutex); 
    514                             return PJ_EEXISTS; 
    515                         } 
    516                       ); 
     514    /* Check if no transaction with the same key exists.  
     515     * Do not use PJ_ASSERT_RETURN since it evaluates the expression 
     516     * twice! 
     517     */ 
     518    pj_assert(pj_hash_get( mod_tsx_layer.htable,  
     519                           &tsx->transaction_key.ptr, 
     520                           tsx->transaction_key.slen,  
     521                           NULL) == NULL); 
     522 
     523    TSX_TRACE_((THIS_FILE,  
     524                "Transaction %p registered with hkey=0x%p and key=%.*s", 
     525                tsx, tsx->hashed_key, tsx->transaction_key.slen, 
     526                tsx->transaction_key.ptr)); 
    517527 
    518528    /* Register the transaction to the hash table. */ 
     529    //pj_hash_set( tsx->pool, mod_tsx_layer.htable, tsx->transaction_key.ptr, 
     530    //           tsx->transaction_key.slen, tsx->hashed_key, tsx); 
     531    PJ_TODO(USE_PRECALCULATED_HASHED_VALUE); 
    519532    pj_hash_set( tsx->pool, mod_tsx_layer.htable, tsx->transaction_key.ptr, 
    520                  tsx->transaction_key.slen, tsx->hashed_key, tsx); 
     533                 tsx->transaction_key.slen, 0, tsx); 
    521534 
    522535    /* Unlock mutex. */ 
     
    539552 
    540553    /* Register the transaction to the hash table. */ 
     554    //pj_hash_set( NULL, mod_tsx_layer.htable, tsx->transaction_key.ptr, 
     555    //           tsx->transaction_key.slen, tsx->hashed_key, NULL); 
     556    PJ_TODO(USE_PRECALCULATED_HASHED_VALUE); 
    541557    pj_hash_set( NULL, mod_tsx_layer.htable, tsx->transaction_key.ptr, 
    542                  tsx->transaction_key.slen, tsx->hashed_key, NULL); 
     558                 tsx->transaction_key.slen, 0, NULL); 
     559 
     560    TSX_TRACE_((THIS_FILE,  
     561                "Transaction %p unregistered, hkey=0x%p and key=%.*s", 
     562                tsx, tsx->hashed_key, tsx->transaction_key.slen, 
     563                tsx->transaction_key.ptr)); 
    543564 
    544565    /* Unlock mutex. */ 
     
    554575{ 
    555576    pjsip_transaction *tsx; 
     577    pj_uint32_t hval = 0; 
    556578 
    557579    pj_mutex_lock(mod_tsx_layer.mutex); 
    558     tsx = pj_hash_get( mod_tsx_layer.htable, key->ptr, key->slen, NULL ); 
     580    tsx = pj_hash_get( mod_tsx_layer.htable, key->ptr, key->slen, &hval ); 
    559581    pj_mutex_unlock(mod_tsx_layer.mutex); 
    560582 
     583    TSX_TRACE_((THIS_FILE,  
     584                "Finding tsx with hkey=0x%p and key=%.*s: found %p", 
     585                hval, key->slen, key->ptr, tsx)); 
    561586 
    562587    /* Race condition! 
     
    642667{ 
    643668    pj_str_t key; 
     669    pj_uint32_t hval = 0; 
    644670    pjsip_transaction *tsx; 
    645671 
     
    650676    pj_mutex_lock( mod_tsx_layer.mutex ); 
    651677 
    652     tsx = pj_hash_get( mod_tsx_layer.htable, key.ptr, key.slen, NULL ); 
     678    tsx = pj_hash_get( mod_tsx_layer.htable, key.ptr, key.slen, &hval ); 
     679 
     680 
     681    TSX_TRACE_((THIS_FILE,  
     682                "Finding tsx for request, hkey=0x%p and key=%.*s, found %p", 
     683                hval, key.slen, key.ptr, tsx)); 
     684 
    653685 
    654686    if (tsx == NULL || tsx->state == PJSIP_TSX_STATE_TERMINATED) { 
     
    683715{ 
    684716    pj_str_t key; 
     717    pj_uint32_t hval = 0; 
    685718    pjsip_transaction *tsx; 
    686719 
     
    691724    pj_mutex_lock( mod_tsx_layer.mutex ); 
    692725 
    693     tsx = pj_hash_get( mod_tsx_layer.htable, key.ptr, key.slen, NULL ); 
     726    tsx = pj_hash_get( mod_tsx_layer.htable, key.ptr, key.slen, &hval ); 
     727 
     728 
     729    TSX_TRACE_((THIS_FILE,  
     730                "Finding tsx for response, hkey=0x%p and key=%.*s, found %p", 
     731                hval, key.slen, key.ptr, tsx)); 
     732 
    694733 
    695734    if (tsx == NULL || tsx->state == PJSIP_TSX_STATE_TERMINATED) { 
     
    919958    } 
    920959 
    921     /* Inform TU */ 
     960    /* Before informing TU about state changed, inform TU about 
     961     * rx event. 
     962     */ 
     963    if (event_src_type==PJSIP_EVENT_RX_MSG && tsx->tsx_user) { 
     964        pjsip_rx_data *rdata = event_src; 
     965 
     966        pj_assert(rdata != NULL); 
     967 
     968        if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG && 
     969            tsx->tsx_user->on_rx_request) 
     970        { 
     971            (*tsx->tsx_user->on_rx_request)(rdata); 
     972 
     973        } else if (rdata->msg_info.msg->type == PJSIP_RESPONSE_MSG && 
     974                   tsx->tsx_user->on_rx_response) 
     975        { 
     976            (*tsx->tsx_user->on_rx_response)(rdata); 
     977        } 
     978 
     979    } 
     980 
     981    /* Inform TU about state changed. */ 
    922982    if (tsx->tsx_user && tsx->tsx_user->on_tsx_state) { 
    923983        pjsip_event e; 
     
    10451105 
    10461106    /* Calculate hashed key value. */ 
     1107    PJ_TODO(OPTIMIZE_TSX_BY_PRECALCULATING_HASHED_KEY_VALUE); 
     1108    /* 
     1109     blp: somehow this yields different hashed value!! 
     1110 
    10471111    tsx->hashed_key = pj_hash_calc(0, tsx->transaction_key.ptr, 
    10481112                                   tsx->transaction_key.slen); 
     1113     */ 
    10491114 
    10501115    PJ_LOG(6, (tsx->obj_name, "tsx_key=%.*s", tsx->transaction_key.slen, 
     
    11591224 
    11601225    /* Calculate hashed key value. */ 
     1226    PJ_TODO(OPTIMIZE_TSX_BY_PRECALCULATING_HASHED_KEY_VALUE); 
     1227    /* 
     1228     blp: somehow this yields different hashed value!! 
     1229 
    11611230    tsx->hashed_key = pj_hash_calc(0, tsx->transaction_key.ptr, 
    11621231                                   tsx->transaction_key.slen); 
     1232     */ 
    11631233 
    11641234    /* Duplicate branch parameter for transaction. */ 
Note: See TracChangeset for help on using the changeset viewer.