From 31d27c686a4479346e4a37e55d9bb25a9441b52c Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Thu, 4 Oct 2012 16:05:08 -0400
Subject: [PATCH] #16331: Implement JAVA thread handler returning requested
 values from JNI

---
 .../sflphone/client/SFLPhoneHome.java         |  2 +
 .../sflphone/service/ISipService.aidl         |  1 +
 .../sflphone/service/SipService.java          | 44 +++++++++++++++++--
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
index b4f99a4e2..ac7463fef 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
@@ -448,6 +448,8 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
                 break;
             case R.id.buttonInit:
                 Log.i(TAG, "R.id.buttonInit");
+                String audioPlugin = service.getCurrentAudioOutputPlugin();
+                Log.i(TAG, "Current Audio Plugin: " + audioPlugin);               
                 break;
             case R.id.buttonService:
                 if (!serviceIsOn) {
diff --git a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
index 8f0eec1f1..a2e836ddc 100644
--- a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
+++ b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
@@ -9,4 +9,5 @@ interface ISipService {
     Map getAccountDetails(in String accountID);
     void setAccountDetails(in String accountId, in Map accountDetails);
     void setAudioPlugin(in String callID);
+    String getCurrentAudioOutputPlugin();
 }
diff --git a/src/com/savoirfairelinux/sflphone/service/SipService.java b/src/com/savoirfairelinux/sflphone/service/SipService.java
index 2b2de8abd..f45688613 100644
--- a/src/com/savoirfairelinux/sflphone/service/SipService.java
+++ b/src/com/savoirfairelinux/sflphone/service/SipService.java
@@ -114,7 +114,23 @@ public class SipService extends Service {
                    Log.i(TAG, "SipService.setAudioPlugin() thread running...");
                    configurationManagerJNI.setAudioPlugin(audioPlugin);
                }
-           });
+            });
+        }
+
+        @Override
+        public String getCurrentAudioOutputPlugin() {
+            class CurrentAudioPlugin extends SipRunnableWithReturn {
+                @Override
+                protected String doRun() throws SameThreadException {
+                    Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running...");
+                    return configurationManagerJNI.getCurrentAudioOutputPlugin();
+                }
+            };
+
+            CurrentAudioPlugin runInstance = new CurrentAudioPlugin();
+            getExecutor().execute(runInstance);
+            while(!runInstance.isDone()) {}
+            return (String) runInstance.getVal(); 
         }
 
         @Override
@@ -132,8 +148,6 @@ public class SipService extends Service {
         public HashMap<String,String> getAccountDetails(final String accountID) {
             StringMap swigmap = configurationManagerJNI.getAccountDetails(accountID);
 
-            Log.i(TAG, "===================== Swig Map Size " + swigmap.size());
-
             HashMap<String, String> nativemap = new HashMap<String, String>();
 
             nativemap.put(ServiceConstants.CONFIG_ACCOUNT_ALIAS, swigmap.get(ServiceConstants.CONFIG_ACCOUNT_ALIAS));
@@ -444,6 +458,30 @@ public class SipService extends Service {
         }
     }
 
+    public abstract static class SipRunnableWithReturn implements Runnable {
+        Object obj = null;
+        boolean done = false;
+
+        protected abstract Object doRun() throws SameThreadException;
+
+        public Object getVal() {
+            return obj;
+        }
+
+        public boolean isDone() {
+            return done;
+        }
+
+        public void run() {
+            try {
+                obj = doRun();
+                done = true; 
+            }catch(SameThreadException e) {
+                Log.e(TAG, "Not done from same thread");
+            }
+        }
+    }
+
     class StartRunnable extends SipRunnable {
         @Override
         protected void doRun() throws SameThreadException {
-- 
GitLab