From: Wootak Jung Date: Mon, 14 Sep 2020 23:58:17 +0000 (+0900) Subject: [Bluetooth][Non-ACR] Define Interop callback to global variable (#2005) X-Git-Tag: accepted/tizen/unified/20210219.040944~416 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4052046ec5adafd22c1f28287212bbfa5b701ebd;hp=114d09295e8deedbfd31ff825164f0e8a6defe9a;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Bluetooth][Non-ACR] Define Interop callback to global variable (#2005) Signed-off-by: Wootak Jung --- diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs index c5aaee3..e577543 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapterImpl.cs @@ -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 GetBondedDevices() { List deviceList = new List(); - 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); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs index d9c494c..334b4fa 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAudioImpl.cs @@ -21,9 +21,11 @@ namespace Tizen.Network.Bluetooth internal class BluetoothAudioImpl : IDisposable { private event EventHandler _audioConnectionChanged; - private event EventHandler _agScoStateChanged; private Interop.Bluetooth.AudioConnectionStateChangedCallback _audioConnectionChangedCallback; + private event EventHandler _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)); }; diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs index d697473..2a7bb0c 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothDevice.cs @@ -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 profileList = new List(); - 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); diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs index 4dd7897..4e8f288 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothGattImpl.cs @@ -29,7 +29,8 @@ namespace Tizen.Network.Bluetooth internal event EventHandler _notificationSent; int _requestId = 0; Dictionary> _sendIndicationTaskSource = new Dictionary>(); - 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 GetServices(BluetoothGattServer server) { List attribututeList = new List(); - 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> _readValueTaskSource = new Dictionary>(); - Interop.Bluetooth.BtGattClientRequestCompletedCallback _readValueCallback; + private Interop.Bluetooth.BtGattClientRequestCompletedCallback _readValueCallback; Dictionary> _writeValueTaskSource = new Dictionary>(); - 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 GetServices(BluetoothGattClient client) { List attribututeList = new List(); - 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 GetCharacteristics(BluetoothGattService service) { List attribututeList = new List(); - 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 GetIncludeServices(BluetoothGattService parentService) { List attribututeList = new List(); - 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 GetDescriptors(BluetoothGattCharacteristic characteristic) { List attribututeList = new List(); - 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; diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs index 7c05471..fedb1e6 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothHidDeviceImpl.cs @@ -22,7 +22,10 @@ namespace Tizen.Network.Bluetooth internal class BluetoothHidDeviceImpl { private event EventHandler _hidDeviceConnectionStateChanged; + private Interop.Bluetooth.HidDeviceConnectionStateChangedCallback _hidDeviceConnectionStateChangedCallback; + private event EventHandler _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)); }; diff --git a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs index 8647160..be30946 100644 --- a/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs +++ b/src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothOppImpl.cs @@ -23,14 +23,17 @@ namespace Tizen.Network.Bluetooth private static readonly BluetoothOppServerImpl _instance = new BluetoothOppServerImpl(); internal event EventHandler ConnectionRequested; + private Interop.Bluetooth.ConnectionRequestedCallback _ConnectionRequestedCallback; internal event EventHandler TransferProgress; + private Interop.Bluetooth.TransferProgressCallback _TransferProgressCallback; internal event EventHandler 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 PushResponded; + private Interop.Bluetooth.PushRespondedCallback _PushRespondedCallback; internal event EventHandler PushProgress; + private Interop.Bluetooth.PushProgressCallback _PushProgressCallback; internal event EventHandler 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)); };