[Bluetooth][Nnon-ACR] Add the exception handling logic (#2028)
authorWootak Jung <wootak.jung@samsung.com>
Sun, 20 Sep 2020 23:38:43 +0000 (08:38 +0900)
committerGitHub <noreply@github.com>
Sun, 20 Sep 2020 23:38:43 +0000 (08:38 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
Co-authored-by: WonYoung Choi <wy80.choi@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.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 c536f908926196db8e2b3b05fedee392caf6984e..19a4f5bcda74db2dd4fd6373440e41961360d48d 100644 (file)
@@ -24,7 +24,10 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<AgScoStateChangedEventArgs> _agScoStateChanged;
         private Interop.Bluetooth.AudioConnectionStateChangedCallback _audioConnectionChangedCallback;
 
-        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
@@ -204,7 +207,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
index 28abda86e895aaa83c0eec2eb296c5ed964c518a..72337cb063dd2433adfcb9eb7c7b9e797f1d0d8c 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 d6974734ccc2ea32aa7552411af0cf7ddcf8a062..2558e14c1a6cb771209c7ea494546e0cfd736e45 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
 {
@@ -680,10 +681,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 7c054712c5d2a3f6dcffc8d13b2a14129e1e2dbf..7c268fbb6bb70634d2bff62049b232d6b0553c7e 100644 (file)
@@ -24,7 +24,10 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<HidDeviceConnectionStateChangedEventArgs> _hidDeviceConnectionStateChanged;
         private event EventHandler<HidDeviceDataReceivedEventArgs> _hidDeviceDataReceived;
 
-        private static readonly BluetoothHidDeviceImpl _instance = new BluetoothHidDeviceImpl();
+        private static readonly Lazy<BluetoothHidDeviceImpl> _instance = new Lazy<BluetoothHidDeviceImpl>(() =>
+        {
+            return new BluetoothHidDeviceImpl();
+        });
 
         internal event EventHandler<HidDeviceConnectionStateChangedEventArgs> ConnectionStateChanged
         {
@@ -127,7 +130,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
 
index 6a1401e330edd921bdea0a83e2193ed4ee0216b8..f4361c6c4c4ff4d5f41ba4837415e05668f034ae 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 f87b86266f5f43233fd32a7c221348023b12d77d..d2c31b699d90f05bbced1b521928ec8c7a9122b8 100644 (file)
@@ -20,6 +20,11 @@ namespace Tizen.Network.Bluetooth
 {
     internal class BluetoothOppServerImpl
     {
+        private static readonly Lazy<BluetoothOppServerImpl> _instance = new Lazy<BluetoothOppServerImpl>(() =>
+        {
+            return new BluetoothOppServerImpl();
+        });
+
         private event EventHandler<ConnectionRequestedEventArgs> _ConnectionRequested;
         private Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback;
 
@@ -29,8 +34,6 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<TransferFinishedEventArgs> _TransferFinished;
         private Interop.Bluetooth.TransferFinishedCallback _TransferFinishedCallback;
 
-        private static readonly BluetoothOppServerImpl _instance = new BluetoothOppServerImpl();
-
         internal event EventHandler<ConnectionRequestedEventArgs> ConnectionRequested
         {
             add
@@ -171,13 +174,18 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
     }
 
     internal class BluetoothOppClientImpl
     {
+        private static readonly Lazy<BluetoothOppClientImpl> _instance = new Lazy<BluetoothOppClientImpl>(() =>
+        {
+            return new BluetoothOppClientImpl();
+        });
+
         private event EventHandler<PushRespondedEventArgs> _PushResponded;
         private Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback;
 
@@ -187,8 +195,6 @@ namespace Tizen.Network.Bluetooth
         private event EventHandler<PushFinishedEventArgs> _PushFinished;
         private Interop.Bluetooth.PushFinishedCallback _PushFinishedCallback;
 
-        private static readonly BluetoothOppClientImpl _instance = new BluetoothOppClientImpl();
-
         internal event EventHandler<PushRespondedEventArgs> PushResponded
         {
             add
@@ -355,7 +361,7 @@ namespace Tizen.Network.Bluetooth
         {
             get
             {
-                return _instance;
+                return _instance.Value;
             }
         }
     }