/// </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>
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) =>
- {
- if (_gattConnectionStateChanged != null)
- {
- Log.Info(Globals.LogTag, "Setting gatt connection state changed callback" );
- GattConnectionStateChangedEventArgs e = new GattConnectionStateChangedEventArgs (result,
- connected, remoteDeviceAddress);
-
- _gattConnectionStateChanged(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) =>