From 719259dd0a4e3b36b9fbf1827738abc2326c735f Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@gmail.com>
Date: Thu, 7 Aug 2014 12:10:13 -0400
Subject: [PATCH] Update swig interface

---
 sflphone-android/jni/Android.mk             |   3 +-
 sflphone-android/jni/callmanager.i          | 224 +++++---------------
 sflphone-android/jni/configurationmanager.i |  80 ++-----
 sflphone-android/jni/jni_interface.i        |  66 +++++-
 sflphone-android/jni/managerimpl.i          |  35 ++-
 5 files changed, 151 insertions(+), 257 deletions(-)

diff --git a/sflphone-android/jni/Android.mk b/sflphone-android/jni/Android.mk
index 83b6115f8..ad37e636f 100644
--- a/sflphone-android/jni/Android.mk
+++ b/sflphone-android/jni/Android.mk
@@ -48,8 +48,7 @@ CPP_STATIC=$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++$(CXXSTL)/libs/$(ARCH)/li
 LOCAL_CPPFLAGS += -frtti
 LOCAL_CPPFLAGS += -fexceptions
 
-LOCAL_SRC_FILES :=	$(LOCAL_SRC_PATH)/sflphone_api.cpp \
-					sflphone_wrapper.cpp
+LOCAL_SRC_FILES :=  sflphone_wrapper.cpp
 
 LOCAL_C_INCLUDES += $(LOCAL_PATH) \
 					$(LOCAL_SRC_PATH) \
diff --git a/sflphone-android/jni/callmanager.i b/sflphone-android/jni/callmanager.i
index 127c89b9b..fd6d519ea 100644
--- a/sflphone-android/jni/callmanager.i
+++ b/sflphone-android/jni/callmanager.i
@@ -32,183 +32,34 @@
 
 #include "sflphone.h"
 
-
 class CallManagerCallback {
 public:
-    static void on_new_call_created(const std::string& arg1,
-                                     const std::string& arg2,
-                                     const std::string& arg3);
-
-    static void on_call_state_changed(const std::string& arg1,
-                                       const std::string& arg2);
-
-    static void on_incoming_call(const std::string& arg1,
-                                  const std::string& arg2,
-                                  const std::string& arg3);
-
-    static void on_transfer_state_changed(const std::string& arg1);
-
-    static void on_conference_created(const std::string& arg1);
-
-    static void on_conference_removed(const std::string& arg1);
-
-    static void on_conference_state_changed(const std::string& arg1,
-                                              const std::string& arg2);
-
-    static void on_incoming_message(const std::string& ID,
-                                    const std::string& from,
-                                    const std::string& msg);
-
-    static void on_record_playback_filepath(const std::string& id,
-                                            const std::string& filename);
-
-    static void on_recording_state_changed(const std::string& callID,
-                                            const bool& state);
-
-    static void newPresSubClientNotification(const std::string& uri,
-                                            const std::string& basic,
-                                            const std::string& note);
-
-    static void newPresSubServerRequest(const std::string& remote);
-
-    static void on_secure_sdes_on(const std::string& callID);
-
-    static void on_secure_sdes_off(const std::string& callID);
-
-    static void on_secure_zrtp_on(const std::string& callID,
-                                const std::string& cipher);
-
-    static void on_secure_zrtp_off(const std::string& callID);
-
-    static void on_show_sas(const std::string& callID,
-                        const std::string& sas,
-                        const bool& verified);
-
-    static void on_zrtp_not_supported(const std::string& callID);
-
-    static void on_zrtp_negociation_failed(const std::string& callID,
-                                                const std::string& reason,
-                                                const std::string& severity);
-
-    static void on_rtcp_report_received (const std::string& callID,
-                                    const std::map<std::string, int>& stats);
-
+    virtual ~CallManagerCallback() {}
+    static void callOnStateChange(const std::string& call_id, const std::string& state){}
+    static void callOnTransferFail(void){}
+    static void callOnTransferSuccess(void){}
+    static void callOnRecordPlaybackStopped(const std::string& path){}
+    static void callOnVoiceMailNotify(const std::string& call_id, int nd_msg){}
+    static void callOnIncomingMessage(const std::string& id, const std::string& from, const std::string& msg){}
+    static void callOnIncomingCall(const std::string& account_id, const std::string& call_id, const std::string& from){}
+    static void callOnRecordPlaybackFilepath(const std::string& id, const std::string& filename){}
+    static void callOnConferenceCreated(const std::string& conf_id){}
+    static void callOnConferenceChanged(const std::string& conf_id, const std::string& state){}
+    static void callOnUpdatePlaybackScale(const std::string& filepath, int position, int scale){}
+    static void callOnConferenceRemove(const std::string& conf_id){}
+    static void callOnNewCall(const std::string& account_id, const std::string& call_id, const std::string& to){}
+    static void callOnSipCallStateChange(const std::string& call_id, const std::string& state, int code){}
+    static void callOnRecordStateChange(const std::string& call_id, int state){}
+    static void callOnSecureSdesOn(const std::string& call_id){}
+    static void callOnSecureSdesOff(const std::string& call_id){}
+    static void callOnSecureZrtpOn(const std::string& call_id, const std::string& cipher){}
+    static void callOnSecureZrtpOff(const std::string& call_id){}
+    static void callOnShowSas(const std::string& call_id, const std::string& sas, int verified){}
+    static void callOnZrtpNotSuppOther(const std::string& call_id){}
+    static void callOnZrtpNegotiationFail(const std::string& call_id, const std::string& reason, const std::string& severity){}
+    static void callOnRtcpReceiveReport(const std::string& call_id, const std::map<std::string, int>& stats){}
 };
 
