From 7a5f5106af3405dae1a2869c8b6445e145f6de40 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 29 May 2007 00:33:09 +0000 Subject: [PATCH] Fixed ticket #91: timer to re-subscribe buddy's presence when subscription failed git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1311 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsua-lib/pjsua_internal.h | 3 ++ pjsip/src/pjsua-lib/pjsua_pres.c | 40 +++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index fae345e1e..a2195d58f 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -206,6 +206,9 @@ struct pjsua_data unsigned buddy_cnt; /**< Buddy count. */ pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */ + /* Presence: */ + pj_timer_entry pres_timer;/**< Presence refresh timer. */ + /* Media: */ pjsua_media_config media_cfg; /**< Media config. */ pjmedia_endpt *med_endpt; /**< Media endpoint. */ diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c index 364d33d76..4809e9ab2 100644 --- a/pjsip/src/pjsua-lib/pjsua_pres.c +++ b/pjsip/src/pjsua-lib/pjsua_pres.c @@ -22,6 +22,10 @@ #define THIS_FILE "pjsua_pres.c" +#ifndef PJSUA_PRES_TIMER +# define PJSUA_PRES_TIMER 120 +#endif + /* * Get total number of buddies. @@ -1133,6 +1137,25 @@ static void refresh_client_subscriptions(void) } } +/* Timer callback to re-create client subscription */ +static void pres_timer_cb(pj_timer_heap_t *th, + pj_timer_entry *entry) +{ + pj_time_val delay = { PJSUA_PRES_TIMER, 0 }; + + PJ_UNUSED_ARG(th); + + PJSUA_LOCK(); + + entry->id = PJ_FALSE; + refresh_client_subscriptions(); + + pjsip_endpt_schedule_timer(pjsua_var.endpt, entry, &delay); + entry->id = PJ_TRUE; + + PJSUA_UNLOCK(); +} + /* * Init presence @@ -1161,7 +1184,17 @@ pj_status_t pjsua_pres_init() */ pj_status_t pjsua_pres_start(void) { - /* Nothing to do (is it?) */ + /* Start presence timer to re-subscribe to buddy's presence when + * subscription has failed. + */ + if (pjsua_var.pres_timer.id == PJ_FALSE) { + pj_time_val pres_interval = {PJSUA_PRES_TIMER, 0}; + + pjsua_var.pres_timer.cb = &pres_timer_cb; + pjsip_endpt_schedule_timer(pjsua_var.endpt, &pjsua_var.pres_timer, + &pres_interval); + } + return PJ_SUCCESS; } @@ -1189,6 +1222,11 @@ void pjsua_pres_shutdown(void) { unsigned i; + if (pjsua_var.pres_timer.id != 0) { + pjsip_endpt_cancel_timer(pjsua_var.endpt, &pjsua_var.pres_timer); + pjsua_var.pres_timer.id = PJ_FALSE; + } + for (i=0; i