[Bluetooth][Non-ACR] Define Interop callback to global variable (#2005)
authorWootak Jung <wootak.jung@samsung.com>
Mon, 14 Sep 2020 23:58:17 +0000 (08:58 +0900)
committerGitHub <noreply@github.com>
Mon, 14 Sep 2020 23:58:17 +0000 (08:58 +0900)
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs

index c5aaee3..e577543 100644 (file)
@@ -43,6 +43,7 @@ namespace Tizen.Network.Bluetooth
         private Interop.Bluetooth.VisibilityModeChangedCallback _visibilityChangedCallback;
         private Interop.Bluetooth.VisibilityDurationChangedCallback _visibilitydurationChangedCallback;
         private Interop.Bluetooth.DiscoveryStateChangedCallback _discoveryStateChangedCallback;
+        private Interop.Bluetooth.BondedDeviceCallback _bondedDeviceCallback;
 
         private static readonly BluetoothAdapterImpl _instance = new BluetoothAdapterImpl();
         private bool disposed = false;
@@ -470,7 +471,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothDevice> GetBondedDevices()
         {
             List<BluetoothDevice> deviceList = new List<BluetoothDevice>();
-            Interop.Bluetooth.BondedDeviceCallback callback = (ref BluetoothDeviceStruct deviceInfo, IntPtr userData) =>
+            _bondedDeviceCallback = (ref BluetoothDeviceStruct deviceInfo, IntPtr userData) =>
             {
                 Log.Info(Globals.LogTag, "Bonded devices cb is called");
                 if(!deviceInfo.Equals(null))
@@ -479,7 +480,7 @@ namespace Tizen.Network.Bluetooth
                 }
                 return true;
             };
-            int ret = Interop.Bluetooth.GetBondedDevices(callback, IntPtr.Zero);
+            int ret = Interop.Bluetooth.GetBondedDevices(_bondedDeviceCallback, IntPtr.Zero);
             if(ret != (int)BluetoothError.None)
             {
                 Log.Error(Globals.LogTag, "Failed to get bonded devices, Error - " + (BluetoothError)ret);
index d9c494c..334b4fa 100644 (file)
@@ -21,9 +21,11 @@ namespace Tizen.Network.Bluetooth
     internal class BluetoothAudioImpl : IDisposable
     {
         private event EventHandler<AudioConnectionStateChangedEventArgs> _audioConnectionChanged;
-        private event EventHandler<AgScoStateChangedEventArgs> _agScoStateChanged;
         private Interop.Bluetooth.AudioConnectionStateChangedCallback _audioConnectionChangedCallback;
 
+        private event EventHandler<AgScoStateChangedEventArgs> _agScoStateChanged;
+        private Interop.Bluetooth.AgScoStateChangedCallback _agScoStateChangedCallback;
+
         private static readonly BluetoothAudioImpl _instance = new BluetoothAudioImpl();
         private bool disposed = false;
 
@@ -159,7 +161,7 @@ namespace Tizen.Network.Bluetooth
 
         private void RegisterAgScoStateChangedEvent()
         {
-            Interop.Bluetooth.AgScoStateChangedCallback _agScoStateChangedCallback = (int result, bool opened, IntPtr userData) =>
+            _agScoStateChangedCallback = (int result, bool opened, IntPtr userData) =>
             {
                 _agScoStateChanged?.Invoke(null, new AgScoStateChangedEventArgs(opened));
             };
index d697473..2a7bb0c 100644 (file)
@@ -42,6 +42,7 @@ namespace Tizen.Network.Bluetooth
         private Interop.Bluetooth.AuthorizationChangedCallback _authorizationChangedCallback;
         private Interop.Bluetooth.ServiceSearchedCallback _serviceSearchedCallback;
         private Interop.Bluetooth.DeviceConnectionStateChangedCallback _connectionChangedCallback;
+        private Interop.Bluetooth.ConnectedProfileCallback _connectedProfileCallback;
 
         internal string RemoteDeviceAddress;
         internal string RemoteDeviceName;
@@ -619,7 +620,7 @@ namespace Tizen.Network.Bluetooth
             if (BluetoothAdapter.IsBluetoothEnabled)
             {
                 List<BluetoothProfileType> profileList = new List<BluetoothProfileType>();
-                Interop.Bluetooth.ConnectedProfileCallback callback = (int profile, IntPtr userData) =>
+                _connectedProfileCallback = (int profile, IntPtr userData) =>
                 {
                     if (!profile.Equals(null))
                     {
@@ -627,7 +628,7 @@ namespace Tizen.Network.Bluetooth
                     }
                     return true;
                 };
-                int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, callback, IntPtr.Zero);
+                int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, _connectedProfileCallback, IntPtr.Zero);
                 if (ret != (int)BluetoothError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get connected profiles, Error - " + (BluetoothError)ret);
index 4dd7897..4e8f288 100644 (file)
@@ -29,7 +29,8 @@ namespace Tizen.Network.Bluetooth
         internal event EventHandler<NotificationSentEventArg> _notificationSent;
         int _requestId = 0;
         Dictionary<int, TaskCompletionSource<bool>> _sendIndicationTaskSource = new Dictionary<int, TaskCompletionSource<bool>>();
-        Interop.Bluetooth.BtGattServerNotificationSentCallback _sendIndicationCallback;
+        private Interop.Bluetooth.BtGattServerNotificationSentCallback _sendIndicationCallback;
+        private Interop.Bluetooth.BtGattForeachCallback _serviceForeachCallback;
 
         internal BluetoothGattServerImpl()
         {
@@ -88,7 +89,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothGattService> GetServices(BluetoothGattServer server)
         {
             List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
-            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            _serviceForeachCallback = (total, index, attributeHandle, userData) =>
             {
                 BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
                 BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, ""); ;
@@ -100,7 +101,7 @@ namespace Tizen.Network.Bluetooth
                 return true;
             };
 
-            int err = Interop.Bluetooth.BtGattServerForeachServices(_handle, cb, IntPtr.Zero);
+            int err = Interop.Bluetooth.BtGattServerForeachServices(_handle, _serviceForeachCallback, IntPtr.Zero);
             GattUtil.Error(err, "Failed to get all services");
 
             return attribututeList;
@@ -163,9 +164,10 @@ namespace Tizen.Network.Bluetooth
         private BluetoothGattClientHandle _handle;
         int _requestId = 0;
         Dictionary<int, TaskCompletionSource<bool>> _readValueTaskSource = new Dictionary<int, TaskCompletionSource<bool>>();
-        Interop.Bluetooth.BtGattClientRequestCompletedCallback _readValueCallback;
+        private Interop.Bluetooth.BtGattClientRequestCompletedCallback _readValueCallback;
         Dictionary<int, TaskCompletionSource<bool>> _writeValueTaskSource = new Dictionary<int, TaskCompletionSource<bool>>();
-        Interop.Bluetooth.BtGattClientRequestCompletedCallback _writeValueCallback;
+        private Interop.Bluetooth.BtGattClientRequestCompletedCallback _writeValueCallback;
+        private Interop.Bluetooth.BtGattForeachCallback _serviceForeachCallback;
 
         internal BluetoothGattClientImpl(string remoteAddress)
         {
@@ -222,7 +224,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothGattService> GetServices(BluetoothGattClient client)
         {
             List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
-            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            _serviceForeachCallback = (total, index, attributeHandle, userData) =>
             {
                 BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
                 BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
@@ -234,7 +236,7 @@ namespace Tizen.Network.Bluetooth
                 return true;
             };
 
-            int err = Interop.Bluetooth.BtGattClientForeachServices(_handle, cb, IntPtr.Zero);
+            int err = Interop.Bluetooth.BtGattClientForeachServices(_handle, _serviceForeachCallback, IntPtr.Zero);
             GattUtil.Error(err, "Failed to get all services");
 
             return attribututeList;
@@ -326,6 +328,9 @@ namespace Tizen.Network.Bluetooth
 
     internal class BluetoothGattServiceImpl : BluetoothGattAttributeImpl
     {
+        private Interop.Bluetooth.BtGattForeachCallback _characteristicForeachCallback;
+        private Interop.Bluetooth.BtGattForeachCallback _includedServiceForeachCallback;
+
         internal BluetoothGattServiceImpl(string uuid, BluetoothGattServiceType type)
         {
             int err = Interop.Bluetooth.BtGattServiceCreate(uuid, (int)type, out _handle);
@@ -373,7 +378,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service)
         {
             List<BluetoothGattCharacteristic> attribututeList = new List<BluetoothGattCharacteristic>();
-            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            _characteristicForeachCallback = (total, index, attributeHandle, userData) =>
             {
                 BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
                 BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(handle, "");
@@ -385,7 +390,7 @@ namespace Tizen.Network.Bluetooth
                 return true;
             };
 
-            int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), cb, IntPtr.Zero);
+            int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), _characteristicForeachCallback, IntPtr.Zero);
             GattUtil.Error(err, "Failed to get all Characteristic");
 
             return attribututeList;
@@ -415,7 +420,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothGattService> GetIncludeServices(BluetoothGattService parentService)
         {
             List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
-            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            _includedServiceForeachCallback = (total, index, attributeHandle, userData) =>
             {
                 BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
                 BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
@@ -427,7 +432,7 @@ namespace Tizen.Network.Bluetooth
                 return true;
             };
 
-            int err = Interop.Bluetooth.BtGattServiceForeachIncludedServices(parentService.GetHandle(), cb, IntPtr.Zero);
+            int err = Interop.Bluetooth.BtGattServiceForeachIncludedServices(parentService.GetHandle(), _includedServiceForeachCallback, IntPtr.Zero);
             GattUtil.Error(err, "Failed to get all services");
 
             return attribututeList;
@@ -436,6 +441,8 @@ namespace Tizen.Network.Bluetooth
 
     internal class BluetoothGattCharacteristicImpl : BluetoothGattAttributeImpl
     {
+        private Interop.Bluetooth.BtGattForeachCallback _descriptorForeachCallback;
+
         internal BluetoothGattCharacteristicImpl(string uuid, BluetoothGattPermission permission, BluetoothGattProperty property, byte[] value)
         {
             int err = Interop.Bluetooth.BtGattCharacteristicCreate(uuid, (int)permission, (int)property, value, value.Length, out _handle);
@@ -532,7 +539,7 @@ namespace Tizen.Network.Bluetooth
         internal IEnumerable<BluetoothGattDescriptor> GetDescriptors(BluetoothGattCharacteristic characteristic)
         {
             List<BluetoothGattDescriptor> attribututeList = new List<BluetoothGattDescriptor>();
-            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            _descriptorForeachCallback = (total, index, attributeHandle, userData) =>
             {
                 BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
                 BluetoothGattDescriptor descriptor = BluetoothGattDescriptorImpl.CreateBluetoothGattDescriptor(handle, "");
@@ -544,7 +551,7 @@ namespace Tizen.Network.Bluetooth
                 return true;
             };
 
-            int err = Interop.Bluetooth.BtGattCharacteristicForeachDescriptors(characteristic.GetHandle(), cb, IntPtr.Zero);
+            int err = Interop.Bluetooth.BtGattCharacteristicForeachDescriptors(characteristic.GetHandle(), _descriptorForeachCallback, IntPtr.Zero);
             GattUtil.Error(err, "Failed to get all descriptor");
 
             return attribututeList;
index 7c05471..fedb1e6 100644 (file)
@@ -22,7 +22,10 @@ namespace Tizen.Network.Bluetooth
     internal class BluetoothHidDeviceImpl
     {
         private event EventHandler<HidDeviceConnectionStateChangedEventArgs> _hidDeviceConnectionStateChanged;
+        private Interop.Bluetooth.HidDeviceConnectionStateChangedCallback _hidDeviceConnectionStateChangedCallback;
+
         private event EventHandler<HidDeviceDataReceivedEventArgs> _hidDeviceDataReceived;
+        private Interop.Bluetooth.HidDeviceDataReceivedCallback _hidDeviceDataReceivedCallback;
 
         private static readonly BluetoothHidDeviceImpl _instance = new BluetoothHidDeviceImpl();
 
@@ -90,7 +93,7 @@ namespace Tizen.Network.Bluetooth
 
         private void RegisterHidDataReceivedEvent()
         {
-            Interop.Bluetooth.HidDeviceDataReceivedCallback _hidDeviceDataReceivedCallback = (ref BluetoothHidDeviceReceivedDataStruct receivedData, IntPtr userData) =>
+            _hidDeviceDataReceivedCallback = (ref BluetoothHidDeviceReceivedDataStruct receivedData, IntPtr userData) =>
             {
                 _hidDeviceDataReceived?.Invoke(null, new HidDeviceDataReceivedEventArgs(BluetoothHidDeviceReceivedData.Create(receivedData)));
             };
@@ -145,7 +148,7 @@ namespace Tizen.Network.Bluetooth
         {
             if (Globals.IsInitialize)
             {
-                Interop.Bluetooth.HidDeviceConnectionStateChangedCallback _hidDeviceConnectionStateChangedCallback = (int result, bool isConnected, string address, IntPtr userData) =>
+                _hidDeviceConnectionStateChangedCallback = (int result, bool isConnected, string address, IntPtr userData) =>
                 {
                     _hidDeviceConnectionStateChanged?.Invoke(null, new HidDeviceConnectionStateChangedEventArgs(result, isConnected, address));
                 };
index 8647160..be30946 100644 (file)
@@ -23,14 +23,17 @@ namespace Tizen.Network.Bluetooth
         private static readonly BluetoothOppServerImpl _instance = new BluetoothOppServerImpl();
 
         internal event EventHandler<ConnectionRequestedEventArgs> ConnectionRequested;
+        private Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback;
 
         internal event EventHandler<TransferProgressEventArgs> TransferProgress;
+        private Interop.Bluetooth.TransferProgressCallback _TransferProgressCallback;
 
         internal event EventHandler<TransferFinishedEventArgs> TransferFinished;
+        private Interop.Bluetooth.TransferFinishedCallback _TransferFinishedCallback;
 
         internal int StartServer(string filePath)
         {
-            Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback = (string devAddress, IntPtr userData) =>
+            _ConnectionRequestedCallback = (string devAddress, IntPtr userData) =>
             {
                 ConnectionRequested?.Invoke(this, new ConnectionRequestedEventArgs(devAddress));
             };
@@ -66,12 +69,12 @@ namespace Tizen.Network.Bluetooth
             _transferId = -1;
             if (Globals.IsOppServerInitialized)
             {
-                Interop.Bluetooth.TransferProgressCallback _TransferProgressCallback = (string file, long size, int percent, IntPtr userData) =>
+                _TransferProgressCallback = (string file, long size, int percent, IntPtr userData) =>
                 {
                     TransferProgress?.Invoke(this, new TransferProgressEventArgs(file, size, percent));
                 };
 
-                Interop.Bluetooth.TransferFinishedCallback _TransferFinishedCallback = (int result, string file, long size, IntPtr userData) =>
+                _TransferFinishedCallback = (int result, string file, long size, IntPtr userData) =>
                 {
                     TransferFinished?.Invoke(this, new TransferFinishedEventArgs(result, file, size));
                 };
@@ -142,10 +145,13 @@ namespace Tizen.Network.Bluetooth
         private static readonly BluetoothOppClientImpl _instance = new BluetoothOppClientImpl();
 
         internal event EventHandler<PushRespondedEventArgs> PushResponded;
+        private Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback;
 
         internal event EventHandler<PushProgressEventArgs> PushProgress;
+        private Interop.Bluetooth.PushProgressCallback _PushProgressCallback;
 
         internal event EventHandler<PushFinishedEventArgs> PushFinished;
+        private Interop.Bluetooth.PushFinishedCallback _PushFinishedCallback;
 
         private BluetoothOppClientImpl()
         {
@@ -208,17 +214,17 @@ namespace Tizen.Network.Bluetooth
 
             if (Globals.IsOppClientInitialized)
             {
-                Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback = (int result, string address, IntPtr userData) =>
+                _PushRespondedCallback = (int result, string address, IntPtr userData) =>
                 {
                     PushResponded?.Invoke(this, new PushRespondedEventArgs(result, address));
                 };
 
-                Interop.Bluetooth.PushProgressCallback _PushProgressCallback = (string file, long size, int percent, IntPtr userData) =>
+                _PushProgressCallback = (string file, long size, int percent, IntPtr userData) =>
                 {
                     PushProgress?.Invoke(this, new PushProgressEventArgs(file, size, percent));
                 };
 
-                Interop.Bluetooth.PushFinishedCallback _PushFinishedCallback = (int result, string address, IntPtr userData) =>
+                _PushFinishedCallback = (int result, string address, IntPtr userData) =>
                 {
                     PushFinished?.Invoke(this, new PushFinishedEventArgs(result, address));
                 };