-static CallManagerCallback* registeredCallbackObject = NULL;
-
-void setCallbackObject(CallManagerCallback* callback) {
-    registeredCallbackObject = callback;
-}
-
-void on_new_call_created_wrapper (const std::string& accountID,
-                                  const std::string& callID,
-                                  const std::string& to) {
-    registeredCallbackObject->on_new_call_created(accountID, callID, to);
-}
-
-void on_call_state_changed_wrapper(const std::string& callID,
-                           const std::string& state) {
-    registeredCallbackObject->on_call_state_changed(callID, state);
-}
-
-void on_incoming_call_wrapper (const std::string& accountID,
-                               const std::string& callID,
-                               const std::string& from) {
-    registeredCallbackObject->on_incoming_call(accountID, callID, from);
-}
-
-void on_transfer_state_changed_wrapper (const std::string& result) {
-    registeredCallbackObject->on_transfer_state_changed(result);
-}
-
-void on_conference_created_wrapper (const std::string& confID) {
-    registeredCallbackObject->on_conference_created(confID);
-}
-
-void on_conference_removed_wrapper (const std::string& confID) {
-    registeredCallbackObject->on_conference_removed(confID);
-}
-
-void on_conference_state_changed_wrapper (const std::string& confID,
-                                          const std::string& state) {
-    registeredCallbackObject->on_conference_state_changed(confID, state);
-}
-
-void on_incoming_message_wrapper(const std::string& ID, const std::string& from, const std::string& msg) {
-    registeredCallbackObject->on_incoming_message(ID, from, msg);
-}
-
-void on_record_playback_filepath_wrapper(const std::string& id, const std::string& filename) {
-    registeredCallbackObject->on_record_playback_filepath(id, filename);
-}
-
-void on_recording_state_changed_wrapper(const std::string& callID, const bool& state) {
-    registeredCallbackObject->on_recording_state_changed(callID, state);
-}
-
-void on_newPresSubClientNotification_wrapper(const std::string& uri, const std::string& basic, const std::string& note) {
-    registeredCallbackObject->newPresSubClientNotification(uri, basic, note);
-}
-
-void on_newPresSubServerRequest_wrapper(const std::string& remote) {
-    registeredCallbackObject->newPresSubServerRequest(remote);
-}
-
-void on_secure_sdes_on_wrapper(const std::string& callID){
-    registeredCallbackObject->on_secure_sdes_on(callID);
-}
-
-void on_secure_sdes_off_wrapper(const std::string& callID) {
-    registeredCallbackObject->on_secure_sdes_off(callID);
-}
-
-void on_secure_zrtp_on_wrapper(const std::string& callID,const std::string& cipher){
-    registeredCallbackObject->on_secure_zrtp_on(callID, cipher);
-}
-
-void on_secure_zrtp_off_wrapper(const std::string& callID){
-    registeredCallbackObject->on_secure_zrtp_off(callID);
-}
-
-void on_show_sas_wrapper(const std::string& callID, const std::string& sas, const bool& verified){
-    registeredCallbackObject->on_show_sas(callID, sas, verified);
-}
-
-void on_zrtp_not_supported_wrapper(const std::string& callID){
-    registeredCallbackObject->on_zrtp_not_supported(callID);
-}
-
-void on_zrtp_negociation_failed_wrapper(const std::string& callID, const std::string& reason, const std::string& severity){
-    registeredCallbackObject->on_zrtp_negociation_failed(callID, reason, severity);
-}
-
-void on_rtcp_report_received_wrapper (const std::string& callID, const std::map<std::string, int>& stats){
-    registeredCallbackObject->on_rtcp_report_received(callID, stats);
-}
-
-static struct sflph_call_ev_handlers wrapper_callback_struct = {
-    &on_new_call_created_wrapper,
-    &on_call_state_changed_wrapper,
-    &on_incoming_call_wrapper,
-    &on_transfer_state_changed_wrapper,
-    &on_conference_created_wrapper,
-    &on_conference_removed_wrapper,
-    &on_conference_state_changed_wrapper,
-    &on_incoming_message_wrapper,
-    &on_record_playback_filepath_wrapper,
-    &on_recording_state_changed_wrapper,
-    &on_newPresSubClientNotification_wrapper,
-    &on_newPresSubServerRequest_wrapper,
-    &on_secure_sdes_on_wrapper,
-    &on_secure_sdes_off_wrapper,
-    &on_secure_zrtp_on_wrapper,
-    &on_secure_zrtp_off_wrapper,
-    &on_show_sas_wrapper,
-    &on_zrtp_not_supported_wrapper,
-    &on_zrtp_negociation_failed_wrapper,
-    &on_rtcp_report_received_wrapper
-};
 
 %}
 
