From ad406033c0f2043d2a3bf73f5b8c8204c48c35a5 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 18 Jun 2013 22:11:36 +0200 Subject: [PATCH] add java wrapper and jni for LinphoneEvent API --- coreapi/linphonecore_jni.cc | 349 +++++++++++++++++- .../org/linphone/core/LinphoneEvent.java | 12 + java/common/org/linphone/core/Privacy.java | 11 + .../org/linphone/core/SubscriptionDir.java | 19 +- .../org/linphone/core/SubscriptionState.java | 32 +- .../org/linphone/core/LinphoneCoreImpl.java | 15 +- .../org/linphone/core/LinphoneEventImpl.java | 91 +++++ 7 files changed, 496 insertions(+), 33 deletions(-) create mode 100644 java/common/org/linphone/core/Privacy.java create mode 100644 java/impl/org/linphone/core/LinphoneEventImpl.java diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 0e0eae1b4..4e638e233 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -56,6 +56,8 @@ static jclass handler_class; static jmethodID loghandler_id; static jobject handler_obj=NULL; +static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *content); + #ifdef ANDROID void linphone_android_log_handler(int prio, char *str) { char *current; @@ -150,6 +152,8 @@ public: vTable.call_stats_updated = callStatsUpdated; vTable.transfer_state_changed = transferStateChanged; vTable.info_received = infoReceived; + vTable.subscription_state_changed=subscriptionStateChanged; + vTable.notify_received=notifyReceived; listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener)); @@ -200,6 +204,12 @@ public: infoReceivedId = env->GetMethodID(listenerClass,"infoReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneInfoMessage;)V"); + subscriptionStateId = env->GetMethodID(listenerClass,"subscriptionStateChanged", + "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/SubscriptionState;)V"); + notifyRecvId = env->GetMethodID(listenerClass,"notifyReceived", + "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Ljava/lang/String;Lorg/linphone/core/LinphoneContent;)V"); + + proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl")); proxyCtrId = env->GetMethodID(proxyClass,"", "(J)V"); @@ -225,6 +235,15 @@ public: infoMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneInfoMessageImpl")); infoMessageCtor = env->GetMethodID(infoMessageClass,"", "(J)V"); + + linphoneEventClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneEventImpl")); + linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"", "(J)V"); + + subscriptionStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionState")); + subscriptionStateFromIntId = env->GetStaticMethodID(subscriptionStateClass,"fromInt","(I)Lorg/linphone/core/SubscriptionState;"); + + subscriptionDirClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionDir")); + subscriptionDirFromIntId = env->GetStaticMethodID(subscriptionDirClass,"fromInt","(I)Lorg/linphone/core/SubscriptionDir;"); } ~LinphoneCoreData() { @@ -244,6 +263,9 @@ public: env->DeleteGlobalRef(chatRoomClass); env->DeleteGlobalRef(friendClass); env->DeleteGlobalRef(infoMessageClass); + env->DeleteGlobalRef(linphoneEventClass); + env->DeleteGlobalRef(subscriptionStateClass); + env->DeleteGlobalRef(subscriptionDirClass); } jobject core; jobject listener; @@ -259,6 +281,8 @@ public: jmethodID callStatsUpdatedId; jmethodID transferStateId; jmethodID infoReceivedId; + jmethodID subscriptionStateId; + jmethodID notifyRecvId; jclass globalStateClass; jmethodID globalStateId; @@ -306,6 +330,15 @@ public: jclass infoMessageClass; jmethodID infoMessageCtor; + + jclass linphoneEventClass; + jmethodID linphoneEventCtrId; + + jclass subscriptionStateClass; + jmethodID subscriptionStateFromIntId; + + jclass subscriptionDirClass; + jmethodID subscriptionDirFromIntId; LinphoneCoreVTable vTable; @@ -319,7 +352,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -335,7 +368,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -349,7 +382,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -383,7 +416,7 @@ public: jint result = jvm->AttachCurrentThread(&env,NULL); jobject jcall; if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -402,7 +435,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -417,7 +450,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -430,7 +463,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -444,7 +477,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -458,7 +491,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -473,7 +506,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -487,7 +520,7 @@ public: JNIEnv *env = 0; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -509,7 +542,7 @@ public: jobject callobj; jint result = jvm->AttachCurrentThread(&env,NULL); if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -526,7 +559,7 @@ public: jint result = jvm->AttachCurrentThread(&env,NULL); jobject jcall; if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); @@ -542,7 +575,7 @@ public: jint result = jvm->AttachCurrentThread(&env,NULL); jobject jcall; if (result != 0) { - ms_error("cannot attach VM\n"); + ms_error("cannot attach VM"); return; } LinphoneInfoMessage *copy_info=linphone_info_message_copy(info); @@ -554,8 +587,60 @@ public: ,env->NewObject(lcData->infoMessageClass,lcData->infoMessageCtor,(jlong)copy_info) ); } - + jobject getEvent(JNIEnv *env, LinphoneEvent *lev){ + if (lev==NULL) return NULL; + jobject jev=(jobject)linphone_event_get_user_data(lev); + if (jev==NULL){ + jev=env->NewObject(linphoneEventClass,linphoneEventCtrId,(jlong)linphone_event_ref(lev)); + jev=env->NewGlobalRef(jev); + linphone_event_set_user_data(lev,jev); + } + return jev; + } + static void subscriptionStateChanged(LinphoneCore *lc, LinphoneEvent *ev, LinphoneSubscriptionState state){ + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + jobject jevent; + jobject jstate; + if (result != 0) { + ms_error("cannot attach VM"); + return; + } + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + jevent=lcData->getEvent(env,ev); + jstate=env->CallStaticObjectMethod(lcData->subscriptionStateClass,lcData->subscriptionStateFromIntId,(jint)state); + env->CallVoidMethod(lcData->listener + ,lcData->subscriptionStateId + ,lcData->core + ,jevent + ,jstate + ); + if (state==LinphoneSubscriptionTerminated || state==LinphoneSubscriptionError){ + /*loose the java reference */ + linphone_event_set_user_data(ev,NULL); + env->DeleteGlobalRef(jevent); + } + } + static void notifyReceived(LinphoneCore *lc, LinphoneEvent *ev, const char *evname, const LinphoneContent *content){ + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + jobject jevent; + if (result != 0) { + ms_error("cannot attach VM"); + return; + } + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + jevent=lcData->getEvent(env,ev); + env->CallVoidMethod(lcData->listener + ,lcData->notifyRecvId + ,lcData->core + ,jevent + ,env->NewStringUTF(evname) + ,content ? create_java_linphone_content(env,content) : NULL + ); + } }; + extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env ,jobject thiz ,jobject jlistener @@ -2597,6 +2682,76 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getUpnpExternalIpaddr return jvalue; } + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: subscribe + * Signature: (JJLjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIEnv *env, jobject jcore, jlong coreptr, jlong addrptr, + jstring jevname, jint expires, jstring jtype, jstring jsubtype, jstring jdata){ + LinphoneCore *lc=(LinphoneCore*)coreptr; + LinphoneAddress *addr=(LinphoneAddress*)addrptr; + LinphoneContent content={0}; + LinphoneEvent *ev; + jobject jev=NULL; + const char *evname=env->GetStringUTFChars(jevname,NULL); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + + if (jtype){ + content.type=(char*)env->GetStringUTFChars(jtype,NULL); + content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); + content.data=(void*)env->GetStringUTFChars(jdata,NULL); + content.size=strlen((char*)content.data); + } + ev=linphone_core_subscribe(lc,addr,evname,expires,content.type ? &content : NULL); + if (jtype){ + env->ReleaseStringUTFChars(jtype,content.type); + env->ReleaseStringUTFChars(jsubtype,content.subtype); + env->ReleaseStringUTFChars(jdata,(char*)content.data); + } + env->ReleaseStringUTFChars(jevname,evname); + if (ev){ + jev=lcData->getEvent(env,ev); + } + return jev; +} + +/* + * Class: org_linphone_core_LinphoneCoreImpl + * Method: publish + * Signature: (JJLjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv *env, jobject jobj, jlong coreptr, jlong addrptr, jstring jevname, jint expires, + jstring jtype, jstring jsubtype, jstring jdata){ + LinphoneCore *lc=(LinphoneCore*)coreptr; + LinphoneAddress *addr=(LinphoneAddress*)addrptr; + LinphoneContent content={0}; + LinphoneEvent *ev; + jobject jev=NULL; + const char *evname=env->GetStringUTFChars(jevname,NULL); + LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc); + + if (jtype){ + content.type=(char*)env->GetStringUTFChars(jtype,NULL); + content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); + content.data=(void*)env->GetStringUTFChars(jdata,NULL); + content.size=strlen((char*)content.data); + } + ev=linphone_core_publish(lc,addr,evname,expires,content.type ? &content : NULL); + if (jtype){ + env->ReleaseStringUTFChars(jtype,content.type); + env->ReleaseStringUTFChars(jsubtype,content.subtype); + env->ReleaseStringUTFChars(jdata,(char*)content.data); + } + env->ReleaseStringUTFChars(jevname,evname); + if (ev){ + jev=lcData->getEvent(env,ev); + } + return jev; +} + + extern "C" jlong Java_org_linphone_core_LpConfigImpl_newLpConfigImpl(JNIEnv *env, jobject thiz, jstring file) { const char *cfile = env->GetStringUTFChars(file, NULL); LpConfig *lp = lp_config_new(cfile); @@ -2635,7 +2790,6 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent * jsubtype=env->NewStringUTF(content->subtype); jdata=content->data ? env->NewStringUTF((const char*)content->data) : NULL; jobject jobj=env->NewObject(contentClass,ctor,jtype, jsubtype, jdata); - env->DeleteGlobalRef(contentClass); return jobj; } @@ -2659,7 +2813,6 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_getCont * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_setContent(JNIEnv *env, jobject jobj, jlong infoptr, jstring jtype, jstring jsubtype, jstring jdata){ - const char *type,*subtype,*data; LinphoneContent content; content.type=(char*)env->GetStringUTFChars(jtype,NULL); @@ -2725,4 +2878,166 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreFactoryImpl__1setLogHa } } +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: getEventName + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneEventImpl_getEventName(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + const char *evname=linphone_event_get_name(ev); + return evname ? env->NewStringUTF(evname) : NULL; +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: acceptSubscription + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_acceptSubscription(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + return linphone_event_accept_subscription(ev); +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: denySubscription + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_denySubscription(JNIEnv *env, jobject jobj, jlong evptr, int reason){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + return linphone_event_deny_subscription(ev,(LinphoneReason)reason); +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: notify + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_notify(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jstring jdata){ + LinphoneContent content={0}; + LinphoneEvent *ev=(LinphoneEvent*)evptr; + jint err; + + if (jtype){ + content.type=(char*)env->GetStringUTFChars(jtype,NULL); + content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); + content.data=(void*)env->GetStringUTFChars(jdata,NULL); + content.size=strlen((char*)content.data); + } + + err=linphone_event_notify(ev,content.type ? &content : NULL); + + if (jtype){ + env->ReleaseStringUTFChars(jtype,content.type); + env->ReleaseStringUTFChars(jsubtype,content.subtype); + env->ReleaseStringUTFChars(jdata,(char*)content.data); + } + return err; +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: updateSubscribe + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updateSubscribe(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jstring jdata){ + LinphoneContent content={0}; + LinphoneEvent *ev=(LinphoneEvent*)evptr; + jint err; + + if (jtype){ + content.type=(char*)env->GetStringUTFChars(jtype,NULL); + content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); + content.data=(void*)env->GetStringUTFChars(jdata,NULL); + content.size=strlen((char*)content.data); + } + + err=linphone_event_update_subscribe(ev,content.type ? &content : NULL); + + if (jtype){ + env->ReleaseStringUTFChars(jtype,content.type); + env->ReleaseStringUTFChars(jsubtype,content.subtype); + env->ReleaseStringUTFChars(jdata,(char*)content.data); + } + return err; +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: updatePublish + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updatePublish(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jstring jdata){ + LinphoneContent content={0}; + LinphoneEvent *ev=(LinphoneEvent*)evptr; + jint err; + + if (jtype){ + content.type=(char*)env->GetStringUTFChars(jtype,NULL); + content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); + content.data=(void*)env->GetStringUTFChars(jdata,NULL); + content.size=strlen((char*)content.data); + } + + err=linphone_event_update_publish(ev,content.type ? &content : NULL); + + if (jtype){ + env->ReleaseStringUTFChars(jtype,content.type); + env->ReleaseStringUTFChars(jsubtype,content.subtype); + env->ReleaseStringUTFChars(jdata,(char*)content.data); + } + return err; +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: terminate + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_terminate(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + linphone_event_terminate(ev); + return 0; +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: getReason + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_getReason(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + return linphone_event_get_reason(ev); +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: getSubscriptionDir + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_getSubscriptionDir(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + return linphone_event_get_subscription_dir(ev); +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: getSubscriptionState + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_getSubscriptionState(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + return linphone_event_get_subscription_state(ev); +} + +/* + * Class: org_linphone_core_LinphoneEventImpl + * Method: unref + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_unref(JNIEnv *env, jobject jobj, jlong evptr){ + LinphoneEvent *ev=(LinphoneEvent*)evptr; + linphone_event_unref(ev); +} diff --git a/java/common/org/linphone/core/LinphoneEvent.java b/java/common/org/linphone/core/LinphoneEvent.java index 26f55c9f1..865200dfd 100644 --- a/java/common/org/linphone/core/LinphoneEvent.java +++ b/java/common/org/linphone/core/LinphoneEvent.java @@ -6,6 +6,18 @@ public interface LinphoneEvent { * @return the event name. */ String getEventName(); + + /** + * Return subscription direction (incoming or outgoing). For publish initiated LinphoneEvent it is set to Invalid. + * @return the subscription direction. + */ + SubscriptionDir getSubscriptionDir(); + + /** + * Get subscription state. + * @return the current subscription state. + */ + SubscriptionState getSubscriptionState(); /** * Accept an incoming subscription. After it is accepted the application can immediately start to send notifications with * {@link LinphoneEvent.notify() }. diff --git a/java/common/org/linphone/core/Privacy.java b/java/common/org/linphone/core/Privacy.java new file mode 100644 index 000000000..59acc7565 --- /dev/null +++ b/java/common/org/linphone/core/Privacy.java @@ -0,0 +1,11 @@ +package org.linphone.core; + +public interface Privacy { + public static final int NONE=0; + public static final int USER=0x1; + public static final int HEADER=0x2; + public static final int SESSION=0x4; + public static final int ID=0x8; + public static final int CRITICAL=0x10; + public static final int DEFAULT=0x8000; +} diff --git a/java/common/org/linphone/core/SubscriptionDir.java b/java/common/org/linphone/core/SubscriptionDir.java index e18639efc..151bd4e15 100644 --- a/java/common/org/linphone/core/SubscriptionDir.java +++ b/java/common/org/linphone/core/SubscriptionDir.java @@ -1,7 +1,20 @@ package org.linphone.core; +import java.util.Vector; + public enum SubscriptionDir { - Incoming, - Outgoing, - Invalid + Incoming(0), + Outgoing(1), + Invalid(2); + protected final int mValue; + private SubscriptionDir(int value){ + mValue=value; + } + static protected SubscriptionDir fromInt(int value){ + switch(value){ + case 0: return Incoming; + case 1: return Outgoing; + } + return Invalid; + } } diff --git a/java/common/org/linphone/core/SubscriptionState.java b/java/common/org/linphone/core/SubscriptionState.java index 4ab9f7ca6..a6e84ec6a 100644 --- a/java/common/org/linphone/core/SubscriptionState.java +++ b/java/common/org/linphone/core/SubscriptionState.java @@ -4,29 +4,47 @@ public enum SubscriptionState { /** * Initial state, should not be used. */ - LinphoneSubscriptionNone, + None(0), /** * An outgoing subcription was created. */ - LinphoneSubscriptionOutoingInit, + OutoingInit(1), /** * An incoming subcription is received. */ - LinphoneSubscriptionIncomingReceived, + IncomingReceived(2), /** * Subscription is pending, waiting for user approval */ - LinphoneSubscriptionPending, + Pending(3), /** * Subscription is accepted and now active. */ - LinphoneSubscriptionActive, + Active(4), /** * Subscription is terminated normally */ - LinphoneSubscriptionTerminated, + Terminated(5), /** * Subscription encountered an error, indicated by { @link LinphoneEvent.getReason() } */ - LinphoneSubscriptionError + Error(6); + + protected final int mValue; + private SubscriptionState(int value){ + mValue=value; + } + static protected SubscriptionState fromInt(int value) throws LinphoneCoreException{ + switch(value){ + case 0: return None; + case 1: return OutoingInit; + case 2: return IncomingReceived; + case 3: return Pending; + case 4: return Active; + case 5: return Terminated; + case 6: return Error; + default: + throw new LinphoneCoreException("Unhandled enum value "+value+" for SubscriptionState"); + } + } } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index bcf128f08..ae9b26fe8 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -954,16 +954,19 @@ class LinphoneCoreImpl implements LinphoneCore { public LinphoneInfoMessage createInfoMessage() { return new LinphoneInfoMessageImpl(createInfoMessage(nativePtr)); } + + private native Object subscribe(long coreptr, long addrptr, String eventname, int expires, String type, String subtype, String data); @Override - public LinphoneEvent subscribe(LinphoneAddress resource, String event, + public LinphoneEvent subscribe(LinphoneAddress resource, String eventname, int expires, LinphoneContent content) { - // TODO Auto-generated method stub - return null; + return (LinphoneEvent)subscribe(nativePtr, ((LinphoneAddressImpl)resource).nativePtr, eventname, expires, + content!=null ? content.getType() : null, content!=null ? content.getSubtype() : null, content!=null ? content.getDataAsString() : null); } + private native Object publish(long coreptr, long addrptr, String eventname, int expires, String type, String subtype, String data); @Override - public LinphoneEvent publish(LinphoneAddress resource, String event, + public LinphoneEvent publish(LinphoneAddress resource, String eventname, int expires, LinphoneContent content) { - // TODO Auto-generated method stub - return null; + return (LinphoneEvent)publish(nativePtr, ((LinphoneAddressImpl)resource).nativePtr, eventname, expires, + content!=null ? content.getType() : null, content!=null ? content.getSubtype() : null, content!=null ? content.getDataAsString() : null); } } diff --git a/java/impl/org/linphone/core/LinphoneEventImpl.java b/java/impl/org/linphone/core/LinphoneEventImpl.java new file mode 100644 index 000000000..ab201af99 --- /dev/null +++ b/java/impl/org/linphone/core/LinphoneEventImpl.java @@ -0,0 +1,91 @@ +package org.linphone.core; + +public class LinphoneEventImpl implements LinphoneEvent { + private Object mUserContext; + private long mNativePtr; + + protected LinphoneEventImpl(long nativePtr){ + mNativePtr=nativePtr; + } + + private native String getEventName(long nativeptr); + @Override + public String getEventName() { + return getEventName(mNativePtr); + } + + private native int acceptSubscription(long nativeptr); + @Override + public void acceptSubscription() { + acceptSubscription(mNativePtr); + } + + private native int denySubscription(long nativeptr, int reason); + @Override + public void denySubscription(Reason reason) { + denySubscription(mNativePtr,reason.mValue); + } + + private native int notify(long nativeptr, String type, String subtype, String data); + @Override + public void notify(LinphoneContent content) { + notify(mNativePtr,content.getType(),content.getSubtype(),content.getDataAsString()); + } + + private native int updateSubscribe(long nativePtr, String type, String subtype, String data); + @Override + public void updateSubscribe(LinphoneContent content) { + updateSubscribe(mNativePtr,content.getType(), content.getSubtype(),content.getDataAsString()); + } + + private native int updatePublish(long nativePtr, String type, String subtype, String data); + @Override + public void updatePublish(LinphoneContent content) { + updatePublish(mNativePtr,content.getType(), content.getSubtype(),content.getDataAsString()); + } + + private native int terminate(long nativePtr); + @Override + public void terminate() { + terminate(mNativePtr); + } + + private native int getReason(long nativePtr); + @Override + public Reason getReason() { + return Reason.fromInt(getReason(mNativePtr)); + } + + @Override + public void setUserContext(Object obj) { + mUserContext=obj; + } + + @Override + public Object getUserContext() { + return mUserContext; + } + + private native int getSubscriptionDir(long nativeptr); + @Override + public SubscriptionDir getSubscriptionDir() { + return SubscriptionDir.fromInt(getSubscriptionDir(mNativePtr)); + } + + private native int getSubscriptionState(long nativeptr); + @Override + public SubscriptionState getSubscriptionState() { + try { + return SubscriptionState.fromInt(getSubscriptionState(mNativePtr)); + } catch (LinphoneCoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return SubscriptionState.Error; + } + private native void unref(long nativeptr); + protected void finalize(){ + unref(mNativePtr); + } + +}