[Bluetooth][Non-ACR] Add the exception handling logic (#2021)
authorWootak Jung <wootak.jung@samsung.com>
Fri, 18 Sep 2020 05:39:17 +0000 (14:39 +0900)
committerGitHub <noreply@github.com>
Fri, 18 Sep 2020 05:39:17 +0000 (14:39 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpControlImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs

index 334b4fa..62acf9d 100644 (file)
@@ -26,7 +26,10 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<AgScoStateChangedEventArgs> _agScoStateChanged;
         private Interop.Bluetooth.AgScoStateChangedCallback _agScoStateChangedCallback;
 
-        private static readonly BluetoothAudioImpl _instance = new BluetoothAudioImpl();
+        private static readonly Lazy<BluetoothAudioImpl> _instance = new Lazy<BluetoothAudioImpl>(() =>
+        {
+            return new BluetoothAudioImpl();
+        });
         private bool disposed = false;
 
         internal event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
@@ -203,7 +206,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
index 3606378..da37d72 100644 (file)
@@ -30,7 +30,10 @@ namespace Tizen.Network.Bluetooth
         private Interop.Bluetooth.TrackInfoChangedCallback _trackInfoChangedCallback;
         private Interop.Bluetooth.AvrcpControlConnectionChangedCallback _connStateChangedCallback;
 
-        private static BluetoothAvrcpControlImpl _instance = new BluetoothAvrcpControlImpl();
+        private static readonly Lazy<BluetoothAvrcpControlImpl> _instance = new Lazy<BluetoothAvrcpControlImpl>(() =>
+        {
+            return new BluetoothAvrcpControlImpl();
+        });
         private bool disposed = false;
 
         internal event EventHandler<AvrcpControlConnectionChangedEventArgs> ConnectionChanged;
@@ -398,7 +401,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
@@ -417,6 +420,7 @@ namespace Tizen.Network.Bluetooth
             if (ret != (int)BluetoothError.None)
             {
                 Log.Error(Globals.LogTag, "Failed to initialize AVRCP Control, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
             }
         }
 
index 28abda8..72337cb 100644 (file)
@@ -32,7 +32,10 @@ namespace Tizen.Network.Bluetooth
         private Interop.Bluetooth.ShuffleModeChangedCallback _shuffleModeChangedCallback;
         private Interop.Bluetooth.ScanModeChangedCallback _scanModeChangedCallback;
 
-        private static BluetoothAvrcpImpl _instance = new BluetoothAvrcpImpl();
+        private static Lazy<BluetoothAvrcpImpl> _instance = new Lazy<BluetoothAvrcpImpl>(() =>
+        {
+            return new BluetoothAvrcpImpl();
+        });
         private bool disposed = false;
 
         internal event EventHandler<TargetConnectionStateChangedEventArgs> TargetConnectionStateChanged
@@ -359,7 +362,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
index 2a7bb0c..2500e55 100644 (file)
@@ -20,6 +20,7 @@ using System.Runtime.InteropServices;
 using System.Collections.Concurrent;
 using System.Collections.ObjectModel;
 using System.Collections.Specialized;
+using System.Reflection;
 
 namespace Tizen.Network.Bluetooth
 {
@@ -681,10 +682,17 @@ namespace Tizen.Network.Bluetooth
         /// <since_tizen> 3 </since_tizen>
         public T GetProfile<T>() where T : BluetoothProfile
         {
-            // TODO : Need to check capability of supporting profiles
-            var profile = (T)Activator.CreateInstance(typeof(T), true);
-            profile.RemoteAddress = RemoteDeviceAddress;
-            return profile;
+            try
+            {
+                // TODO : Need to check capability of supporting profiles
+                var profile = (T)Activator.CreateInstance(typeof(T), true);
+                profile.RemoteAddress = RemoteDeviceAddress;
+                return profile;
+            }
+            catch (TargetInvocationException err)
+            {
+                throw err.InnerException;
+            }
         }
 
         /// <summary>
index fedb1e6..a64e600 100644 (file)
@@ -27,7 +27,10 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<HidDeviceDataReceivedEventArgs> _hidDeviceDataReceived;
         private Interop.Bluetooth.HidDeviceDataReceivedCallback _hidDeviceDataReceivedCallback;
 
-        private static readonly BluetoothHidDeviceImpl _instance = new BluetoothHidDeviceImpl();
+        private static readonly Lazy<BluetoothHidDeviceImpl> _instance = new Lazy<BluetoothHidDeviceImpl>(() =>
+        {
+            return new BluetoothHidDeviceImpl();
+        });
 
         internal event EventHandler<HidDeviceConnectionStateChangedEventArgs> ConnectionStateChanged
         {
@@ -130,7 +133,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
index 6a1401e..f4361c6 100644 (file)
@@ -23,7 +23,10 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<HidConnectionStateChangedEventArgs> _hidConnectionChanged;
         private Interop.Bluetooth.HidConnectionStateChangedCallback _hidConnectionChangedCallback;
 
-        private static readonly BluetoothHidImpl _instance = new BluetoothHidImpl();
+        private static readonly Lazy<BluetoothHidImpl> _instance = new Lazy<BluetoothHidImpl>(() =>
+        {
+            return new BluetoothHidImpl();
+        });
         private bool disposed = false;
 
         internal event EventHandler<HidConnectionStateChangedEventArgs> HidConnectionStateChanged
@@ -68,7 +71,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
         private BluetoothHidImpl ()
index be30946..68782ce 100644 (file)
@@ -20,7 +20,10 @@ namespace Tizen.Network.Bluetooth
 {
     internal class BluetoothOppServerImpl
     {
-        private static readonly BluetoothOppServerImpl _instance = new BluetoothOppServerImpl();
+        private static readonly Lazy<BluetoothOppServerImpl> _instance = new Lazy<BluetoothOppServerImpl>(() =>
+        {
+            return new BluetoothOppServerImpl();
+        });
 
         internal event EventHandler<ConnectionRequestedEventArgs> ConnectionRequested;
         private Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback;
@@ -135,14 +138,17 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
     }
 
     internal class BluetoothOppClientImpl
     {
-        private static readonly BluetoothOppClientImpl _instance = new BluetoothOppClientImpl();
+        private static readonly Lazy<BluetoothOppClientImpl> _instance = new Lazy<BluetoothOppClientImpl>(() =>
+        {
+            return new BluetoothOppClientImpl();
+        });
 
         internal event EventHandler<PushRespondedEventArgs> PushResponded;
         private Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback;
@@ -283,7 +289,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
     }