From 5f1e8dd03ddce0bfe437016f86342b038ab9f5fe Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 24 Jun 2013 14:53:49 +0200 Subject: [PATCH] Add JNI for presence. --- coreapi/linphonecore_jni.cc | 258 +++++++++++++++++- coreapi/linphonepresence.h | 84 ++++++ coreapi/presence.c | 73 +++++ .../org/linphone/core/LinphoneCore.java | 26 +- .../org/linphone/core/LinphoneFriend.java | 15 +- .../org/linphone/core/OnlineStatus.java | 2 +- .../org/linphone/core/PresenceActivity.java | 42 +++ .../linphone/core/PresenceActivityType.java | 137 ++++++++++ .../org/linphone/core/PresenceModel.java | 109 ++++++++ .../org/linphone/core/PresenceNote.java | 36 +++ .../org/linphone/core/LinphoneCoreImpl.java | 19 +- .../org/linphone/core/LinphoneFriendImpl.java | 8 + .../linphone/core/PresenceActivityImpl.java | 51 ++++ .../org/linphone/core/PresenceModelImpl.java | 85 ++++++ .../org/linphone/core/PresenceNoteImpl.java | 45 +++ 15 files changed, 978 insertions(+), 12 deletions(-) create mode 100644 java/common/org/linphone/core/PresenceActivity.java create mode 100644 java/common/org/linphone/core/PresenceActivityType.java create mode 100644 java/common/org/linphone/core/PresenceModel.java create mode 100644 java/common/org/linphone/core/PresenceNote.java create mode 100644 java/impl/org/linphone/core/PresenceActivityImpl.java create mode 100644 java/impl/org/linphone/core/PresenceModelImpl.java create mode 100644 java/impl/org/linphone/core/PresenceNoteImpl.java diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 2a8d4d1cd..bf3045de8 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -50,6 +50,27 @@ extern "C" void libmsbcg729_init(); #endif #endif /*ANDROID*/ + + +#define RETURN_USER_DATA_OBJECT(javaclass, funcprefix, cobj) \ + { \ + jclass jUserDataObjectClass; \ + jmethodID jUserDataObjectCtor; \ + jobject jUserDataObj; \ + jUserDataObj = (jobject)funcprefix ## _get_user_data(cobj); \ + if (jUserDataObj == NULL) { \ + jUserDataObjectClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/" javaclass)); \ + jUserDataObjectCtor = env->GetMethodID(jUserDataObjectClass,"", "(J)V"); \ + jUserDataObj = env->NewObject(jUserDataObjectClass, jUserDataObjectCtor, (jlong)funcprefix ## _ref(cobj)); \ + jUserDataObj = env->NewGlobalRef(jUserDataObj); \ + funcprefix ## _set_user_data(cobj, jUserDataObj); \ + env->DeleteGlobalRef(jUserDataObjectClass); \ + } \ + return jUserDataObj; \ + } + + + static JavaVM *jvm=0; static const char* LogDomain = "Linphone"; static jclass handler_class; @@ -1062,13 +1083,41 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env ,jobject thiz ,jlong lc - ,jint minute_away + ,jint minutes_away ,jstring jalternative_contact ,jint status) { const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL; - linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status); + linphone_core_set_presence_info((LinphoneCore*)lc,minutes_away,alternative_contact,(LinphoneOnlineStatus)status); if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact); } +extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getPresenceInfo(JNIEnv *env, jobject thiz, jlong lc) { + return (jint)linphone_core_get_presence_info((LinphoneCore *)lc); +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: setPresenceModel + * Signature: (JILjava/lang/String;J)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setPresenceModel(JNIEnv *env, jobject jobj, jlong ptr, jint minutes_away, jstring jalternative_contact, jlong modelPtr) { + LinphoneCore *lc = (LinphoneCore *)ptr; + const char *calternative_contact = jalternative_contact ? env->GetStringUTFChars(jalternative_contact, NULL) : NULL; + LinphonePresenceModel *model = (LinphonePresenceModel *)modelPtr; + linphone_core_set_presence_model(lc, minutes_away, calternative_contact, model); + if (calternative_contact) env->ReleaseStringUTFChars(jalternative_contact, calternative_contact); +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: getPresenceModel + * Signature: (J)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_getPresenceModel(JNIEnv *env, jobject jobj, jlong ptr) { + LinphoneCore *lc = (LinphoneCore *)ptr; + LinphonePresenceModel *model = linphone_core_get_presence_model(lc); + if (model == NULL) return NULL; + RETURN_USER_DATA_OBJECT("PresenceModelImpl", linphone_presence_model, model) +} extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv* env ,jobject thiz @@ -1952,6 +2001,30 @@ extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv* env ,jlong ptr) { return (jint)linphone_friend_get_status((LinphoneFriend*)ptr); } + +/* + * Class: org_linphone_core_LinphoneFriendImpl + * Method: getPresenceModel + * Signature: (J)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneFriendImpl_getPresenceModel(JNIEnv *env, jobject jobj, jlong ptr) { + LinphoneFriend *lf = (LinphoneFriend *)ptr; + LinphonePresenceModel *model = linphone_friend_get_presence_model(lf); + if (model == NULL) return NULL; + RETURN_USER_DATA_OBJECT("PresenceModelImpl", linphone_presence_model, model); +} + +/* + * Class: org_linphone_core_LinphoneFriendImpl + * Method: setPresenceModel + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneFriendImpl_setPresenceModel(JNIEnv *env, jobject jobj, jlong ptr, jlong presencePtr) { + LinphoneFriend *lf = (LinphoneFriend *)ptr; + LinphonePresenceModel *model = (LinphonePresenceModel *)presencePtr; + linphone_friend_set_presence_model(lf, model); +} + extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv* env ,jobject thiz ,jlong ptr) { @@ -3040,3 +3113,184 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_unref(JNIEnv *en linphone_event_unref(ev); } +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: unref + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_PresenceModelImpl_unref(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + linphone_presence_model_unref(model); +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: getBasicStatus + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceModelImpl_getBasicStatus(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + return (jint)linphone_presence_model_get_basic_status(model); +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: nbActivities + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_linphone_core_PresenceModelImpl_nbActivities(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + return (jlong)linphone_presence_model_nb_activities(model); +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: getNthActivity + * Signature: (JJ)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_PresenceModelImpl_getNthActivity(JNIEnv *env, jobject jobj, jlong ptr, jlong idx) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + LinphonePresenceActivity *activity = linphone_presence_model_get_nth_activity(model, (unsigned int)idx); + if (activity == NULL) return NULL; + RETURN_USER_DATA_OBJECT("PresenceActivityImpl", linphone_presence_activity, activity) +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: getActivity + * Signature: (J)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_PresenceModelImpl_getActivity(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + LinphonePresenceActivity *activity = linphone_presence_model_get_activity(model); + if (activity == NULL) return NULL; + RETURN_USER_DATA_OBJECT("PresenceActivityImpl", linphone_presence_activity, activity) +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: setActivity + * Signature: (JILjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceModelImpl_setActivity(JNIEnv *env, jobject jobj, jlong ptr, jint acttype, jstring description) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + const char *cdescription = description ? env->GetStringUTFChars(description, NULL) : NULL; + jint res = (jint)linphone_presence_model_set_activity(model, (LinphonePresenceActivityType)acttype, cdescription); + if (cdescription) env->ReleaseStringUTFChars(description, cdescription); + return res; +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: getNote + * Signature: (JLjava/lang/String;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_PresenceModelImpl_getNote(JNIEnv *env , jobject jobj, jlong ptr, jstring lang) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + const char *clang = lang ? env->GetStringUTFChars(lang, NULL) : NULL; + LinphonePresenceNote *note = linphone_presence_model_get_note(model, clang); + if (clang) env->ReleaseStringUTFChars(lang, clang); + if (note == NULL) return NULL; + RETURN_USER_DATA_OBJECT("PresenceNoteImpl", linphone_presence_note, note) +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: addNote + * Signature: (JLjava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceModelImpl_addNote(JNIEnv *env, jobject jobj, jlong ptr, jstring description, jstring lang) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + const char *cdescription = description ? env->GetStringUTFChars(description, NULL) : NULL; + const char *clang = lang ? env->GetStringUTFChars(lang, NULL) : NULL; + jint res = (jint)linphone_presence_model_add_note(model, cdescription, clang); + if (cdescription) env->ReleaseStringUTFChars(description, cdescription); + if (clang) env->ReleaseStringUTFChars(lang, clang); + return res; +} + +/* + * Class: org_linphone_core_PresenceModelImpl + * Method: clearNotes + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceModelImpl_clearNotes(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceModel *model = (LinphonePresenceModel *)ptr; + return (jint)linphone_presence_model_clear_notes(model); +} + +/* + * Class: org_linphone_core_PresenceActivityImpl + * Method: unref + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_PresenceActivityImpl_unref(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceActivity *activity = (LinphonePresenceActivity *)ptr; + linphone_presence_activity_unref(activity); +} + + /* + * Class: org_linphone_core_PresenceActivityImpl + * Method: toString + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceActivityImpl_toString(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceActivity *activity = (LinphonePresenceActivity *)ptr; + char *cactstr = linphone_presence_activity_to_string(activity); + jstring jactstr = cactstr ? env->NewStringUTF(cactstr) : NULL; + if (cactstr) ms_free(cactstr); + return jactstr; +} + +/* + * Class: org_linphone_core_PresenceActivityImpl + * Method: getType + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceActivityImpl_getType(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceActivity *activity = (LinphonePresenceActivity *)ptr; + return (jint)linphone_presence_activity_get_type(activity); +} + +/* + * Class: org_linphone_core_PresenceActivityImpl + * Method: getDescription + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceActivityImpl_getDescription(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceActivity *activity = (LinphonePresenceActivity *)ptr; + const char *cdescription = linphone_presence_activity_get_description(activity); + return cdescription ? env->NewStringUTF(cdescription) : NULL; +} + +/* + * Class: org_linphone_core_PresenceNoteImpl + * Method: unref + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_PresenceNoteImpl_unref(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceNote *note = (LinphonePresenceNote *)ptr; + linphone_presence_note_unref(note); +} + +/* + * Class: org_linphone_core_PresenceNoteImpl + * Method: getContent + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceNoteImpl_getContent(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceNote *note = (LinphonePresenceNote *)ptr; + const char *ccontent = linphone_presence_note_get_content(note); + return ccontent ? env->NewStringUTF(ccontent) : NULL; +} + +/* + * Class: org_linphone_core_PresenceNoteImpl + * Method: getLang + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceNoteImpl_getLang(JNIEnv *env, jobject jobj, jlong ptr) { + LinphonePresenceNote *note = (LinphonePresenceNote *)ptr; + const char *clang = linphone_presence_note_get_lang(note); + return clang ? env->NewStringUTF(clang) : NULL; +} diff --git a/coreapi/linphonepresence.h b/coreapi/linphonepresence.h index 924df2008..7b7c66f4f 100644 --- a/coreapi/linphonepresence.h +++ b/coreapi/linphonepresence.h @@ -214,6 +214,34 @@ LINPHONE_PUBLIC LinphonePresenceModel * linphone_presence_model_new_with_activit */ LINPHONE_PUBLIC void linphone_presence_model_delete(LinphonePresenceModel *model); +/** + * Increase the reference count of the #LinphonePresenceModel object. + * @param[in] model The #LinphonePresenceModel object for which the reference count is to be increased. + * @return The #LinphonePresenceModel object with the increased reference count. + */ +LinphonePresenceModel * linphone_presence_model_ref(LinphonePresenceModel *model); + +/** + * Decrease the reference count of the #LinphonePresenceModel object and destroy it if it reaches 0. + * @param[in] model The #LinphonePresenceModel object for which the reference count is to be decreased. + * @return The #LinphonePresenceModel object if the reference count is still positive, NULL if the object has been destroyed. + */ +LinphonePresenceModel * linphone_presence_model_unref(LinphonePresenceModel *model); + +/** + * Sets the user data of a #LinphonePresenceModel object. + * @param[in] model The #LinphonePresenceModel object for which to set the user data. + * @param[in] user_data A pointer to the user data to set. + */ +void linphone_presence_model_set_user_data(LinphonePresenceModel *model, void *user_data); + +/** + * Gets the user data of a #LinphonePresenceModel object. + * @param[in] model The #LinphonePresenceModel object for which to get the user data. + * @return A pointer to the user data. + */ +void * linphone_presence_model_get_user_data(LinphonePresenceModel *model); + /** * @brief Compares two presence models. * @param[in] m1 The first #LinphonePresenceModel object. @@ -286,6 +314,34 @@ LINPHONE_PUBLIC int linphone_presence_model_add_note(LinphonePresenceModel *mode */ LINPHONE_PUBLIC int linphone_presence_model_clear_notes(LinphonePresenceModel *model); +/** + * Increase the reference count of the #LinphonePresenceActivity object. + * @param[in] activity The #LinphonePresenceActivity object for which the reference count is to be increased. + * @return The #LinphonePresenceActivity object with the increased reference count. + */ +LinphonePresenceActivity * linphone_presence_activity_ref(LinphonePresenceActivity *activity); + +/** + * Decrease the reference count of the #LinphonePresenceActivity object and destroy it if it reaches 0. + * @param[in] activity The #LinphonePresenceActivity object for which the reference count is to be decreased. + * @return The #LinphonePresenceActivity object if the reference count is still positive, NULL if the object has been destroyed. + */ +LinphonePresenceActivity * linphone_presence_activity_unref(LinphonePresenceActivity *activity); + +/** + * Sets the user data of a #LinphonePresenceActivity object. + * @param[in] activity The #LinphonePresenceActivity object for which to set the user data. + * @param[in] user_data A pointer to the user data to set. + */ +void linphone_presence_activity_set_user_data(LinphonePresenceActivity *activity, void *user_data); + +/** + * Gets the user data of a #LinphonePresenceActivity object. + * @param[in] activity The #LinphonePresenceActivity object for which to get the user data. + * @return A pointer to the user data. + */ +void * linphone_presence_activity_get_user_data(LinphonePresenceActivity *activity); + /** * @brief Gets the string representation of a presence activity. * @param[in] activity A pointer to the #LinphonePresenceActivity object for which to get a string representation. @@ -309,6 +365,34 @@ LINPHONE_PUBLIC LinphonePresenceActivityType linphone_presence_activity_get_type */ LINPHONE_PUBLIC const char * linphone_presence_activity_get_description(const LinphonePresenceActivity *activity); +/** + * Increase the reference count of the #LinphonePresenceNote object. + * @param[in] note The #LinphonePresenceNote object for which the reference count is to be increased. + * @return The #LinphonePresenceNote object with the increased reference count. + */ +LinphonePresenceNote * linphone_presence_note_ref(LinphonePresenceNote *note); + +/** + * Decrease the reference count of the #LinphonePresenceNote object and destroy it if it reaches 0. + * @param[in] note The #LinphonePresenceNote object for which the reference count is to be decreased. + * @return The #LinphonePresenceNote object if the reference count is still positive, NULL if the object has been destroyed. + */ +LinphonePresenceNote * linphone_presence_note_unref(LinphonePresenceNote *note); + +/** + * Sets the user data of a #LinphonePresenceNote object. + * @param[in] note The #LinphonePresenceNote object for which to set the user data. + * @param[in] user_data A pointer to the user data to set. + */ +void linphone_presence_note_set_user_data(LinphonePresenceNote *note, void *user_data); + +/** + * Gets the user data of a #LinphonePresenceNote object. + * @param[in] note The #LinphonePresenceNote object for which to get the user data. + * @return A pointer to the user data. + */ +void * linphone_presence_note_get_user_data(LinphonePresenceNote *note); + /** * @brief Gets the content of a presence note. * @param[in] note A pointer to the #LinphonePresenceNote for which to get the content. diff --git a/coreapi/presence.c b/coreapi/presence.c index 6148e3929..9f6ee9bf6 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -37,6 +37,8 @@ extern const char *__policy_enum_to_str(LinphoneSubscribePolicy pol); struct _LinphonePresenceNote { + void *user_data; + int refcnt; char *lang; char *content; }; @@ -50,6 +52,8 @@ struct _LinphonePresenceService { }; struct _LinphonePresenceActivity { + void *user_data; + int refcnt; LinphonePresenceActivityType type; char *description; }; @@ -67,6 +71,8 @@ struct _LinphonePresencePerson { * This model is not complete. For example, it does not handle devices. */ struct _LinphonePresenceModel { + void *user_data; + int refcnt; MSList *services; /**< A list of _LinphonePresenceService structures. Also named tuples in the RFC. */ MSList *persons; /**< A list of _LinphonePresencePerson structures. */ MSList *notes; /**< A list of _LinphonePresenceNote structures. */ @@ -139,6 +145,7 @@ static const char * presence_basic_status_to_string(LinphonePresenceBasicStatus static struct _LinphonePresenceNote * presence_note_new(const char *content, const char *lang) { struct _LinphonePresenceNote * note = ms_new0(struct _LinphonePresenceNote, 1); + note->refcnt = 1; note->content = ms_strdup(content); if (lang != NULL) { note->lang = ms_strdup(lang); @@ -448,6 +455,28 @@ void linphone_presence_model_delete(LinphonePresenceModel *model) { ms_free(model); } +LinphonePresenceModel * linphone_presence_model_ref(LinphonePresenceModel *model) { + model->refcnt++; + return model; +} + +LinphonePresenceModel * linphone_presence_model_unref(LinphonePresenceModel *model) { + model->refcnt--; + if (model->refcnt == 0) { + linphone_presence_model_delete(model); + return NULL; + } + return model; +} + +void linphone_presence_model_set_user_data(LinphonePresenceModel *model, void *user_data) { + model->user_data = user_data; +} + +void * linphone_presence_model_get_user_data(LinphonePresenceModel *model) { + return model->user_data; +} + bool_t linphone_presence_model_equals(const LinphonePresenceModel *m1, const LinphonePresenceModel *m2) { LinphonePresenceActivity *activity = NULL; int nb; @@ -918,6 +947,28 @@ static const char * presence_activity_type_to_string(LinphonePresenceActivityTyp return NULL; } +LinphonePresenceActivity * linphone_presence_activity_ref(LinphonePresenceActivity *activity) { + activity->refcnt++; + return activity; +} + +LinphonePresenceActivity * linphone_presence_activity_unref(LinphonePresenceActivity *activity) { + activity->refcnt--; + if (activity->refcnt == 0) { + presence_note_delete(activity); + return NULL; + } + return activity; +} + +void linphone_presence_activity_set_user_data(LinphonePresenceActivity *activity, void *user_data) { + activity->user_data = user_data; +} + +void * linphone_presence_activity_get_user_data(LinphonePresenceActivity *activity) { + return activity->user_data; +} + char * linphone_presence_activity_to_string(const LinphonePresenceActivity *activity) { LinphonePresenceActivityType acttype = linphone_presence_activity_get_type(activity); const char *description = linphone_presence_activity_get_description(activity); @@ -947,6 +998,28 @@ const char * linphone_presence_activity_get_description(const LinphonePresenceAc return activity->description; } +LinphonePresenceNote * linphone_presence_note_ref(LinphonePresenceNote *note) { + note->refcnt++; + return note; +} + +LinphonePresenceNote * linphone_presence_note_unref(LinphonePresenceNote *note) { + note->refcnt--; + if (note->refcnt == 0) { + presence_note_delete(note); + return NULL; + } + return note; +} + +void linphone_presence_note_set_user_data(LinphonePresenceNote *note, void *user_data) { + note->user_data = user_data; +} + +void * linphone_presence_note_get_user_data(LinphonePresenceNote *note) { + return note->user_data; +} + const char * linphone_presence_note_get_content(const LinphonePresenceNote *note) { if (note == NULL) return NULL; diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index c8a6d7b6f..66db71526 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -669,11 +669,31 @@ public interface LinphoneCore { void addFriend(LinphoneFriend lf) throws LinphoneCoreException; /** - * Set my presence status - * @param minute_away how long in away + * @brief Set my presence status + * @param minutes_away how long in away * @param status sip uri used to redirect call in state LinphoneStatusMoved + * @param status OnlineStatus + * @deprecated Use setPresenceModel() instead */ - void setPresenceInfo(int minute_away,String alternative_contact, OnlineStatus status); + void setPresenceInfo(int minutes_away, String alternative_contact, OnlineStatus status); + /** + * @brief Get my presence status + * @return OnlineStatus + * @deprecated Use getPresenceModel() instead + */ + OnlineStatus getPresenceInfo(); + /** + * @brief Set my presence status + * @param minutess_away how long in away + * @param alternative_contact sip uri used to redirect call in state #LinphoneStatusMoved + * @param presence #LinphonePresenceModel + */ + void setPresenceModel(int minutes_away, String alternative_contact, PresenceModel presence); + /** + * @brief Get my presence status + * @return A #PresenceModel object, or null if no presence model has been set. + */ + PresenceModel getPresenceModel(); /** * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org * @param to destination address for messages diff --git a/java/common/org/linphone/core/LinphoneFriend.java b/java/common/org/linphone/core/LinphoneFriend.java index 417c582d9..d4a33fe45 100644 --- a/java/common/org/linphone/core/LinphoneFriend.java +++ b/java/common/org/linphone/core/LinphoneFriend.java @@ -103,10 +103,21 @@ public interface LinphoneFriend { */ boolean isSubscribesEnabled(); /** - * get friend status - * @return + * @brief Get the status of a friend + * @return OnlineStatus + * @deprecated Use getPresenceModel() instead */ OnlineStatus getStatus(); + /** + * @brief Get the presence information of a friend + * @return A #PresenceModel object, or null if the friend do not have presence information (in which case he is considered offline) + */ + PresenceModel getPresenceModel(); + /** + * @brief Set the presence information of a friend + * @param presence A #PresenceModel object. It can be null to remove the presence information of the friend. + */ + void setPresenceModel(PresenceModel presence); /** * Starts editing a friend configuration. *
Because friend configuration must be consistent, applications MUST call {@link #edit()} before doing any attempts to modify friend configuration (such as address or subscription policy and so on). diff --git a/java/common/org/linphone/core/OnlineStatus.java b/java/common/org/linphone/core/OnlineStatus.java index 081084171..9a101d223 100644 --- a/java/common/org/linphone/core/OnlineStatus.java +++ b/java/common/org/linphone/core/OnlineStatus.java @@ -23,7 +23,7 @@ import java.util.Vector; /** * Enum describing remote friend status - * + * @deprecated Use #PresenceModel and #PresenceActivity instead */ public class OnlineStatus { diff --git a/java/common/org/linphone/core/PresenceActivity.java b/java/common/org/linphone/core/PresenceActivity.java new file mode 100644 index 000000000..4f116c43c --- /dev/null +++ b/java/common/org/linphone/core/PresenceActivity.java @@ -0,0 +1,42 @@ +/* +PresenceActivity.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public interface PresenceActivity { + + /** + * @brief Gets the string representation of a presence activity. + * @return A String representing the given activity. + */ + String toString(); + + /** + * @brief Gets the activity type of a presence activity. + * @return The #PresenceActivityType of the activity. + */ + PresenceActivityType getType(); + + /** + * @brief Gets the description of a presence activity. + * @return A String containing the description of the presence activity, or null if no description is specified. + */ + String getDescription(); + +} diff --git a/java/common/org/linphone/core/PresenceActivityType.java b/java/common/org/linphone/core/PresenceActivityType.java new file mode 100644 index 000000000..c20398661 --- /dev/null +++ b/java/common/org/linphone/core/PresenceActivityType.java @@ -0,0 +1,137 @@ +/* +PresenceActivityType.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +/** Activities as defined in section 3.2 of RFC 4480 */ +public enum PresenceActivityType { + /** This value is not defined in the RFC, it corresponds to no activity with a basic status of "closed". */ + Offline(0), + /** This value is not defined in the RFC, it corresponds to no activity with a basic status of "open". */ + Online(1), + /** 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. */ + Appointment(2), + /** The person is physically away from all interactive communication devices. */ + Away(3), + /** The person is eating the first meal of the day, usually eaten in the morning. */ + Breakfast(4), + /** The person is busy, without further details. */ + Busy(5), + /** The person is having his or her main meal of the day, eaten in the evening or at midday. */ + Dinner(6), + /** This is a scheduled national or local holiday. */ + Holiday(7), + /** The person is riding in a vehicle, such as a car, but not steering. */ + InTransit(8), + /** The person is looking for (paid) work. */ + LookingForWork(9), + /** The person is eating his or her midday meal. */ + Lunch(10), + /** The person is scheduled for a meal, without specifying whether it is breakfast, lunch, or dinner, + * or some other meal. */ + Meal(11), + /** The person is in an assembly or gathering of people, as for a business, social, or religious purpose. + * A meeting is a sub-class of an appointment. */ + Meeting(12), + /** The person is talking on the telephone. */ + OnThePhone(13), + /** The person is engaged in an activity with no defined representation. A string describing the activity + * in plain text SHOULD be provided. */ + Other(14), + /** A performance is a sub-class of an appointment and includes musical, theatrical, and cinematic + * performances as well as lectures. It is distinguished from a meeting by the fact that the person + * may either be lecturing or be in the audience, with a potentially large number of other people, + * making interruptions particularly noticeable. */ + Performance(15), + /** The person will not return for the foreseeable future, e.g., because it is no longer working for + * the company. */ + PermanentAbsence(16), + /** The person is occupying himself or herself in amusement, sport, or other recreation. */ + Playing(17), + /** The person is giving a presentation, lecture, or participating in a formal round-table discussion. */ + Presentation(18), + /** The person is visiting stores in search of goods or services. */ + Shopping(19), + /** The person is sleeping.*/ + Sleeping(20), + /** The person is observing an event, such as a sports event. */ + Spectator(21), + /** The person is controlling a vehicle, watercraft, or plane. */ + Steering(22), + /** The person is on a business or personal trip, but not necessarily in-transit. */ + Travel(23), + /** The person is watching television. */ + TV(24), + /** The activity of the person is unknown. */ + Unknown(25), + /** A period of time devoted to pleasure, rest, or relaxation. */ + Vacation(26), + /** The person is engaged in, typically paid, labor, as part of a profession or job. */ + Working(27), + /** The person is participating in religious rites. */ + Worship(28), + Invalid(29); + + protected final int mValue; + + private PresenceActivityType(int value) { + mValue = value; + } + + public int toInt() { + return mValue; + } + + static protected PresenceActivityType fromInt(int value) { + switch (value) { + case 0: return Offline; + case 1: return Online; + case 2: return Appointment; + case 3: return Away; + case 4: return Breakfast; + case 5: return Busy; + case 6: return Dinner; + case 7: return Holiday; + case 8: return InTransit; + case 9: return LookingForWork; + case 10: return Lunch; + case 11: return Meal; + case 12: return Meeting; + case 13: return OnThePhone; + case 14: return Other; + case 15: return Performance; + case 16: return PermanentAbsence; + case 17: return Playing; + case 18: return Presentation; + case 19: return Shopping; + case 20: return Sleeping; + case 21: return Spectator; + case 22: return Steering; + case 23: return Travel; + case 24: return TV; + case 25: return Unknown; + case 26: return Vacation; + case 27: return Working; + case 28: return Worship; + default: return Invalid; + } + } +} diff --git a/java/common/org/linphone/core/PresenceModel.java b/java/common/org/linphone/core/PresenceModel.java new file mode 100644 index 000000000..9644e04cb --- /dev/null +++ b/java/common/org/linphone/core/PresenceModel.java @@ -0,0 +1,109 @@ +/* +PresenceModel.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public interface PresenceModel { + + /** Basic status as defined in section 4.1.4 of RFC 3863 */ + public enum BasicStatus { + /** This value means that the associated contact element, if any, is ready to accept communication. */ + Open(0), + /** This value means that the associated contact element, if any, is unable to accept communication. */ + Closed(1), + Invalid(2); + + protected final int mValue; + + private BasicStatus(int value) { + mValue = value; + } + + public int toInt() { + return mValue; + } + + static protected BasicStatus fromInt(int value) { + switch (value) { + case 0: return Open; + case 1: return Closed; + default: return Invalid; + } + } + } + + + + /** + * @brief Gets the basic status of a presence model. + * @return The #BasicStatus of the #PresenceModel object. + */ + BasicStatus getBasicStatus(); + + /** + * @brief Gets the number of activities included in the presence model. + * @return The number of activities included in the #PresenceModel object. + */ + long nbActivities(); + + /** + * @brief Gets the nth activity of a presence model. + * @param idx The index of the activity to get (the first activity having the index 0). + * @return A #PresenceActivity object if successful, null otherwise. + */ + PresenceActivity getNthActivity(long idx); + + /** + * @brief Gets the first activity of a presence model (there is usually only one). + * @return A #PresenceActivity object if successful, null otherwise. + */ + PresenceActivity getActivity(); + + /** + * @brief Sets the activity of a presence model (limits to only one activity). + * @param[in] activity The #PresenceActivityType 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. + */ + int setActivity(PresenceActivityType activity, String description); + + /** + * @brief Gets the first note of a presence model (there is usually only one). + * @param[in] lang The language of the note to get. Can be null to get a note that has no language specified or to get the first note whatever language it is written into. + * @return A #PresenceNote object if successful, null otherwise. + */ + PresenceNote getNote(String lang); + + /** + * @brief Adds a note to a presence model. + * @param[in] note_content The note to be added to the presence model. + * @param[in] lang The language of the note to be added. Can be null if no language is to be specified for the note. + * @return 0 if successful, a value < 0 in case of error. + * + * Only one note for each language can be set, so e.g. setting a note for the 'fr' language if there is only one will replace the existing one. + */ + int addNote(String note_content, String lang); + + /** + * @brief Clears all the notes of a presence model. + * @return 0 if successful, a value < 0 in case of error. + */ + int clearNotes(); + +} diff --git a/java/common/org/linphone/core/PresenceNote.java b/java/common/org/linphone/core/PresenceNote.java new file mode 100644 index 000000000..a89cde1df --- /dev/null +++ b/java/common/org/linphone/core/PresenceNote.java @@ -0,0 +1,36 @@ +/* +PresenceNote.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public interface PresenceNote { + + /** + * @brief Gets the content of a presence note. + * @return A String with the content of the presence note. + */ + String getContent(); + + /** + * @brief Gets the language of a presence note. + * @return A String containing the language of the presence note, or null if no language is specified. + */ + String getLang(); + +} diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index ae9b26fe8..7884fb011 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -80,7 +80,10 @@ class LinphoneCoreImpl implements LinphoneCore { private native void setPreviewWindowId(long nativePtr, Object wid); private native void setDeviceRotation(long nativePtr, int rotation); private native void addFriend(long nativePtr,long friend); - private native void setPresenceInfo(long nativePtr,int minute_away, String alternative_contact,int status); + private native void setPresenceInfo(long nativePtr, int minutes_away, String alternative_contact, int status); + private native int getPresenceInfo(long nativePtr); + private native void setPresenceModel(long nativePtr, int minutes_away, String alternative_contact, long presencePtr); + private native Object getPresenceModel(long nativePtr); private native long createChatRoom(long nativePtr,String to); private native void enableVideo(long nativePtr,boolean vcap_enabled,boolean display_enabled); private native boolean isVideoEnabled(long nativePtr); @@ -368,11 +371,19 @@ class LinphoneCoreImpl implements LinphoneCore { addFriend(nativePtr,((LinphoneFriendImpl)lf).nativePtr); } - public synchronized void setPresenceInfo(int minute_away, String alternative_contact, - OnlineStatus status) { - setPresenceInfo(nativePtr,minute_away,alternative_contact,status.mValue); + public synchronized void setPresenceInfo(int minutes_away, String alternative_contact, OnlineStatus status) { + setPresenceInfo(nativePtr,minutes_away,alternative_contact,status.mValue); } + public synchronized OnlineStatus getPresenceInfo() { + return OnlineStatus.fromInt(getPresenceInfo(nativePtr)); + } + public synchronized void setPresenceModel(int minutes_away, String alternative_contact, PresenceModel presence) { + setPresenceModel(nativePtr, minutes_away, alternative_contact, ((PresenceModelImpl)presence).getNativePtr()); + } + public synchronized PresenceModel getPresenceModel() { + return (PresenceModel)getPresenceModel(nativePtr); + } public synchronized LinphoneChatRoom createChatRoom(String to) { return new LinphoneChatRoomImpl(createChatRoom(nativePtr,to)); } diff --git a/java/impl/org/linphone/core/LinphoneFriendImpl.java b/java/impl/org/linphone/core/LinphoneFriendImpl.java index 6e7aa2db1..da37b15ac 100644 --- a/java/impl/org/linphone/core/LinphoneFriendImpl.java +++ b/java/impl/org/linphone/core/LinphoneFriendImpl.java @@ -30,6 +30,8 @@ class LinphoneFriendImpl implements LinphoneFriend, Serializable { private native void enableSubscribes(long nativePtr,boolean value); private native boolean isSubscribesEnabled(long nativePtr); private native int getStatus(long nativePtr); + private native Object getPresenceModel(long nativePtr); + private native void setPresenceModel(long nativePtr, long presencePtr); private native void edit(long nativePtr); private native void done(long nativePtr); @@ -69,6 +71,12 @@ class LinphoneFriendImpl implements LinphoneFriend, Serializable { public OnlineStatus getStatus() { return OnlineStatus.fromInt(getStatus(nativePtr)); } + public PresenceModel getPresenceModel() { + return (PresenceModel)getPresenceModel(nativePtr); + } + public void setPresenceModel(PresenceModel presence) { + setPresenceModel(nativePtr, ((PresenceModelImpl)presence).getNativePtr()); + } public void edit() { edit(nativePtr); } diff --git a/java/impl/org/linphone/core/PresenceActivityImpl.java b/java/impl/org/linphone/core/PresenceActivityImpl.java new file mode 100644 index 000000000..fc63c4114 --- /dev/null +++ b/java/impl/org/linphone/core/PresenceActivityImpl.java @@ -0,0 +1,51 @@ +/* +PresenceActivityImpl.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public class PresenceActivityImpl implements PresenceActivity { + private long mNativePtr; + + protected PresenceActivityImpl(long nativePtr) { + mNativePtr = nativePtr; + } + + private native void unref(long nativePtr); + protected void finalize() { + unref(mNativePtr); + } + + private native String toString(long nativePtr); + @Override + public String toString() { + return toString(mNativePtr); + } + + private native int getType(long nativePtr); + @Override + public PresenceActivityType getType() { + return PresenceActivityType.fromInt(getType(mNativePtr)); + } + + private native String getDescription(long nativePtr); + @Override + public String getDescription() { + return getDescription(mNativePtr); + } +} diff --git a/java/impl/org/linphone/core/PresenceModelImpl.java b/java/impl/org/linphone/core/PresenceModelImpl.java new file mode 100644 index 000000000..c7720fa2e --- /dev/null +++ b/java/impl/org/linphone/core/PresenceModelImpl.java @@ -0,0 +1,85 @@ +/* +PresenceModelImpl.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public class PresenceModelImpl implements PresenceModel { + private long mNativePtr; + + protected PresenceModelImpl(long nativePtr) { + mNativePtr = nativePtr; + } + + private native void unref(long nativePtr); + protected void finalize() { + unref(mNativePtr); + } + + public long getNativePtr() { + return mNativePtr; + } + + private native int getBasicStatus(long nativePtr); + @Override + public BasicStatus getBasicStatus() { + return BasicStatus.fromInt(getBasicStatus(mNativePtr)); + } + + private native long nbActivities(long nativePtr); + @Override + public long nbActivities() { + return nbActivities(mNativePtr); + } + + private native Object getNthActivity(long nativePtr, long idx); + @Override + public PresenceActivity getNthActivity(long idx) { + return (PresenceActivity)getNthActivity(mNativePtr, idx); + } + + private native Object getActivity(long nativePtr); + @Override + public PresenceActivity getActivity() { + return (PresenceActivity)getActivity(mNativePtr); + } + + private native int setActivity(long nativePtr, int activity, String description); + @Override + public int setActivity(PresenceActivityType activity, String description) { + return setActivity(mNativePtr, activity.toInt(), description); + } + + private native Object getNote(long nativePtr, String lang); + @Override + public PresenceNote getNote(String lang) { + return (PresenceNote)getNote(mNativePtr, lang); + } + + private native int addNote(long nativePtr, String note_content, String lang); + @Override + public int addNote(String note_content, String lang) { + return addNote(mNativePtr, note_content, lang); + } + + private native int clearNotes(long nativePtr); + @Override + public int clearNotes() { + return clearNotes(mNativePtr); + } +} diff --git a/java/impl/org/linphone/core/PresenceNoteImpl.java b/java/impl/org/linphone/core/PresenceNoteImpl.java new file mode 100644 index 000000000..38c541cf2 --- /dev/null +++ b/java/impl/org/linphone/core/PresenceNoteImpl.java @@ -0,0 +1,45 @@ +/* +PresenceNoteImpl.java +Copyright (C) 2010-2013 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone.core; + +public class PresenceNoteImpl implements PresenceNote { + private long mNativePtr; + + protected PresenceNoteImpl(long nativePtr) { + mNativePtr = nativePtr; + } + + private native void unref(long nativePtr); + protected void finalize() { + unref(mNativePtr); + } + + private native String getContent(long nativePtr); + @Override + public String getContent() { + return getContent(mNativePtr); + } + + private native String getLang(long nativePtr); + @Override + public String getLang() { + return getLang(mNativePtr); + } +}