@@ -256,3 +107,30 @@ void sflph_call_request_go_clear(const std::string& call_id);
 void sflph_call_accept_enrollment(const std::string& call_id, bool accepted);
 void sflph_call_send_text_message(const std::string& call_id, const std::string& message);
 
+class CallManagerCallback {
+public:
+    virtual ~CallManagerCallback();
+static void callOnStateChange(const std::string& call_id, const std::string& state);
+        static void callOnTransferFail(void);
+        static void callOnTransferSuccess(void);
+        static void callOnRecordPlaybackStopped(const std::string& path);
+        static void callOnVoiceMailNotify(const std::string& call_id, int nd_msg);
+        static void callOnIncomingMessage(const std::string& id, const std::string& from, const std::string& msg);
+        static void callOnIncomingCall(const std::string& account_id, const std::string& call_id, const std::string& from);
+        static void callOnRecordPlaybackFilepath(const std::string& id, const std::string& filename);
+        static void callOnConferenceCreated(const std::string& conf_id);
+        static void callOnConferenceChanged(const std::string& conf_id, const std::string& state);
+        static void callOnUpdatePlaybackScale(const std::string& filepath, int position, int scale);
+        static void callOnConferenceRemove(const std::string& conf_id);
+        static void callOnNewCall(const std::string& account_id, const std::string& call_id, const std::string& to);
+        static void callOnSipCallStateChange(const std::string& call_id, const std::string& state, int code);
+        static void callOnRecordStateChange(const std::string& call_id, int state);
+        static void callOnSecureSdesOn(const std::string& call_id);
+        static void callOnSecureSdesOff(const std::string& call_id);
+        static void callOnSecureZrtpOn(const std::string& call_id, const std::string& cipher);
+        static void callOnSecureZrtpOff(const std::string& call_id);
+        static void callOnShowSas(const std::string& call_id, const std::string& sas, int verified);
+        static void callOnZrtpNotSuppOther(const std::string& call_id);
+        static void callOnZrtpNegotiationFail(const std::string& call_id, const std::string& reason, const std::string& severity);
+        static void callOnRtcpReceiveReport(const std::string& call_id, const std::map<std::string, int>& stats);
+};
diff --git a/sflphone-android/jni/configurationmanager.i b/sflphone-android/jni/configurationmanager.i
index 5d2b1dee2..8e21e5a07 100644
--- a/sflphone-android/jni/configurationmanager.i
+++ b/sflphone-android/jni/configurationmanager.i
@@ -32,65 +32,16 @@
 
 class ConfigurationCallback {
 public:
-    static void on_volume_changed(void);
-    static void on_accounts_changed(void);
-    static void on_history_change(void);
-    static void on_stun_status_failed(const std::string& accountID);
-    static void on_account_state_changed(const std::string& accountID, const int32_t& state);
-    static void on_account_state_changed_with_code(const std::string& accountID, const std::string& state, const int32_t& code);
-    static void on_error(int alert);
-    static std::vector<int32_t> get_hardware_audio_format(void);
-};
-
-static ConfigurationCallback *registeredConfigurationCallbackObject = NULL;
-
-void setConfigurationCallbackObject(ConfigurationCallback *callback) {
-    registeredConfigurationCallbackObject = callback;
-}
-
-void on_volume_change_wrapper (void) {
-
-}
-
-void on_stun_status_fail_wrapper (const std::string& accountID) {
-
-}
-
-void on_history_change_wrapper (void) {
-
-}
-
-void on_error_wrapper (int alert) {
-
-}
-
-void on_accounts_changed_wrapper (void) {
-    registeredConfigurationCallbackObject->on_accounts_changed();
-}
+    virtual ~ConfigurationCallback(){}
+    static void configOnVolumeChange(const std::string& device, int value){}
+    static void configOnAccountsChange(void){}
+    static void configOnHistoryChange(void){}
+    static void configOnStunStatusFail(const std::string& account_id){}
+    static void configOnRegistrationStateChange(const std::string& account_id, int state){}
+    static void configOnSipRegistrationStateChange(const std::string& account_id, const std::string& state, int code){}
+    static void configOnError(int alert){}
 
