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;
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))
}
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);
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;
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));
};
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;
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))
{
}
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);
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()
{
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, ""); ;
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;
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)
{
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, "");
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;
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);
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, "");
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;
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, "");
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;
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);
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, "");
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;
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();
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)));
};
{
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));
};
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));
};
_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));
};
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()
{
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));
};