From c25863d18e273d92f61550f7dccf9a54c81dd9b8 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 31 Oct 2007 10:54:53 +0000 Subject: Ticket #406: New PJSUA API to update buddy's presence subscription git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1535 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsua-lib/pjsua.h | 23 +++++++++++++++++++++++ pjsip/src/pjsua-lib/pjsua_pres.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'pjsip') diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index bb2eb3d7..579d722f 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -3333,6 +3333,29 @@ PJ_DECL(pj_status_t) pjsua_buddy_subscribe_pres(pjsua_buddy_id buddy_id, pj_bool_t subscribe); +/** + * Update the presence information for the buddy. Although the library + * periodically refreshes the presence subscription for all buddies, some + * application may want to refresh the buddy's presence subscription + * immediately, and in this case it can use this function to accomplish + * this. + * + * Note that the buddy's presence subscription will only be initiated + * if presence monitoring is enabled for the buddy. See + * #pjsua_buddy_subscribe_pres() for more info. Also if presence subscription + * for the buddy is already active, this function will not do anything. + * + * Once the presence subscription is activated successfully for the buddy, + * application will be notified about the buddy's presence status in the + * on_buddy_state() callback. + * + * @param buddy_id Buddy identification. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjsua_buddy_update_pres(pjsua_buddy_id buddy_id); + + /** * Dump presence subscriptions to log. * diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c index 0d750e07..482be7e9 100644 --- a/pjsip/src/pjsua-lib/pjsua_pres.c +++ b/pjsip/src/pjsua-lib/pjsua_pres.c @@ -310,6 +310,42 @@ PJ_DEF(pj_status_t) pjsua_buddy_subscribe_pres( pjsua_buddy_id buddy_id, } +/* + * Update buddy's presence. + */ +PJ_DEF(pj_status_t) pjsua_buddy_update_pres(pjsua_buddy_id buddy_id) +{ + pjsua_buddy *buddy; + + PJ_ASSERT_RETURN(buddy_id>=0 && + buddy_id<(int)PJ_ARRAY_SIZE(pjsua_var.buddy), + PJ_EINVAL); + + PJSUA_LOCK(); + + buddy = &pjsua_var.buddy[buddy_id]; + + /* Return error if buddy's presence monitoring is not enabled */ + if (!buddy->monitor) { + PJSUA_UNLOCK(); + return PJ_EINVALIDOP; + } + + /* Ignore if presence is already active for the buddy */ + if (buddy->sub) { + PJSUA_UNLOCK(); + return PJ_SUCCESS; + } + + /* Initiate presence subscription */ + subscribe_buddy_presence(buddy_id); + + PJSUA_UNLOCK(); + + return PJ_SUCCESS; +} + + /* * Dump presence subscriptions to log file. */ -- cgit v1.2.3