From 95c893dcc1de29a72836ea98e0915eceffc1e88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Wed, 6 Jan 2016 13:54:22 +0100 Subject: [PATCH] Wrap LinphoneConference class into Java --- coreapi/linphonecore_jni.cc | 30 +++++++++++++ .../org/linphone/core/LinphoneCall.java | 11 ++++- .../org/linphone/core/LinphoneConference.java | 39 +++++++++++++++++ .../org/linphone/core/LinphoneCore.java | 7 +++ .../org/linphone/core/LinphoneCallImpl.java | 7 ++- .../linphone/core/LinphoneConferenceImpl.java | 43 +++++++++++++++++++ .../org/linphone/core/LinphoneCoreImpl.java | 4 ++ 7 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 java/common/org/linphone/core/LinphoneConference.java create mode 100644 java/impl/org/linphone/core/LinphoneConferenceImpl.java diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index f6361e389..7c3714d85 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -4135,6 +4135,10 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv return (jint)linphone_core_get_conference_size((LinphoneCore *) pCore); } +extern "C" jlong Jave_org_linphone_core_LinphoneCoreImpl_getConference(JNIEnv *env, jobject thiz, jlong pCore) { + return (jlong)linphone_core_get_conference((LinphoneCore *)pCore); +} + extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startConferenceRecording(JNIEnv *env,jobject thiz,jlong pCore, jstring jpath){ int err=-1; if (jpath){ @@ -4269,6 +4273,10 @@ extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVe linphone_call_set_authentication_token_verified(call, verified); } +extern "C" jlong Java_org_linphnoe_core_LinphoneCallImpl_getConference(JNIEnv *env, jobject thiz, jlong ptr) { + return (jlong)linphone_call_get_conference((LinphoneCall *)ptr); +} + extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getPlayVolume(JNIEnv* env, jobject thiz, jlong ptr) { LinphoneCall *call = (LinphoneCall *) ptr; return (jfloat)linphone_call_get_play_volume(call); @@ -6570,4 +6578,26 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getSipTransportTi return linphone_core_get_sip_transport_timeout((LinphoneCore*)pcore); } +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneConferenceImpl_getParticipants(JNIEnv *env, jobject thiz, jlong pconference) { + MSList *participants, *it; + jclass addr_class = env->FindClass("org/linphone/core/LinphoneAddressImpl"); + jclass addr_list_class = env->FindClass("[Lorg/linphone/core/LinphoneAddressImpl;"); + jmethodID addr_constructor = env->GetMethodID(addr_class, "", "(J)"); + jmethodID addr_list_constructor = env->GetMethodID(addr_list_class, "", "(V)"); + jmethodID addr_list_append = env->GetMethodID(addr_list_class, "add", "(Lorg/linphone/core/LinphoneAddressImpl;)Z"); + jobject jaddr_list = env->NewObject(addr_list_class, addr_list_constructor); + + participants = linphone_conference_get_participants((LinphoneConference *)pconference); + for(it = participants; it; it = ms_list_next(it)) { + LinphoneAddress *addr = (LinphoneAddress *)it->data; + jobject jaddr = env->NewObject(addr_class, addr_constructor, addr); + env->CallBooleanMethod(jaddr_list, addr_list_append, jaddr); + } + return jaddr_list; +} +JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneConferenteImpl_removeParticipant(JNIEnv *env, jobject thiz, jlong pconference, jobject uri) { + jfieldID native_ptr_attr = env->GetFieldID(env->GetObjectClass(uri), "nativePtr", "J"); + LinphoneAddress *addr = (LinphoneAddress *)env->GetLongField(uri, native_ptr_attr); + return linphone_conference_remove_participant((LinphoneConference *)pconference, addr); +} diff --git a/java/common/org/linphone/core/LinphoneCall.java b/java/common/org/linphone/core/LinphoneCall.java index ad10b96b1..3ab28d437 100644 --- a/java/common/org/linphone/core/LinphoneCall.java +++ b/java/common/org/linphone/core/LinphoneCall.java @@ -273,8 +273,17 @@ public interface LinphoneCall { * @param verified true when displayed SAS is correct */ void setAuthenticationTokenVerified(boolean verified); - + + /** + * Checks wether the call is part of a conferece. + * @return A boolean + */ boolean isInConference(); + /** + * Get the pointer on the C conference instance associated to that call. + * @return A positive value if the call is part of a conference, 0 if not. + */ + long getConference(); /** * Indicates whether an operation is in progress at the media side. diff --git a/java/common/org/linphone/core/LinphoneConference.java b/java/common/org/linphone/core/LinphoneConference.java new file mode 100644 index 000000000..9fb25d518 --- /dev/null +++ b/java/common/org/linphone/core/LinphoneConference.java @@ -0,0 +1,39 @@ +/* +LinphoneConference.java +Copyright (C) 2015 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; + +import org.linphone.core.LinphoneAddress; +import java.util.List; + +/** + * Interface to manipulate a running conference + */ +public interface LinphoneConference { + /** + * Get the URIs of all participants of the conference + */ + public List getParticipants(); + /** + * Remove a participant from the conference + * @param uri The URI of the participant to remove + * @return 0 if succeed, -1 if not. + */ + public int removeParticipant(LinphoneAddress uri); +} diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index f2ce0ccab..0ff6c25bd 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1407,6 +1407,13 @@ public interface LinphoneCore { * @returns the number of participants to the conference **/ int getConferenceSize(); + /** + * Return the value of the C pointer on the conference instance. + * + * That function can be used to test whether a conference is running. + * @return A positive value if a conference is running, 0 if not. + **/ + long getConference(); /** * Request recording of the conference into a supplied file path. diff --git a/java/impl/org/linphone/core/LinphoneCallImpl.java b/java/impl/org/linphone/core/LinphoneCallImpl.java index f04ce86d8..28f6302d1 100644 --- a/java/impl/org/linphone/core/LinphoneCallImpl.java +++ b/java/impl/org/linphone/core/LinphoneCallImpl.java @@ -165,8 +165,11 @@ class LinphoneCallImpl implements LinphoneCall { } public boolean isInConference() { - LinphoneCallParamsImpl params = new LinphoneCallParamsImpl(getCurrentParamsCopy(nativePtr)); - return params.localConferenceMode(); + return getConference() != 0; + } + private native long getConference(long nativePtr); + public long getConference() { + return getConference(nativePtr); } public boolean mediaInProgress() { return mediaInProgress(nativePtr);} diff --git a/java/impl/org/linphone/core/LinphoneConferenceImpl.java b/java/impl/org/linphone/core/LinphoneConferenceImpl.java new file mode 100644 index 000000000..4e77a3414 --- /dev/null +++ b/java/impl/org/linphone/core/LinphoneConferenceImpl.java @@ -0,0 +1,43 @@ +/* +LinphoneConferenceImpl.java +Copyright (C) 2015 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; + +import org.linphone.core.LinphoneConference; +import java.util.List; + +public class LinphoneConferenceImpl implements LinphoneConference { + private final long nativePtr; + + private LinphoneConferenceImpl(long nativePtr) { + this.nativePtr = nativePtr; + } + private native void finalize(long nativePtr); + protected void finalize() { + finalize(nativePtr); + } + private native List getParticipants(long nativePtr); + public List getParticipants() { + return getParticipants(nativePtr); + } + private native int removeParticipant(long nativePtr, LinphoneAddress uri); + public int removeParticipant(LinphoneAddress uri) { + return removeParticipant(nativePtr, uri); + } +} diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 87842c78e..c81100c5c 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -709,6 +709,10 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized int getConferenceSize() { return getConferenceSize(nativePtr); } + private native long getConference(long nativePtr); + public synchronized long getConference() { + return getConference(nativePtr); + } private native int getCallsNb(long nativePtr); public synchronized int getCallsNb() { return getCallsNb(nativePtr);