Commit 1b7f68b4 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Change presence API a little bit to ease wrapping for other programming languages.

parent 392b36c2
......@@ -220,28 +220,26 @@ static void call_received(SalOp *h){
/* first check if we can answer successfully to this invite */
if (linphone_presence_model_get_basic_status(lc->presence_model) == LinphonePresenceBasicStatusClosed) {
LinphonePresenceActivity activity = LinphonePresenceActivityOffline;
if (linphone_presence_model_get_activity(lc->presence_model, &activity, NULL)) {
switch (activity) {
case LinphonePresenceActivityBusy:
sal_call_decline(h,SalReasonBusy,NULL);
break;
case LinphonePresenceActivityAppointment:
case LinphonePresenceActivityMeeting:
case LinphonePresenceActivityOffline:
case LinphonePresenceActivityWorship:
sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
break;
case LinphonePresenceActivityPermanentAbsence:
if (lc->alt_contact != NULL)
sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
break;
default:
break;
}
sal_op_release(h);
return;
LinphonePresenceActivity *activity = linphone_presence_model_get_activity(lc->presence_model);
switch (linphone_presence_activity_get_type(activity)) {
case LinphonePresenceActivityBusy:
sal_call_decline(h,SalReasonBusy,NULL);
break;
case LinphonePresenceActivityAppointment:
case LinphonePresenceActivityMeeting:
case LinphonePresenceActivityOffline:
case LinphonePresenceActivityWorship:
sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL);
break;
case LinphonePresenceActivityPermanentAbsence:
if (lc->alt_contact != NULL)
sal_call_decline(h,SalReasonRedirect,lc->alt_contact);
break;
default:
break;
}
sal_op_release(h);
return;
}
if (!linphone_core_can_we_add_call(lc)){/*busy*/
......
......@@ -280,10 +280,8 @@ LinphoneSubscribePolicy linphone_friend_get_inc_subscribe_policy(const LinphoneF
LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){
LinphoneOnlineStatus online_status = LinphoneStatusOffline;
LinphonePresenceBasicStatus basic_status = LinphonePresenceBasicStatusClosed;
LinphonePresenceActivity activity = LinphonePresenceActivityUnknown;
char *activity_description = NULL;
LinphonePresenceActivity *activity = NULL;
unsigned int nb_activities = 0;
int err = 0;
if (lf->presence != NULL) {
basic_status = linphone_presence_model_get_basic_status(lf->presence);
......@@ -298,60 +296,58 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){
nb_activities = 1;
}
if (nb_activities == 1) {
err = linphone_presence_model_get_activity(lf->presence, &activity, &activity_description);
if (err == 0) {
switch (activity) {
case LinphonePresenceActivityBreakfast:
case LinphonePresenceActivityDinner:
case LinphonePresenceActivityLunch:
case LinphonePresenceActivityMeal:
online_status = LinphoneStatusOutToLunch;
break;
case LinphonePresenceActivityAppointment:
case LinphonePresenceActivityMeeting:
case LinphonePresenceActivityPerformance:
case LinphonePresenceActivityPresentation:
case LinphonePresenceActivitySpectator:
case LinphonePresenceActivityWorking:
case LinphonePresenceActivityWorship:
online_status = LinphoneStatusDoNotDisturb;
break;
case LinphonePresenceActivityAway:
case LinphonePresenceActivitySleeping:
online_status = LinphoneStatusAway;
break;
case LinphonePresenceActivityHoliday:
case LinphonePresenceActivityTravel:
case LinphonePresenceActivityVacation:
online_status = LinphoneStatusVacation;
break;
case LinphonePresenceActivityBusy:
case LinphonePresenceActivityLookingForWork:
case LinphonePresenceActivityPlaying:
case LinphonePresenceActivityShopping:
case LinphonePresenceActivityTV:
online_status = LinphoneStatusBusy;
break;
case LinphonePresenceActivityInTransit:
case LinphonePresenceActivitySteering:
online_status = LinphoneStatusBeRightBack;
break;
case LinphonePresenceActivityOnThePhone:
online_status = LinphoneStatusOnThePhone;
break;
case LinphonePresenceActivityOther:
case LinphonePresenceActivityPermanentAbsence:
online_status = LinphoneStatusMoved;
break;
case LinphonePresenceActivityUnknown:
/* Rely on the basic status information. */
break;
case LinphonePresenceActivityOnline:
case LinphonePresenceActivityOffline:
/* Should not happen! */
ms_warning("LinphonePresenceActivityOnline or LinphonePresenceActivityOffline should not happen here!");
break;
}
activity = linphone_presence_model_get_activity(lf->presence);
switch (linphone_presence_activity_get_type(activity)) {
case LinphonePresenceActivityBreakfast:
case LinphonePresenceActivityDinner:
case LinphonePresenceActivityLunch:
case LinphonePresenceActivityMeal:
online_status = LinphoneStatusOutToLunch;
break;
case LinphonePresenceActivityAppointment:
case LinphonePresenceActivityMeeting:
case LinphonePresenceActivityPerformance:
case LinphonePresenceActivityPresentation:
case LinphonePresenceActivitySpectator:
case LinphonePresenceActivityWorking:
case LinphonePresenceActivityWorship:
online_status = LinphoneStatusDoNotDisturb;
break;
case LinphonePresenceActivityAway:
case LinphonePresenceActivitySleeping:
online_status = LinphoneStatusAway;
break;
case LinphonePresenceActivityHoliday:
case LinphonePresenceActivityTravel:
case LinphonePresenceActivityVacation:
online_status = LinphoneStatusVacation;
break;
case LinphonePresenceActivityBusy:
case LinphonePresenceActivityLookingForWork:
case LinphonePresenceActivityPlaying:
case LinphonePresenceActivityShopping:
case LinphonePresenceActivityTV:
online_status = LinphoneStatusBusy;
break;
case LinphonePresenceActivityInTransit:
case LinphonePresenceActivitySteering:
online_status = LinphoneStatusBeRightBack;
break;
case LinphonePresenceActivityOnThePhone:
online_status = LinphoneStatusOnThePhone;
break;
case LinphonePresenceActivityOther:
case LinphonePresenceActivityPermanentAbsence:
online_status = LinphoneStatusMoved;
break;
case LinphonePresenceActivityUnknown:
/* Rely on the basic status information. */
break;
case LinphonePresenceActivityOnline:
case LinphonePresenceActivityOffline:
/* Should not happen! */
ms_warning("LinphonePresenceActivityOnline or LinphonePresenceActivityOffline should not happen here!");
break;
}
}
}
......
......@@ -51,15 +51,12 @@ static void stop(int signum){
* presence state change notification callback
*/
static void notify_presence_recv_updated (LinphoneCore *lc, LinphoneFriend *friend) {
LinphonePresenceActivity activity = LinphonePresenceActivityOffline;
const LinphonePresenceModel* model = linphone_friend_get_presence_model(friend);
const LinphoneAddress* friend_address = linphone_friend_get_address(friend);
char *description = NULL;
linphone_presence_model_get_activity(model, &activity, &description);
printf("New state state [%s%s%s] for user id [%s] \n"
,linphone_presence_activity_to_string(activity)
,(description == NULL) ? "" : ": "
,(description == NULL) ? "" : description
LinphonePresenceActivity *activity = linphone_presence_model_get_activity(model);
char *activity_str = linphone_presence_activity_to_string(activity);
printf("New state state [%s] for user id [%s] \n"
,activity_str
,linphone_address_as_string (friend_address));
}
static void new_subscription_request (LinphoneCore *lc, LinphoneFriend *friend, const char* url) {
......
......@@ -3645,52 +3645,52 @@ 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;
char *description = NULL;
LinphonePresenceActivity activity = LinphonePresenceActivityUnknown;
LinphonePresenceActivityType acttype = LinphonePresenceActivityUnknown;
switch (os) {
case LinphoneStatusOffline:
activity = LinphonePresenceActivityOffline;
acttype = LinphonePresenceActivityOffline;
break;
case LinphoneStatusOnline:
activity = LinphonePresenceActivityOnline;
acttype = LinphonePresenceActivityOnline;
break;
case LinphoneStatusBusy:
activity = LinphonePresenceActivityBusy;
acttype = LinphonePresenceActivityBusy;
break;
case LinphoneStatusBeRightBack:
activity = LinphonePresenceActivityInTransit;
acttype = LinphonePresenceActivityInTransit;
break;
case LinphoneStatusAway:
activity = LinphonePresenceActivityAway;
acttype = LinphonePresenceActivityAway;
break;
case LinphoneStatusOnThePhone:
activity = LinphonePresenceActivityOnThePhone;
acttype = LinphonePresenceActivityOnThePhone;
break;
case LinphoneStatusOutToLunch:
activity = LinphonePresenceActivityLunch;
acttype = LinphonePresenceActivityLunch;
break;
case LinphoneStatusDoNotDisturb:
activity = LinphonePresenceActivityBusy;
acttype = LinphonePresenceActivityBusy;
description = "Do not disturb";
break;
case LinphoneStatusMoved:
activity = LinphonePresenceActivityPermanentAbsence;
acttype = LinphonePresenceActivityPermanentAbsence;
break;
case LinphoneStatusAltService:
activity = LinphonePresenceActivityBusy;
acttype = LinphonePresenceActivityBusy;
description = "Using another messaging service";
break;
case LinphoneStatusPending:
activity = LinphonePresenceActivityOther;
acttype = LinphonePresenceActivityOther;
description = "Waiting for user acceptance";
break;
case LinphoneStatusVacation:
activity = LinphonePresenceActivityVacation;
acttype = LinphonePresenceActivityVacation;
break;
case LinphoneStatusEnd:
ms_warning("Invalid status LinphoneStatusEnd");
return;
}
presence = linphone_presence_model_new_with_activity(activity, description);
presence = linphone_presence_model_new_with_activity(acttype, description);
linphone_core_set_presence_model(lc, minutes_away, contact, presence);
}
......@@ -3718,14 +3718,12 @@ void linphone_core_set_presence_model(LinphoneCore *lc, int minutes_away, const
}
LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
LinphonePresenceActivity activity = LinphonePresenceActivityOffline;
char *description = NULL;
if ((lc->presence_model == NULL)
|| (linphone_presence_model_get_activity(lc->presence_model, &activity, &description) < 0))
return LinphoneStatusOffline;
LinphonePresenceActivity *activity = NULL;
const char *description = NULL;
switch (activity) {
activity = linphone_presence_model_get_activity(lc->presence_model);
description = linphone_presence_activity_get_description(activity);
switch (linphone_presence_activity_get_type(activity)) {
case LinphonePresenceActivityOffline:
return LinphoneStatusOffline;
case LinphonePresenceActivityOnline:
......
......@@ -138,7 +138,7 @@ typedef enum LinphonePresenceActivity {
/** The person is participating in religious rites. */
LinphonePresenceActivityWorship
} LinphonePresenceActivity;
} LinphonePresenceActivityType;
/**
* Structure holding the information about the presence of a person.
......@@ -150,6 +150,26 @@ struct _LinphonePresenceModel;
*/
typedef struct _LinphonePresenceModel LinphonePresenceModel;
/**
* Structure holding the information about a presence activity.
*/
struct _LinphonePresenceActivity;
/**
* Presence activity type holding information about a presence activity.
*/
typedef struct _LinphonePresenceActivity LinphonePresenceActivity;
/**
* Structure holding the information about a presence note.
*/
struct _LinphonePresenceNote;
/**
* Presence note type holding information about a presence note.
*/
typedef struct _LinphonePresenceNote LinphonePresenceNote;
/**
......@@ -172,7 +192,7 @@ LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new(void);
*
* The created presence model has the activity specified in the parameters.
*/
LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activity(LinphonePresenceActivity activity, const char *description);
LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activity(LinphonePresenceActivityType activity, const char *description);
/**
* @brief Creates a presence model specifying an activity and adding a note.
......@@ -186,7 +206,7 @@ LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activit
*
* The created presence model has the activity and the note specified in the parameters.
*/
LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivity activity, const char *description, const char *note, const char *lang);
LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityType activity, const char *description, const char *note, const char *lang);
/**
* @brief Deletes a presence model.
......@@ -220,39 +240,33 @@ LINPHONE_PUBLIC unsigned int linphone_presence_model_nb_activities(const Linphon
* @brief Gets the nth activity of a presence model.
* @param[in] model The #LinphonePresenceModel object to get the activity from.
* @param[in] idx The index of the activity to get (the first activity having the index 0).
* @param[out] activity The returned #LinphonePresenceActivity (may not be changed in case of error).
* @param[out] description The description of the returned #LinphonePresenceActivity (may not be changed in case of error).
* @return 0 if successful, a value < 0 in case of error.
* @return A pointer to a #LinphonePresenceActivity object if successful, NULL otherwise.
*/
LINPHONE_PUBLIC int linphone_presence_model_get_nth_activity(const LinphonePresenceModel *model, unsigned int idx, LinphonePresenceActivity *activity, char **description);
LINPHONE_PUBLIC LinphonePresenceActivity * linphone_presence_model_get_nth_activity(const LinphonePresenceModel *model, unsigned int idx);
/**
* @brief Gets the first activity of a presence model (there is usually only one).
* @param[in] model The #LinphonePresenceModel object to get the activity from.
* @param[out] activity The returned #LinphonePresenceActivity (may not be changed in case of error).
* @param[out] description The description of the returned #LinphonePresenceActivity (may not be changed in case of error).
* @return 0 if successful, a value < 0 in case of error.
* @return A #LinphonePresenceActivity object if successful, NULL otherwise.
*/
LINPHONE_PUBLIC int linphone_presence_model_get_activity(const LinphonePresenceModel *model, LinphonePresenceActivity *activity, char **description);
LINPHONE_PUBLIC LinphonePresenceActivity * linphone_presence_model_get_activity(const LinphonePresenceModel *model);
/**
* @brief Sets the activity of a presence model (limits to only one activity).
* @param[in] model The #LinphonePresenceModel object for which to set the activity.
* @param[in] activity The #LinphonePresenceActivity to set for the model.
* @param[in] activity The #LinphonePresenceActivityType to set for the model.
* @param[in] description An additional description of the activity to set for the model. Can be NULL if no additional description is to be added.
* @return 0 if successful, a value < 0 in case of error.
*/
LINPHONE_PUBLIC int linphone_presence_model_set_activity(LinphonePresenceModel *model, LinphonePresenceActivity activity, const char *description);
LINPHONE_PUBLIC int linphone_presence_model_set_activity(LinphonePresenceModel *model, LinphonePresenceActivityType activity, const char *description);
/**
* @brief Gets the first note of a presence model (there is usually only one).
* @param[in] model The #LinphonePresenceModel object to get the note from.
* @param[in] lang The language of the note to get. Can be NULL to a note that has no language specified or to get the first note whatever language it is written into.
* @return A pointer to dynamically allocated string in case of success, NULL otherwise.
*
* The string that is returned MUST be freed using ms_free().
* @return A pointer to a #LinphonePresenceNote object if successful, NULL otherwise.
*/
LINPHONE_PUBLIC char * linphone_presence_model_get_note(const LinphonePresenceModel *model, const char *lang);
LINPHONE_PUBLIC LinphonePresenceNote * linphone_presence_model_get_note(const LinphonePresenceModel *model, const char *lang);
/**
* @brief Adds a note to a presence model.
......@@ -274,10 +288,40 @@ LINPHONE_PUBLIC int linphone_presence_model_clear_notes(LinphonePresenceModel *m
/**
* @brief Gets the string representation of a presence activity.
* @param[in] activity The #LinphonePresenceActivity for which to get a string representation.
* @return A pointer to the string representing the given activity.
* @param[in] activity A pointer to the #LinphonePresenceActivity object for which to get a string representation.
* @return A pointer a dynamically allocated string representing the given activity.
*
* The returned string is to be freed by calling ms_free().
*/
LINPHONE_PUBLIC char * linphone_presence_activity_to_string(const LinphonePresenceActivity * activity);
/**
* @brief Gets the activity type of a presence activity.
* @param[in] activity A pointer to the #LinphonePresenceActivity for which to get the type.
* @return The #LinphonePresenceActivityType of the activity.
*/
LINPHONE_PUBLIC LinphonePresenceActivityType linphone_presence_activity_get_type(const LinphonePresenceActivity *activity);
/**
* @brief Gets the description of a presence activity.
* @param[in] activity A pointer to the #LinphonePresenceActivity for which to get the description.
* @return A pointer to the description string of the presence activity, or NULL if no description is specified.
*/
LINPHONE_PUBLIC const char * linphone_presence_activity_get_description(const LinphonePresenceActivity *activity);
/**
* @brief Gets the content of a presence note.
* @param[in] note A pointer to the #LinphonePresenceNote for which to get the content.
* @return A pointer to the content of the presence note.
*/
LINPHONE_PUBLIC const char * linphone_presence_note_get_content(const LinphonePresenceNote *note);
/**
* @brief Gets the language of a presence note.
* @param[in] note A pointer to the #LinphonePresenceNote for which to get the language.
* @return A pointer to the language string of the presence note, or NULL if no language is specified.
*/
LINPHONE_PUBLIC const char * linphone_presence_activity_to_string(LinphonePresenceActivity activity);
LINPHONE_PUBLIC const char * linphone_presence_note_get_lang(const LinphonePresenceNote *note);
/**
......
......@@ -48,7 +48,7 @@ struct _LinphonePresenceService {
};
struct _LinphonePresenceActivity {
LinphonePresenceActivity activity;
LinphonePresenceActivityType type;
char *description;
};
......@@ -193,9 +193,9 @@ static void presence_service_add_note(struct _LinphonePresenceService *service,
service->notes = ms_list_append(service->notes, note);
}
static struct _LinphonePresenceActivity * presence_activity_new(LinphonePresenceActivity activity, const char *description) {
static struct _LinphonePresenceActivity * presence_activity_new(LinphonePresenceActivityType acttype, const char *description) {
struct _LinphonePresenceActivity *act = ms_new0(struct _LinphonePresenceActivity, 1);
act->activity = activity;
act->type = acttype;
if (description != NULL) {
act->description = ms_strdup(description);
}
......@@ -315,15 +315,11 @@ static void presence_model_clear_activities(LinphonePresenceModel *model) {
ms_list_for_each(model->persons, (MSIterateFunc)presence_person_clear_activities);
}
static int presence_model_add_activity(LinphonePresenceModel *model, LinphonePresenceActivity activity, const char *description) {
static int presence_model_add_activity(LinphonePresenceModel *model, LinphonePresenceActivityType acttype, const char *description) {
char *id = NULL;
struct _LinphonePresencePerson *person = NULL;
struct _LinphonePresenceActivity *act = NULL;
/* Do not add activity for special cases Offline and Online. */
if ((activity == LinphonePresenceActivityOffline) || (activity == LinphonePresenceActivityOnline))
return 0;
if (ms_list_size(model->persons) == 0) {
/* There is no person in the presence model, add one. */
id = generate_presence_id();
......@@ -336,7 +332,7 @@ static int presence_model_add_activity(LinphonePresenceModel *model, LinphonePre
/* Add the activity to the first person in the model. */
person = (struct _LinphonePresencePerson *)ms_list_nth_data(model->persons, 0);
}
act = presence_activity_new(activity, description);
act = presence_activity_new(acttype, description);
if (act == NULL)
return -1;
presence_person_add_activity(person, act);
......@@ -376,7 +372,7 @@ static bool_t presence_activity_equals(const struct _LinphonePresenceActivity *a
|| ((a1->description != NULL) && (a2->description == NULL)))
return FALSE;
if (a1->activity != a2->activity)
if (a1->type != a2->type)
return FALSE;
if ((a1->description != NULL) && (a2->description != NULL)) {
......@@ -421,18 +417,18 @@ LinphonePresenceModel * linphone_presence_model_new(void) {
return ms_new0(LinphonePresenceModel, 1);
}
LinphonePresenceModel * linphone_presence_model_new_with_activity(LinphonePresenceActivity activity, const char *description) {
LinphonePresenceModel * linphone_presence_model_new_with_activity(LinphonePresenceActivityType acttype, const char *description) {
LinphonePresenceModel *model = linphone_presence_model_new();
if (model != NULL) {
linphone_presence_model_set_activity(model, activity, description);
linphone_presence_model_set_activity(model, acttype, description);
}
return model;
}
LinphonePresenceModel * linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivity activity, const char *description, const char *note, const char *lang) {
LinphonePresenceModel * linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityType acttype, const char *description, const char *note, const char *lang) {
LinphonePresenceModel *model = linphone_presence_model_new();
if (model != NULL) {
linphone_presence_model_set_activity(model, activity, description);
linphone_presence_model_set_activity(model, acttype, description);
linphone_presence_model_add_note(model, note, lang);
}
return model;
......@@ -451,7 +447,7 @@ void linphone_presence_model_delete(LinphonePresenceModel *model) {
}
bool_t linphone_presence_model_equals(const LinphonePresenceModel *m1, const LinphonePresenceModel *m2) {
LinphonePresenceActivity activity = LinphonePresenceActivityOffline;
LinphonePresenceActivity *activity = NULL;
int nb;
int i;
......@@ -461,14 +457,14 @@ bool_t linphone_presence_model_equals(const LinphonePresenceModel *m1, const Lin
/* A null activity is equal to an activity with no activity but a basic status of Closed. */
if (m1 == NULL) {
if ((linphone_presence_model_get_activity(m2, &activity, NULL) < 0)
|| (activity != LinphonePresenceActivityOffline))
activity = linphone_presence_model_get_activity(m2);
if (linphone_presence_activity_get_type(activity) != LinphonePresenceActivityOffline)
return FALSE;
return TRUE;
}
if (m2 == NULL) {
if ((linphone_presence_model_get_activity(m2, &activity, NULL) < 0)
|| (activity != LinphonePresenceActivityOffline))
activity = linphone_presence_model_get_activity(m2);
if (linphone_presence_activity_get_type(activity) != LinphonePresenceActivityOffline)
return FALSE;
return TRUE;
}
......@@ -521,64 +517,41 @@ unsigned int linphone_presence_model_nb_activities(const LinphonePresenceModel *
struct _get_activity_st {
unsigned int requested_idx;
unsigned int current_idx;
LinphonePresenceActivity *activity;
char **description;
struct _LinphonePresenceActivity *activity;
};
static void presence_model_get_activity(const struct _LinphonePresencePerson *person, struct _get_activity_st *st) {
struct _LinphonePresenceActivity *activity;
unsigned int size = ms_list_size(person->activities);
if (st->requested_idx < (st->current_idx + size)) {
activity = (struct _LinphonePresenceActivity *)ms_list_nth_data(person->activities, st->requested_idx - st->current_idx);
*st->activity = activity->activity;
if (st->description != NULL) {
*st->description = activity->description;
}
st->activity = (struct _LinphonePresenceActivity *)ms_list_nth_data(person->activities, st->requested_idx - st->current_idx);
} else {
st->current_idx += size;
}
}
int linphone_presence_model_get_nth_activity(const LinphonePresenceModel *model, unsigned int idx, LinphonePresenceActivity *activity, char **description) {
LinphonePresenceActivity * linphone_presence_model_get_nth_activity(const LinphonePresenceModel *model, unsigned int idx) {
struct _get_activity_st st;
if ((model == NULL) || (activity == NULL) || (idx >= linphone_presence_model_nb_activities(model)))
return -1;
if ((model == NULL) || (idx >= linphone_presence_model_nb_activities(model)))
return NULL;
memset(&st, 0, sizeof(st));
st.requested_idx = idx;
st.activity = activity;
*st.activity = LinphonePresenceActivityUnknown;
if (description != NULL) {
st.description = description;
}
ms_list_for_each2(model->persons, (MSIterate2Func)presence_model_get_activity, &st);
return 0;
return st.activity;
}
int linphone_presence_model_get_activity(const LinphonePresenceModel *model, LinphonePresenceActivity *activity, char **description) {
if ((model == NULL) || (activity == NULL))
return -1;
if (linphone_presence_model_get_nth_activity(model, 0, activity, description) < 0) {
/* There is no activities, base the result on the basic status. */
LinphonePresenceBasicStatus basic_status = linphone_presence_model_get_basic_status(model);
if (basic_status == LinphonePresenceBasicStatusOpen)
*activity = LinphonePresenceActivityOnline;
else
*activity = LinphonePresenceActivityOffline;
}
return 0;
LinphonePresenceActivity * linphone_presence_model_get_activity(const LinphonePresenceModel *model) {
return linphone_presence_model_get_nth_activity(model, 0);
}
int linphone_presence_model_set_activity(LinphonePresenceModel *model, LinphonePresenceActivity activity, const char *description) {
int linphone_presence_model_set_activity(LinphonePresenceModel *model, LinphonePresenceActivityType acttype, const char *description) {
LinphonePresenceBasicStatus basic_status = LinphonePresenceBasicStatusOpen;
if (model == NULL) return -1;
switch (activity) {
switch (acttype) {
case LinphonePresenceActivityAppointment:
case LinphonePresenceActivityBusy:
case LinphonePresenceActivityMeeting:
......@@ -594,7 +567,7 @@ int linphone_presence_model_set_activity(LinphonePresenceModel *model, LinphoneP
if (presence_model_set_basic_status(model, basic_status) < 0)
return -1;
presence_model_clear_activities(model);
if (presence_model_add_activity(model, activity, description) < 0)
if (presence_model_add_activity(model, acttype, description) < 0)
return -1;
return 0;
......@@ -653,7 +626,7 @@ static void get_first_presence_service_note(struct _LinphonePresenceService *ser
st->note = get_first_presence_note_in_list(service->notes);
}