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

Correct bookkeeping of connected devices #43

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 @@ -20,6 +20,7 @@ public class Adapter : Java.Lang.Object, BluetoothAdapter.ILeScanCallback, IAdap
protected BluetoothManager _manager;
protected BluetoothAdapter _adapter;
protected GattCallback _gattCallback;
protected IDictionary<Guid, IDevice> _guidToDevice = new Dictionary<Guid, IDevice>();

public bool IsScanning {
get { return this._isScanning; }
Expand All @@ -33,10 +34,11 @@ public IList<IDevice> DiscoveredDevices {

public IList<IDevice> ConnectedDevices {
get {
return this._connectedDevices;
var devices = new List<IDevice> (_guidToDevice.Count);
devices.AddRange (this._guidToDevice.Values);
return devices;
}
} protected IList<IDevice> _connectedDevices = new List<IDevice>();

}

public Adapter ()
{
Expand All @@ -48,14 +50,12 @@ public Adapter ()
this._gattCallback = new GattCallback (this);

this._gattCallback.DeviceConnected += (object sender, DeviceConnectionEventArgs e) => {
this._connectedDevices.Add ( e.Device);
this._guidToDevice.Add (e.Device.ID, e.Device);
this.DeviceConnected (this, e);
};

this._gattCallback.DeviceDisconnected += (object sender, DeviceConnectionEventArgs e) => {
// TODO: remove the disconnected device from the _connectedDevices list
// i don't think this will actually work, because i'm created a new underlying device here.
//if(this._connectedDevices.Contains(
this._guidToDevice.Remove (e.Device.ID);
this.DeviceDisconnected (this, e);
};
}
Expand Down