2013-07-26 33 views
0

我試圖做一個簡單的計時器,當它的時間到來時觸發特定的回調。 我寫了這個代碼:pjsip pj_timer_heap_schedule崩潰

void testTimer() 
{ 
    pj_timer_heap_t *timer_heap; 
    pj_timer_entry registrationTimer; 
    char *username="test_data"; 
    pj_timer_entry_init(&registrationTimer, 50, username, &on_timer_event); 
    pj_time_val delay; 
    delay.sec = 5; 
    delay.msec = 0; 
    pj_status_t status = pj_timer_heap_create(global.pool, 256, &timer_heap); 
    status=pj_timer_heap_schedule(timer_heap,&registrationTimer, &delay); 
} 

我不知道什麼是錯的代碼。此代碼在pj_timer_heap_schedule上崩潰。我無法弄清楚缺少什麼。請幫助。

+0

你說的*崩潰意味着*? – nouney

+0

我正在導出一個包含一些方法作爲DLL文件的類,我從C#應用程序中使用它,當我調用testTimer()時,我的C sharp應用程序崩潰。 –

+0

對'pj_timer_heap_create'的調用失敗,並且你正在將'timer_heap'傳遞給'pj_timer_heap_schedule'?除此之外,您可能想嘗試pjsua_schedule_timer(請參閱http://www.pjsip.org/pjsip/docs/html/group__PJSUA__LIB__BASE.htm#ga4b3f7529ece820df563c4b1a4f4a649b)。使用更簡單。最後,我認爲你的代碼有另一個bug:'registrationTimer'將會超出範圍,而且我記得,它必須保持有效,直到回調觸發。 – chr

回答

0

這是一個有點不可能知道這個問題不

pj_timer_heap_schedule

功能

+1

它是標題中提到的'pjsip'的一部分。 PJSIP是開源的。見http://www.pjsip.org/。 – chr

0

嘗試並初始化爲

`pj_bzero(&registrationTimer, sizeof(registrationTimer));` 

然後確保你做

`registrationTimer.id = PJSUA_INVALID_ID;` 
`registrationTimer.cb = &my_callback;` 

最後別忘了定義和申報回調 my_callback

好運