Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Fix phantom delegate trying to use its referenced gatt instance #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt,

// when the services are discovered on the gatt callback, cache them here
if (this._gattCallback != null) {
this._gattCallback.ServicesDiscovered += (s, e) => {
var services = this._gatt.Services;
this._services = new List<IService> ();
foreach (var item in services) {
this._services.Add (new Service (item, this._gatt, this._gattCallback));
}
this.ServicesDiscovered (this, e);
};
this._gattCallback.ServicesDiscovered += this.OnServiceDiscovered;
}
}

public void OnServiceDiscovered(object sender, ServicesDiscoveredEventArgs args)
{
var services = this._gatt.Services;
this._services = new List<IService> ();
foreach (var item in services) {
this._services.Add (new Service (item, this._gatt, this._gattCallback));
}
this.ServicesDiscovered (this, args);
}

public override Guid ID {
get {
//TODO: verify - fix from Evolve player
Expand Down Expand Up @@ -104,7 +107,11 @@ public override void DiscoverServices ()
public void Disconnect ()
{
this._gatt.Disconnect ();
this._gatt.Dispose ();
if (this._gattCallback != null) {
this._gattCallback.ServicesDiscovered -= this.OnServiceDiscovered;
}
this._gatt.Close ();
this._gatt = null;
}

#endregion
Expand Down