-void on_account_state_changed_wrapper (const std::string& accountID, const int32_t& state) {
-    registeredConfigurationCallbackObject->on_account_state_changed(accountID, state);
-}
-
-void on_account_state_changed_with_code_wrapper (const std::string& accountID, const std::string& state, const int32_t& code) {
-    registeredConfigurationCallbackObject->on_account_state_changed_with_code(accountID, state, code);
-}
-
-std::vector<int32_t> get_hardware_audio_format_wrapper(void) {
-    return registeredConfigurationCallbackObject->get_hardware_audio_format();
-}
-
-static struct sflph_config_ev_handlers wrapper_configurationcallback_struct = {
-    &on_volume_change_wrapper,
-    &on_accounts_changed_wrapper,
-    &on_history_change_wrapper,
-    &on_stun_status_fail_wrapper,
-    &on_account_state_changed_wrapper,
-    &on_account_state_changed_with_code_wrapper,
-    &on_error_wrapper,
-    &get_hardware_audio_format_wrapper
 };
-
 %}
 
 %feature("director") ConfigurationCallback;
@@ -161,3 +112,18 @@ double sflph_config_get_volume(const std::string& device);
 bool sflph_config_check_for_private_key(const std::string& pem_path);
 bool sflph_config_check_certificate_validity(const std::string& ca_path, const std::string& pem_path);
 bool sflph_config_check_hostname_certificate(const std::string& host, const std::string& port);
+
+
+class ConfigurationCallback {
+public:
+    virtual ~ConfigurationCallback();
+    static void configOnVolumeChange(const std::string& device, int value);
+    static void configOnAccountsChange(void);
+    static void configOnHistoryChange(void);
+    static void configOnStunStatusFail(const std::string& account_id);
+    static void configOnRegistrationStateChange(const std::string& account_id, int state);
+    static void configOnSipRegistrationStateChange(const std::string& account_id, const std::string& state, int code);
+    static void configOnError(int alert);
+
+};
+
diff --git a/sflphone-android/jni/jni_interface.i b/sflphone-android/jni/jni_interface.i
index 88a278506..2c3a54063 100644
--- a/sflphone-android/jni/jni_interface.i
+++ b/sflphone-android/jni/jni_interface.i
@@ -71,22 +71,76 @@ namespace std {
 
 %}
 
-%inline %{
-/* some functions that need to be declared in *_wrap.cpp
- * that are not declared elsewhere in the c++ code
- */
-%}
 
 /* parsed by SWIG to generate all the glue */
 /* %include "../managerimpl.h" */
 /* %include <client/callmanager.h> */
 
-//%constant struct sflph_call_ev_handlers* WRAPPER_CALLBACK_STRUCT = &wrapper_callback_struct;
+//%constant struct sflph_call_ev_handlers* WRAPPER_CALLMANAGERCALLBACK_STRUCT = &wrapper_callback_struct;
+//%constant struct sflph_config_ev_handlers* WRAPPER_CONFIGCALLBACK_STRUCT = &wrapper_configurationcallback_struct;
 
 %include "managerimpl.i"
 %include "callmanager.i"
 %include "configurationmanager.i"
 
