From 1f94614b43e454e9e958b32fb9487b1b3ec874c9 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Mon, 21 Sep 2020 08:38:43 +0900 Subject: [PATCH] [Bluetooth][Nnon-ACR] Add the exception handling logic (#2028) Signed-off-by: Wootak Jung Co-authored-by: WonYoung Choi --- .../Tizen.Network.Bluetooth/BluetoothAudioImpl.cs | 7 +++++-- .../Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs | 7 +++++-- .../Tizen.Network.Bluetooth/BluetoothDevice.cs | 16 ++++++++++++---- .../Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs | 7 +++++-- .../Tizen.Network.Bluetooth/BluetoothHidImpl.cs | 7 +++++-- .../Tizen.Network.Bluetooth/BluetoothOppImpl.cs | 18 ++++++++++++------ 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs index c536f90..19a4f5b 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs @@ -24,7 +24,10 @@ namespace Tizen.Network.Bluetooth private event EventHandler _agScoStateChanged; private Interop.Bluetooth.AudioConnectionStateChangedCallback _audioConnectionChangedCallback; - private static readonly BluetoothAudioImpl _instance = new BluetoothAudioImpl(); + private static readonly Lazy _instance = new Lazy(() => + { + return new BluetoothAudioImpl(); + }); private bool disposed = false; internal event EventHandler AudioConnectionStateChanged @@ -204,7 +207,7 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs index 28abda8..72337cb 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAvrcpImpl.cs @@ -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 _instance = new Lazy(() => + { + return new BluetoothAvrcpImpl(); + }); private bool disposed = false; internal event EventHandler TargetConnectionStateChanged @@ -359,7 +362,7 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs index d697473..2558e14 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs @@ -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 /// 3 public T GetProfile() 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; + } } /// diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs index 7c05471..7c268fb 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs @@ -24,7 +24,10 @@ namespace Tizen.Network.Bluetooth private event EventHandler _hidDeviceConnectionStateChanged; private event EventHandler _hidDeviceDataReceived; - private static readonly BluetoothHidDeviceImpl _instance = new BluetoothHidDeviceImpl(); + private static readonly Lazy _instance = new Lazy(() => + { + return new BluetoothHidDeviceImpl(); + }); internal event EventHandler ConnectionStateChanged { @@ -127,7 +130,7 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidImpl.cs index 6a1401e..f4361c6 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidImpl.cs @@ -23,7 +23,10 @@ namespace Tizen.Network.Bluetooth private event EventHandler _hidConnectionChanged; private Interop.Bluetooth.HidConnectionStateChangedCallback _hidConnectionChangedCallback; - private static readonly BluetoothHidImpl _instance = new BluetoothHidImpl(); + private static readonly Lazy _instance = new Lazy(() => + { + return new BluetoothHidImpl(); + }); private bool disposed = false; internal event EventHandler HidConnectionStateChanged @@ -68,7 +71,7 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } private BluetoothHidImpl () diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs index f87b862..d2c31b6 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs @@ -20,6 +20,11 @@ namespace Tizen.Network.Bluetooth { internal class BluetoothOppServerImpl { + private static readonly Lazy _instance = new Lazy(() => + { + return new BluetoothOppServerImpl(); + }); + private event EventHandler _ConnectionRequested; private Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback; @@ -29,8 +34,6 @@ namespace Tizen.Network.Bluetooth private event EventHandler _TransferFinished; private Interop.Bluetooth.TransferFinishedCallback _TransferFinishedCallback; - private static readonly BluetoothOppServerImpl _instance = new BluetoothOppServerImpl(); - internal event EventHandler ConnectionRequested { add @@ -171,13 +174,18 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } } internal class BluetoothOppClientImpl { + private static readonly Lazy _instance = new Lazy(() => + { + return new BluetoothOppClientImpl(); + }); + private event EventHandler _PushResponded; private Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback; @@ -187,8 +195,6 @@ namespace Tizen.Network.Bluetooth private event EventHandler _PushFinished; private Interop.Bluetooth.PushFinishedCallback _PushFinishedCallback; - private static readonly BluetoothOppClientImpl _instance = new BluetoothOppClientImpl(); - internal event EventHandler PushResponded { add @@ -355,7 +361,7 @@ namespace Tizen.Network.Bluetooth { get { - return _instance; + return _instance.Value; } } } -- 2.7.4