private static event EventHandler<GattConnectionStateChangedEventArgs> s_connectionStateChanged;
private static Interop.Bluetooth.GattConnectionStateChangedCallBack s_connectionStateChangeCallback;
- internal BluetoothGattClient(string remoteAddress, bool fromLe)
+ internal BluetoothGattClient(string remoteAddress)
{
_impl = new BluetoothGattClientImpl(remoteAddress);
_remoteAddress = remoteAddress;
- if (fromLe == false)
- {
- StaticConnectionStateChanged += OnConnectionStateChanged;
- }
- else
- {
- // fromLe will be removed after BluetoothLeDevice.GattConnect removed for backward compatibility.
- // BluetoothLeDevice.GattConnectionStateChanged event will be occured in this case.
- }
+ StaticConnectionStateChanged += OnConnectionStateChanged;
}
/// <summary>
/// <since_tizen> 6 </since_tizen>
public static BluetoothGattClient CreateClient(string remoteAddress)
{
- BluetoothGattClient client = new BluetoothGattClient(remoteAddress, false);
- return client.Isvalid() ? client : null;
- }
-
- internal static BluetoothGattClient CreateClient(string remoteAddress, bool fromLe)
- {
- BluetoothGattClient client = new BluetoothGattClient(remoteAddress, fromLe);
+ BluetoothGattClient client = new BluetoothGattClient(remoteAddress);
return client.Isvalid() ? client : null;
}
}
}
- private static event EventHandler<GattConnectionStateChangedEventArgs> StaticConnectionStateChanged
+ internal static event EventHandler<GattConnectionStateChangedEventArgs> StaticConnectionStateChanged
{
add
{
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API level 6. Please use ConnectionStateChanged event on BluetoothGattClient.")]
- public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged
- {
- add
- {
- BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged += value;
- }
- remove
- {
- BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged -= value;
- }
- }
+ public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged;
internal BluetoothLeDevice(BluetoothLeScanData scanData)
{
_scanDataValue = new byte[_scanData.ScanDataLength];
scanData.ScanData.CopyTo(_scanDataValue, 0);
}
+
+ BluetoothGattClient.StaticConnectionStateChanged += (s, e) =>
+ {
+ GattConnectionStateChanged?.Invoke(this, e);
+ };
}
/// <summary>
}
else
{
- client = BluetoothGattClient.CreateClient(_remoteAddress, true);
+ client = BluetoothGattClient.CreateClient(_remoteAddress);
}
}
else
private event EventHandler<AdvertisingStateChangedEventArgs> _advertisingStateChanged = null;
private Interop.Bluetooth.AdvertisingStateChangedCallBack _advertisingStateChangedCallback;
- private event EventHandler<GattConnectionStateChangedEventArgs> _gattConnectionStateChanged = null;
- private Interop.Bluetooth.GattConnectionStateChangedCallBack _gattConnectionStateChangedCallback;
-
private int _serviceListCount = 0;
private bool _scanStarted;
{
// Free managed objects.
}
- //Free unmanaged objects
- if (_gattConnectionStateChanged != null)
- {
- UnRegisterGattConnectionStateChangedEvent();
- }
//stop scan operation in progress
StopScan ();
}
}
- internal event EventHandler<GattConnectionStateChangedEventArgs> LeGattConnectionStateChanged
- {
- add
- {
- if (_gattConnectionStateChanged == null)
- {
- RegisterGattConnectionStateChangedEvent();
- }
- _gattConnectionStateChanged += value;
- }
- remove
- {
- _gattConnectionStateChanged -= value;
- if (_gattConnectionStateChanged == null)
- {
- UnRegisterGattConnectionStateChangedEvent();
- }
- }
- }
-
- internal void RegisterGattConnectionStateChangedEvent()
- {
- _gattConnectionStateChangedCallback = (int result, bool connected,
- string remoteDeviceAddress, IntPtr userData) =>
- {
- Log.Info(Globals.LogTag, "Setting gatt connection state changed callback");
- GattConnectionStateChangedEventArgs e = new GattConnectionStateChangedEventArgs(result,
- connected, remoteDeviceAddress);
- _gattConnectionStateChanged?.Invoke(null, e);
- };
-
- int ret = Interop.Bluetooth.SetGattConnectionStateChangedCallback(
- _gattConnectionStateChangedCallback, IntPtr.Zero);
- if (ret != (int)BluetoothError.None)
- {
- Log.Error(Globals.LogTag, "Failed to set gatt connection state changed callback, Error - " + (BluetoothError)ret);
- }
- }
-
- internal void UnRegisterGattConnectionStateChangedEvent()
- {
- int ret = Interop.Bluetooth.UnsetGattConnectionStateChangedCallback();
- if (ret != (int)BluetoothError.None)
- {
- Log.Error(Globals.LogTag, "Failed to unset gatt connection state changed callback, Error - " + (BluetoothError)ret);
- }
- }
-
internal int StartScan()
{
_adapterLeScanResultChangedCallback = (int result, ref BluetoothLeScanDataStruct scanData, IntPtr userData) =>