+%inline %{
+/* some functions that need to be declared in *_wrap.cpp
+ * that are not declared elsewhere in the c++ code
+ */
+void init(ConfigurationCallback* conf_cb, CallManagerCallback* call_cb) {
+
+    // Call event handlers
+    sflph_call_ev_handlers callEvHandlers = {
+        CallManagerCallback::callOnStateChange,
+        CallManagerCallback::callOnTransferFail,
+        CallManagerCallback::callOnTransferSuccess,
+        CallManagerCallback::callOnRecordPlaybackStopped,
+        CallManagerCallback::callOnVoiceMailNotify,
+        CallManagerCallback::callOnIncomingMessage,
+        CallManagerCallback::callOnIncomingCall,
+        CallManagerCallback::callOnRecordPlaybackFilepath,
+        CallManagerCallback::callOnConferenceCreated,
+        CallManagerCallback::callOnConferenceChanged,
+        CallManagerCallback::callOnUpdatePlaybackScale,
+        CallManagerCallback::callOnConferenceRemove,
+        CallManagerCallback::callOnNewCall,
+        CallManagerCallback::callOnSipCallStateChange,
+        CallManagerCallback::callOnRecordStateChange,
+        CallManagerCallback::callOnSecureSdesOn,
+        CallManagerCallback::callOnSecureSdesOff,
+        CallManagerCallback::callOnSecureZrtpOn,
+        CallManagerCallback::callOnSecureZrtpOff,
+        CallManagerCallback::callOnShowSas,
+        CallManagerCallback::callOnZrtpNotSuppOther,
+        CallManagerCallback::callOnZrtpNegotiationFail,
+        CallManagerCallback::callOnRtcpReceiveReport,
+    };
+
+    // Configuration event handlers
+    sflph_config_ev_handlers configEvHandlers = {
+        ConfigurationCallback::configOnVolumeChange,
+        ConfigurationCallback::configOnAccountsChange,
+        ConfigurationCallback::configOnHistoryChange,
+        ConfigurationCallback::configOnStunStatusFail,
+        ConfigurationCallback::configOnRegistrationStateChange,
+        ConfigurationCallback::configOnSipRegistrationStateChange,
+        ConfigurationCallback::configOnError,
+    };
+
+
+
+    // All event handlers
+    sflph_ev_handlers evHandlers;
+    memset(std::addressof(evHandlers), 0, sizeof(evHandlers));
+
+    evHandlers.call_ev_handlers = callEvHandlers;
+    evHandlers.config_ev_handlers = configEvHandlers;
+    sflph_init(&evHandlers, 0);
+
+
+}
+
+%}
 #ifndef SWIG
 /* some bad declarations */
 #endif
diff --git a/sflphone-android/jni/managerimpl.i b/sflphone-android/jni/managerimpl.i
index 78a3d0adb..c2bc56499 100644
--- a/sflphone-android/jni/managerimpl.i
+++ b/sflphone-android/jni/managerimpl.i
@@ -32,27 +32,24 @@
 %header %{
 
 #include "sflphone.h"
-class ManagerImpl {
-public:
-    /**
-     * Initializes libsflphone.
-     *
-     * @param ev_handlers Event handlers
-     * @param flags       Flags to customize this initialization
-     * @returns           0 if successful or a negative error code
-     */
-    int sflph_init(struct sflph_ev_handlers* ev_handlers, enum sflph_init_flag flags);
+/**
+ * Initializes libsflphone.
+ *
+ * @param ev_handlers Event handlers
+ * @param flags       Flags to customize this initialization
+ * @returns           0 if successful or a negative error code
+ */
+int sflph_init(struct sflph_ev_handlers* ev_handlers, enum sflph_init_flag flags);
 
-    /**
-     * Finalizes libsflphone, freeing any resource allocated by the library.
-     */
-    void sflph_fini(void);
+/**
+ * Finalizes libsflphone, freeing any resource allocated by the library.
+ */
+void sflph_fini(void);
 
-    /**
-     * Poll for SIP/IAX events
-     */
-    void sflph_poll_events(void);
-};
+/**
+ * Poll for SIP/IAX events
+ */
+void sflph_poll_events(void);
 
 %}
 
-- 
GitLab