summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsua-lib/pjsua_core.c
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2012-01-09 11:51:56 +0000
committerLiong Sauw Ming <ming@teluu.com>2012-01-09 11:51:56 +0000
commitca35d13e6b2018cf6c5423bda2c0c59122aac7f0 (patch)
treea661020f7d3ababf80abf54c074cf324dc89ce31 /pjsip/src/pjsua-lib/pjsua_core.c
parent4e026426606ca3ac4d438284ca70326ed7ffc2fe (diff)
Fixes #1442: Unable to make call if disabled media is included
Add an API pjsua_schedule_timer2() to allow application to schedule a callback function to be executed after a specified time interval. This enables app to post a delayed job which, in this case, allows the initialization of all media transport creations to finish first before we get the media transport creations result. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3938 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsua-lib/pjsua_core.c')
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index fc47121d..2806123b 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -712,6 +712,18 @@ PJ_DEF(pj_status_t) pjsua_create(void)
&pjsua_var.endpt);
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
+ /* Init timer entry list */
+ pj_list_init(&pjsua_var.timer_list);
+
+ /* Create timer mutex */
+ status = pj_mutex_create_recursive(pjsua_var.pool, "pjsua_timer",
+ &pjsua_var.timer_mutex);
+ if (status != PJ_SUCCESS) {
+ pj_log_pop_indent();
+ pjsua_perror(THIS_FILE, "Unable to create mutex", status);
+ return status;
+ }
+
pjsua_set_state(PJSUA_STATE_CREATED);
pj_log_pop_indent();
return PJ_SUCCESS;
@@ -2603,6 +2615,59 @@ PJ_DEF(pj_status_t) pjsua_schedule_timer( pj_timer_entry *entry,
return pjsip_endpt_schedule_timer(pjsua_var.endpt, entry, delay);
}
+/* Timer callback */
+static void timer_cb( pj_timer_heap_t *th,
+ pj_timer_entry *entry)
+{
+ struct timer_list *tmr = (struct timer_list *)entry->user_data;
+ void (*cb)(void *user_data) = tmr->cb;
+ void *user_data = tmr->user_data;
+
+ PJ_UNUSED_ARG(th);
+
+ pj_mutex_lock(pjsua_var.timer_mutex);
+ pj_list_push_back(&pjsua_var.timer_list, tmr);
+ pj_mutex_unlock(pjsua_var.timer_mutex);
+
+ if (cb)
+ (*cb)(user_data);
+}
+
+/*
+ * Schedule a timer callback.
+ */
+PJ_DEF(pj_status_t) pjsua_schedule_timer2( void (*cb)(void *user_data),
+ void *user_data,
+ unsigned msec_delay)
+{
+ struct timer_list *tmr = NULL;
+ pj_status_t status;
+ pj_time_val delay;
+
+ pj_mutex_lock(pjsua_var.timer_mutex);
+
+ if (pj_list_empty(&pjsua_var.timer_list)) {
+ tmr = PJ_POOL_ALLOC_T(pjsua_var.pool, struct timer_list);
+ } else {
+ tmr = pjsua_var.timer_list.next;
+ pj_list_erase(tmr);
+ }
+ pj_timer_entry_init(&tmr->entry, 0, tmr, timer_cb);
+ tmr->cb = cb;
+ tmr->user_data = user_data;
+ delay.sec = 0;
+ delay.msec = msec_delay;
+
+ status = pjsip_endpt_schedule_timer(pjsua_var.endpt, &tmr->entry, &delay);
+ if (status != PJ_SUCCESS) {
+ pj_list_push_back(&pjsua_var.timer_list, tmr);
+ }
+
+ pj_mutex_unlock(pjsua_var.timer_mutex);
+
+ return status;
+}
+
/*
* Cancel the previously scheduled timer.
*