From ff688cd975818b34fce5230139a6405d8a56ac88 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 11 Oct 2017 15:03:50 +0200 Subject: [PATCH] Finished removeCallbacks in JNI layer for Java wrapper for multi listenable classes --- coreapi/vtables.c | 10 ++++++++++ include/linphone/api/c-call.h | 7 +++++++ include/linphone/core.h | 8 ++++++++ src/c-wrapper/api/c-call.cpp | 4 ++++ wrappers/java/jni.mustache | 16 +++++++++++++--- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/coreapi/vtables.c b/coreapi/vtables.c index 7b0fb82c8..6a8691c02 100644 --- a/coreapi/vtables.c +++ b/coreapi/vtables.c @@ -332,6 +332,16 @@ void linphone_core_remove_listener(LinphoneCore *lc, const LinphoneCoreVTable *v } } +bctbx_list_t *linphone_core_get_callbacks(const LinphoneCore *lc) { + bctbx_list_t *result; + bctbx_list_t *it; + for(it=lc->vtable_refs; it!=NULL; it=it->next){ + VTableReference *ref=(VTableReference*)it->data; + result = bctbx_list_append(result, ref->cbs); + } + return result; +} + void linphone_core_remove_callbacks(LinphoneCore *lc, const LinphoneCoreCbs *cbs) { bctbx_list_t *it; ms_message("Callbacks [%p] unregistered on core [%p]",cbs,lc); diff --git a/include/linphone/api/c-call.h b/include/linphone/api/c-call.h index fe3c2c768..589056f19 100644 --- a/include/linphone/api/c-call.h +++ b/include/linphone/api/c-call.h @@ -756,6 +756,13 @@ LINPHONE_PUBLIC void linphone_call_add_callbacks(LinphoneCall *call, LinphoneCal */ LINPHONE_PUBLIC void linphone_call_remove_callbacks(LinphoneCall *call, LinphoneCallCbs *cbs); +/** + * Gets the list of listener in the call + * @param[in] call LinphoneCall object + * @return the list of LinphoneCallCbs + */ +LINPHONE_PUBLIC const bctbx_list_t *linphone_call_get_callbacks(const LinphoneCall *call); + /** * Gets the current LinphoneCallCbs. * This is meant only to be called from a callback to be able to get the user_data associated with the LinphoneCallCbs that is calling the callback. diff --git a/include/linphone/core.h b/include/linphone/core.h index e78ba8e4c..421e88e28 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -975,6 +975,14 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_remove_listener(LinphoneC */ LINPHONE_PUBLIC void linphone_core_remove_callbacks(LinphoneCore *lc, const LinphoneCoreCbs *cbs); +/** + * @ingroup initializing + * Gets the list of listener in the core + * @param lc The #LinphoneCore + * @return the list of LinphoneCoreCbs + */ +LINPHONE_PUBLIC bctbx_list_t *linphone_core_get_callbacks(const LinphoneCore *lc); + /** * Sets the user agent string used in SIP messages, ideally called just after linphone_core_new() or linphone_core_init(). * @param[in] lc LinphoneCore object diff --git a/src/c-wrapper/api/c-call.cpp b/src/c-wrapper/api/c-call.cpp index bc33b1ae5..47a6492cc 100644 --- a/src/c-wrapper/api/c-call.cpp +++ b/src/c-wrapper/api/c-call.cpp @@ -1097,6 +1097,10 @@ LinphoneCallCbs *linphone_call_get_current_callbacks (const LinphoneCall *call) return call->currentCbs; } +const bctbx_list_t *linphone_call_get_callbacks(const LinphoneCall *call) { + return call->callbacks; +} + void linphone_call_set_params (LinphoneCall *call, const LinphoneCallParams *params) { #if 0 if ( call->state == LinphoneCallOutgoingInit || call->state == LinphoneCallIncomingReceived){ diff --git a/wrappers/java/jni.mustache b/wrappers/java/jni.mustache index 083d42ec6..f0040cc49 100644 --- a/wrappers/java/jni.mustache +++ b/wrappers/java/jni.mustache @@ -224,7 +224,7 @@ void {{jniPackage}}{{classCName}}Impl_addListener(JNIEnv* env, jobject thiz, jlo {{classCName}} *cptr = ({{classCName}}*)ptr; jobject listener = env->NewGlobalRef(jlistener); {{#isSingleListener}} - {{classCName}}Cbs *cbs = {{cPrefix}}_get_callbacks(request); + {{classCName}}Cbs *cbs = {{cPrefix}}_get_callbacks(cptr); {{/isSingleListener}} {{#isMultiListener}} {{classCName}}Cbs *cbs = linphone_factory_create_{{factoryName}}_cbs(NULL); @@ -233,13 +233,23 @@ void {{jniPackage}}{{classCName}}Impl_addListener(JNIEnv* env, jobject thiz, jlo {{#callbacksList}} {{cPrefix}}_cbs_set_{{callback}}(cbs, {{callbackName}}); {{/callbacksList}} + {{#isMultiListener}} + {{cPrefix}}_add_callbacks(cptr, cbs); + {{/isMultiListener}} } {{#isMultiListener}} void {{jniPackage}}{{classCName}}Impl_removeListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { {{classCName}} *cptr = ({{classCName}}*)ptr; - //TODO - {{cPrefix}}_remove_callbacks(ptr, ); + const bctbx_list_t *cbs_list = {{cPrefix}}_get_callbacks(cptr); + bctbx_list_t *it; + for (it = cbs_list; it != NULL; it = it->next) { + {{classCName}}Cbs *cbs = ({{classCName}}Cbs *)it->data; + if ({{cPrefix}}_cbs_get_user_data(cbs) == jlistener) { + {{cPrefix}}_remove_callbacks(cptr, cbs); + break; + } + } } {{/isMultiListener}}