Commit c979eeaa authored by Ghislain MARY's avatar Ghislain MARY

Rework presence to remove online and offline virtual activities and introduce...

Rework presence to remove online and offline virtual activities and introduce consolidated presence.
parent 87871f56
......@@ -504,7 +504,8 @@ void linphone_friend_invalidate_subscription(LinphoneFriend *lf){
while (iterator) {
LinphoneFriendPresence *lfp = (LinphoneFriendPresence *)bctbx_list_get_data(iterator);
linphone_presence_model_unref(lfp->presence);
lfp->presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline, "unknown activity");
lfp->presence = linphone_presence_model_new();
linphone_presence_model_set_basic_status(lfp->presence, LinphonePresenceBasicStatusClosed);
linphone_core_notify_notify_presence_received_for_uri_or_tel(lc, lf, lfp->uri_or_tel, lfp->presence);
iterator = bctbx_list_next(iterator);
}
......@@ -649,13 +650,6 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){
case LinphonePresenceActivityUnknown:
/* Rely on the basic status information. */
break;
case LinphonePresenceActivityOnline:
/* Should not happen! */
/*ms_warning("LinphonePresenceActivityOnline should not happen here!");*/
break;
case LinphonePresenceActivityOffline:
online_status = LinphoneStatusOffline;
break;
}
}
}
......@@ -688,6 +682,12 @@ const LinphonePresenceModel * linphone_friend_get_presence_model(const LinphoneF
return presence;
}
LinphoneConsolidatedPresence linphone_friend_get_consolidated_presence(const LinphoneFriend *lf) {
const LinphonePresenceModel *model = linphone_friend_get_presence_model(lf);
if (!model) return LinphoneConsolidatedPresenceOffline;
return linphone_presence_model_get_consolidated_presence(model);
}
const LinphonePresenceModel * linphone_friend_get_presence_model_for_uri_or_tel(const LinphoneFriend *lf, const char *uri_or_tel) {
LinphoneFriendPresence *lfp = find_presence_model_for_uri_or_tel(lf, uri_or_tel);
if (lfp) return lfp->presence;
......
......@@ -92,6 +92,7 @@ int main(int argc, char *argv[]){
char* password=NULL;
LinphoneFriend* my_friend=NULL;
LinphonePresenceModel *model;
/* takes sip uri identity from the command line arguments */
if (argc>1){
......@@ -173,7 +174,10 @@ int main(int argc, char *argv[]){
}
/*set my status to online*/
linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOnline, NULL));
model = linphone_presence_model_new();
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusOpen);
linphone_core_set_presence_model(lc, model);
linphone_presence_model_unref(model);
/* main loop for receiving notifications and doing background linphone core work: */
while(running){
......@@ -182,7 +186,10 @@ int main(int argc, char *argv[]){
}
/* change my presence status to offline*/
linphone_core_set_presence_model(lc, linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline, NULL));
model = linphone_presence_model_new();
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusClosed);
linphone_core_set_presence_model(lc, model);
linphone_presence_model_unref(model);
linphone_core_iterate(lc); /* just to make sure new status is initiate message is issued */
linphone_friend_edit(my_friend); /* start editing friend */
......
......@@ -1934,7 +1934,8 @@ static void linphone_core_start(LinphoneCore * lc) {
sip_config_read(lc);
video_config_read(lc);
//autoreplier_config_init(&lc->autoreplier_conf);
lc->presence_model=linphone_presence_model_new_with_activity(LinphonePresenceActivityOnline, NULL);
lc->presence_model=linphone_presence_model_new();
linphone_presence_model_set_basic_status(lc->presence_model, LinphonePresenceBasicStatusOpen);
misc_config_read(lc);
ui_config_read(lc);
#ifdef TUNNEL_ENABLED
......@@ -3628,18 +3629,20 @@ void linphone_core_set_delayed_timeout(LinphoneCore *lc, int seconds){
void linphone_core_set_presence_info(LinphoneCore *lc, int minutes_away, const char *contact, LinphoneOnlineStatus os) {
LinphonePresenceModel *presence = NULL;
LinphonePresenceActivity *activity = NULL;
char *description = NULL;
LinphonePresenceActivityType acttype = LinphonePresenceActivityUnknown;
if (minutes_away>0) lc->minutes_away=minutes_away;
presence = linphone_presence_model_new();
linphone_presence_model_set_basic_status(presence, LinphonePresenceBasicStatusOpen);
switch (os) {
case LinphoneStatusOffline:
acttype = LinphonePresenceActivityOffline;
break;
linphone_presence_model_set_basic_status(presence, LinphonePresenceBasicStatusClosed);
goto end;
case LinphoneStatusOnline:
acttype = LinphonePresenceActivityOnline;
break;
goto end;
case LinphoneStatusBusy:
acttype = LinphonePresenceActivityBusy;
break;
......@@ -3658,6 +3661,7 @@ void linphone_core_set_presence_info(LinphoneCore *lc, int minutes_away, const c
case LinphoneStatusDoNotDisturb:
acttype = LinphonePresenceActivityBusy;
description = "Do not disturb";
linphone_presence_model_set_basic_status(presence, LinphonePresenceBasicStatusClosed);
break;
case LinphoneStatusMoved:
acttype = LinphonePresenceActivityPermanentAbsence;
......@@ -3677,9 +3681,14 @@ void linphone_core_set_presence_info(LinphoneCore *lc, int minutes_away, const c
ms_warning("Invalid status LinphoneStatusEnd");
return;
}
presence = linphone_presence_model_new_with_activity(acttype, description);
activity = linphone_presence_activity_new(acttype, description);
linphone_presence_model_add_activity(presence, activity);
linphone_presence_activity_unref(activity);
end:
linphone_presence_model_set_contact(presence, contact);
linphone_core_set_presence_model(lc, presence);
linphone_presence_model_unref(presence);
}
void linphone_core_send_presence(LinphoneCore *lc, LinphonePresenceModel *presence){
......@@ -3688,12 +3697,10 @@ void linphone_core_send_presence(LinphoneCore *lc, LinphonePresenceModel *presen
}
void linphone_core_set_presence_model(LinphoneCore *lc, LinphonePresenceModel *presence) {
linphone_core_send_presence(lc,presence);
if ((lc->presence_model != NULL) && (lc->presence_model != presence)) {
linphone_presence_model_unref(lc->presence_model);
lc->presence_model = presence;
}
linphone_presence_model_ref(presence);
linphone_core_send_presence(lc, presence);
if (lc->presence_model != NULL) linphone_presence_model_unref(lc->presence_model);
lc->presence_model = presence;
}
LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
......@@ -3704,10 +3711,6 @@ LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
if (activity) {
description = linphone_presence_activity_get_description(activity);
switch (linphone_presence_activity_get_type(activity)) {
case LinphonePresenceActivityOffline:
return LinphoneStatusOffline;
case LinphonePresenceActivityOnline:
return LinphoneStatusOnline;
case LinphonePresenceActivityBusy:
if (description != NULL) {
if (strcmp(description, "Do not disturb") == 0)
......@@ -3757,6 +3760,53 @@ LinphonePresenceModel * linphone_core_get_presence_model(const LinphoneCore *lc)
return lc->presence_model;
}
LinphoneConsolidatedPresence linphone_core_get_consolidated_presence(const LinphoneCore *lc) {
LinphoneProxyConfig *cfg = lc->default_proxy;
if ((cfg != NULL) && !linphone_proxy_config_publish_enabled(cfg)) return LinphoneConsolidatedPresenceOffline;
return linphone_presence_model_get_consolidated_presence(linphone_core_get_presence_model(lc));
}
void linphone_core_set_consolidated_presence(LinphoneCore *lc, LinphoneConsolidatedPresence presence) {
LinphoneProxyConfig *cfg;
LinphonePresenceModel *model;
LinphonePresenceActivity *activity = NULL;
cfg = linphone_core_get_default_proxy_config(lc);
if ((cfg != NULL) && (presence == LinphoneConsolidatedPresenceOffline) && linphone_proxy_config_publish_enabled(cfg)) {
/* Unpublish when going offline before changing the presence model. */
linphone_proxy_config_edit(cfg);
linphone_proxy_config_enable_publish(cfg, FALSE);
linphone_proxy_config_done(cfg);
}
model = linphone_presence_model_new();
switch (presence) {
case LinphoneConsolidatedPresenceOnline:
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusOpen);
break;
case LinphoneConsolidatedPresenceBusy:
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusOpen);
activity = linphone_presence_activity_new(LinphonePresenceActivityAway, NULL);
break;
case LinphoneConsolidatedPresenceDoNotDisturb:
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusClosed);
activity = linphone_presence_activity_new(LinphonePresenceActivityAway, NULL);
break;
case LinphoneConsolidatedPresenceOffline:
default:
linphone_presence_model_set_basic_status(model, LinphonePresenceBasicStatusClosed);
break;
}
if (activity != NULL) linphone_presence_model_add_activity(model, activity);
linphone_core_set_presence_model(lc, model);
linphone_presence_model_unref(model);
if ((cfg != NULL) && (presence != LinphoneConsolidatedPresenceOffline) && !linphone_proxy_config_publish_enabled(cfg)) {
/* When going online or busy, publish after changing the presence model. */
linphone_proxy_config_edit(cfg);
linphone_proxy_config_enable_publish(cfg, TRUE);
linphone_proxy_config_done(cfg);
}
}
int linphone_core_get_play_level(LinphoneCore *lc) {
return lc->sound_conf.play_lev;
}
......
This diff is collapsed.
......@@ -853,7 +853,7 @@ int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy, LinphonePrese
}
if (!(presence_body = linphone_presence_model_to_xml(presence))) {
ms_error("Cannot publish presence model [%p] for proxy config [%p] because of xml serilization error",presence,proxy);
ms_error("Cannot publish presence model [%p] for proxy config [%p] because of xml serialization error",presence,proxy);
return -1;
}
......
......@@ -4813,6 +4813,20 @@ LINPHONE_PUBLIC LinphoneOnlineStatus linphone_core_get_presence_info(const Linph
*/
LINPHONE_PUBLIC LinphonePresenceModel * linphone_core_get_presence_model(const LinphoneCore *lc);
/**
* Get my consolidated presence
* @param[in] lc LinphoneCore object
* @return My consolidated presence
*/
LINPHONE_PUBLIC LinphoneConsolidatedPresence linphone_core_get_consolidated_presence(const LinphoneCore *lc);
/**
* Set my consolidated presence
* @param[in] lc LinphoneCore object
* @param[in] presence LinphoneConsolidatedPresence value
*/
LINPHONE_PUBLIC void linphone_core_set_consolidated_presence(LinphoneCore *lc, LinphoneConsolidatedPresence presence);
/**
* @deprecated Use linphone_core_interpret_url() instead
*/
......
......@@ -209,6 +209,13 @@ LINPHONE_PUBLIC LinphoneSubscriptionState linphone_friend_get_subscription_state
*/
LINPHONE_PUBLIC const LinphonePresenceModel * linphone_friend_get_presence_model(const LinphoneFriend *lf);
/**
* Get the consolidated presence of a friend.
* @param[in] lf LinphoneFriend object
* @return The consolidated presence of the friend
*/
LINPHONE_PUBLIC LinphoneConsolidatedPresence linphone_friend_get_consolidated_presence(const LinphoneFriend *lf);
/**
* Get the presence model for a specific SIP URI or phone number of a friend
* @param[in] lf A #LinphoneFriend object
......
......@@ -195,6 +195,13 @@ LINPHONE_PUBLIC int linphone_presence_model_add_note(LinphonePresenceModel *mode
*/
LINPHONE_PUBLIC int linphone_presence_model_clear_notes(LinphonePresenceModel *model);
/**
* Get the consolidated presence from a presence model.
* @param[in] model LinphonePresenceModel object
* @return The LinphoneConsolidatedPresence corresponding to the presence model
*/
LINPHONE_PUBLIC LinphoneConsolidatedPresence linphone_presence_model_get_consolidated_presence(const LinphonePresenceModel *model);
/*****************************************************************************
* PRESENCE MODEL FUNCTIONS TO GET ACCESS TO ALL FUNCTIONALITIES *
......@@ -270,11 +277,30 @@ LINPHONE_PUBLIC int linphone_presence_model_add_person(LinphonePresenceModel *mo
*/
LINPHONE_PUBLIC int linphone_presence_model_clear_persons(LinphonePresenceModel *model);
/**
* Tells whether a presence model is considered online.
* It is any of theses cases:
* - basic status is'open' and no activities
* - explicit 'online' tag in the status
* @param[in] model LinphonePresenceModel object
* @return A boolean value telling whether the presence model is considered online or not.
*/
LINPHONE_PUBLIC bool_t linphone_presence_model_is_online(const LinphonePresenceModel *model);
/*****************************************************************************
* PRESENCE SERVICE FUNCTIONS TO GET ACCESS TO ALL FUNCTIONALITIES *
****************************************************************************/
/**
* Gets the string representation of a presence basic status.
* @param[in] basic_status A LinphonePresenceBasicStatus for which to get a string representation.
* @return A pointer a dynamically allocated string representing the given basic status.
*
* The returned string is to be freed by calling ms_free().
*/
char * linphone_presence_basic_status_to_string(LinphonePresenceBasicStatus basic_status);
/**
* Creates a presence service.
* @param[in] id The id of the presence service to be created. Can be NULL to generate it automatically.
......
......@@ -339,6 +339,20 @@ typedef enum _LinphoneConfiguringState {
LinphoneConfiguringSkipped
} LinphoneConfiguringState;
/**
* Consolidated presence information: 'online' means the user is open for communication,
* 'busy' means the user is open for communication but involved in an other activity,
* 'do not disturb' means the user is not open for communication, and 'offline' means
* that no presence information is available.
* @ingroup buddy_list
*/
typedef enum _LinphoneConsolidatedPresence {
LinphoneConsolidatedPresenceOnline,
LinphoneConsolidatedPresenceBusy,
LinphoneConsolidatedPresenceDoNotDisturb,
LinphoneConsolidatedPresenceOffline
} LinphoneConsolidatedPresence;
typedef struct _LinphoneContactProvider LinphoneContactProvider;
typedef struct _LinphoneContactSearch LinphoneContactSearch;
......@@ -617,12 +631,6 @@ typedef struct _LinphonePresenceActivity LinphonePresenceActivity;
* @ingroup buddy_list
*/
typedef enum LinphonePresenceActivityType {
/** This value is not defined in the RFC, it corresponds to no activity with a basic status of "closed". */
LinphonePresenceActivityOffline,
/** This value is not defined in the RFC, it corresponds to no activity with a basic status of "open". */
LinphonePresenceActivityOnline,
/** The person has a calendar appointment, without specifying exactly of what type. This activity is
* indicated if more detailed information is not available or the person chooses not to reveal more
* information. */
......
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.linphone.org/xsds/pidfonline.xsd"
xmlns:tns="http://www.linphone.org/xsds/pidfonline.xsd"
elementFormDefault="qualified">
<xs:element name="online" type="empty"></xs:element>
</xs:schema>
This diff is collapsed.
......@@ -72,10 +72,6 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {
for (i=0;counters->last_received_presence&&i<linphone_presence_model_get_nb_activities(counters->last_received_presence); i++) {
LinphonePresenceActivity *activity = linphone_presence_model_get_nth_activity(counters->last_received_presence, i);
switch (linphone_presence_activity_get_type(activity)) {
case LinphonePresenceActivityOffline:
counters->number_of_LinphonePresenceActivityOffline++; break;
case LinphonePresenceActivityOnline:
counters->number_of_LinphonePresenceActivityOnline++; break;
case LinphonePresenceActivityAppointment:
counters->number_of_LinphonePresenceActivityAppointment++; break;
case LinphonePresenceActivityAway:
......@@ -167,8 +163,10 @@ static void simple_publish_with_expire(int expires) {
BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishProgress,1));
BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishOk,1));
presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline,NULL);
presence = linphone_presence_model_new();
linphone_presence_model_set_basic_status(presence, LinphonePresenceBasicStatusClosed);
linphone_core_set_presence_model(marie->lc,presence);
linphone_presence_model_unref(presence);
BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishProgress,2));
BC_ASSERT_TRUE(wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphonePublishOk,2));
......@@ -401,6 +399,7 @@ static void presence_information(void) {
/* Presence activity without description. */
presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL);
linphone_core_set_presence_model(pauline->lc, presence);
linphone_presence_model_unref(presence);
wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityDinner,1);
BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityDinner, 1, int, "%d");
activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
......@@ -412,6 +411,7 @@ static void presence_information(void) {
/* Presence activity with description. */
presence = linphone_presence_model_new_with_activity(LinphonePresenceActivitySteering, bike_description);
linphone_core_set_presence_model(pauline->lc, presence);
linphone_presence_model_unref(presence);
wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivitySteering,1);
BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivitySteering, 1, int, "%d");
activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
......@@ -424,6 +424,7 @@ static void presence_information(void) {
/* Presence activity with description and note. */
presence = linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityVacation, NULL, vacation_note, vacation_lang);
linphone_core_set_presence_model(pauline->lc, presence);
linphone_presence_model_unref(presence);
wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityVacation,1);
BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityVacation, 1, int, "%d");
activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
......@@ -445,6 +446,7 @@ static void presence_information(void) {
presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL);
linphone_presence_model_set_contact(presence, contact);
linphone_core_set_presence_model(pauline->lc, presence);
linphone_presence_model_unref(presence);
wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnThePhone,1);
BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityOnThePhone, 1, int, "%d");
contact2 = linphone_presence_model_get_contact(presence);
......@@ -462,6 +464,7 @@ static void presence_information(void) {
BC_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityShopping, 1, int, "%d");
presence_timestamp = linphone_presence_model_get_timestamp(presence);
BC_ASSERT_GREATER((unsigned)presence_timestamp , (unsigned)current_timestamp, unsigned, "%u");
linphone_presence_model_unref(presence);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment