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 void Enable()
+ {
+ if (Globals.IsInitialize)
+ {
+ int ret = Interop.Bluetooth.EnableAdapter();
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to enable adapter, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ }
+ else
+ {
+ BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+ }
+ }
+
+ internal void Disable()
+ {
+ if (IsBluetoothEnabled)
+ {
+ int ret = Interop.Bluetooth.DisableAdapter();
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to disable adapter, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ }
+ else
+ {
+ BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+ }
+ }
+
+ internal void SetVisibility(VisibilityMode mode, int timeout)
+ {
+ if (IsBluetoothEnabled)
+ {
+ int ret = Interop.Bluetooth.SetVisibility(mode, timeout);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to set visibility, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ }
+ else
+ {
+ BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+ }
+ }
+
internal void StartDiscovery()
{
int ret = Interop.Bluetooth.StartDiscovery();
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);
}
BluetoothDeviceStruct device = (BluetoothDeviceStruct)Marshal.PtrToStructure(deviceInfo, typeof(BluetoothDeviceStruct));
+ Interop.Bluetooth.FreeDeviceInfo(deviceInfo);
return BluetoothUtils.ConvertStructToDeviceClass(device);
}