1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
9 #import <CoreBluetooth/CoreBluetooth.h>
11 #import <IOBluetooth/IOBluetooth.h>
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/mac/sdk_forward_declarations.h"
16 #include "device/bluetooth/bluetooth_device.h"
20 // This class will scan for Bluetooth LE device on Mac.
21 class BluetoothLowEnergyDiscoveryManagerMac
{
23 // Interface for being notified of events during a device discovery session.
26 // Called when |this| manager has found a device or an update on a device.
27 virtual void LowEnergyDeviceUpdated(CBPeripheral
* peripheral
,
28 NSDictionary
* advertisementData
,
32 virtual ~Observer() {}
35 virtual ~BluetoothLowEnergyDiscoveryManagerMac();
37 // Returns true, if discovery is currently being performed.
38 virtual bool IsDiscovering() const;
40 // Initiates a discovery session.
41 // BluetoothLowEnergyDeviceMac objects discovered within a previous
42 // discovery session will be invalid.
43 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids
);
45 // Stops a discovery session.
46 virtual void StopDiscovery();
48 // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
49 static BluetoothLowEnergyDiscoveryManagerMac
* Create(Observer
* observer
);
51 virtual void SetCentralManager(CBCentralManager
* central_manager
);
54 // Called when a discovery or an update of a BLE device occurred.
55 virtual void DiscoveredPeripheral(CBPeripheral
* peripheral
,
56 NSDictionary
* advertisementData
,
59 // The device discovery can really be started when Bluetooth is powered on.
60 // The method TryStartDiscovery() is called when it's a good time to try to
61 // start the BLE device discovery. It will check if the discovery session has
62 // been started and if the Bluetooth is powered and then really start the
63 // CoreBluetooth BLE device discovery.
64 virtual void TryStartDiscovery();
67 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer
* observer
);
69 friend class BluetoothAdapterMacTest
;
70 friend class BluetoothLowEnergyCentralManagerBridge
;
72 // Observer interested in notifications from us.
75 // Underlying CoreBluetooth central manager, owned by |observer_|.
76 CBCentralManager
* central_manager_
= nil
;
78 // Discovery has been initiated by calling the API StartDiscovery().
81 // A discovery has been initiated but has not started yet because it's
82 // waiting for Bluetooth to turn on.
85 // List of service UUIDs to scan.
86 BluetoothDevice::UUIDList services_uuids_
;
88 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac
);
93 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_