OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
| 7 |
| 8 #if defined(OS_IOS) |
| 9 #import <CoreBluetooth/CoreBluetooth.h> |
| 10 #else |
| 11 #import <IOBluetooth/IOBluetooth.h> |
| 12 #endif |
| 13 |
| 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "device/bluetooth/bluetooth_device.h" |
| 16 |
| 17 @class BluetoothLowEnergyDiscoveryManagerMacBridge; |
| 18 |
| 19 namespace device { |
| 20 |
| 21 class BluetoothLowEnergyDeviceMac; |
| 22 class BluetoothLowEnergyDiscoveryManagerMacDelegate; |
| 23 |
| 24 // This class will scan for Bluetooth LE device on Mac. |
| 25 class BluetoothLowEnergyDiscoveryManagerMac { |
| 26 public: |
| 27 // Interface for being notified of events during a device discovery session. |
| 28 class Observer { |
| 29 public: |
| 30 // Called when |this| manager has found a device. |
| 31 virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0; |
| 32 |
| 33 // Called when |this| manager has updated on a device. |
| 34 virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0; |
| 35 }; |
| 36 |
| 37 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); |
| 38 |
| 39 // Returns true, if discovery is currently being performed. |
| 40 virtual bool IsDiscovering() const; |
| 41 |
| 42 // Initiates a discovery session. |
| 43 // BluetoothLowEnergyDeviceMac objects discovered within a previous |
| 44 // discovery session will be invalid. |
| 45 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids); |
| 46 |
| 47 // Stops a discovery session. |
| 48 virtual void StopDiscovery(); |
| 49 |
| 50 // Returns a new BluetoothLowEnergyDiscoveryManagerMac. |
| 51 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer); |
| 52 |
| 53 protected: |
| 54 // Called when a discovery or an update of a BLE device occurred. |
| 55 virtual void DiscoveredPeripheral(CBPeripheral* peripheral, |
| 56 NSDictionary* advertisementData, |
| 57 int rssi); |
| 58 |
| 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(); |
| 65 |
| 66 private: |
| 67 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); |
| 68 void ClearDevices(); |
| 69 |
| 70 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; |
| 71 |
| 72 // Observer interested in notifications from us. |
| 73 Observer* observer_; |
| 74 |
| 75 // Underlaying CoreBluetooth central manager. |
| 76 base::scoped_nsobject<CBCentralManager> manager_; |
| 77 |
| 78 // Discovery has been initiated by calling the API StartDiscovery(). |
| 79 bool discovering_; |
| 80 |
| 81 // A discovery has been initiated but has not started yet because it's |
| 82 // waiting for Bluetooth to turn on. |
| 83 bool pending_; |
| 84 |
| 85 // Delegate of the central manager. |
| 86 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; |
| 87 |
| 88 // Map of the device identifiers to the discovered device. |
| 89 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; |
| 90 |
| 91 // List of service UUIDs to scan. |
| 92 BluetoothDevice::UUIDList services_uuids_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); |
| 95 }; |
| 96 |
| 97 } // namespace device |
| 98 |
| 99 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
OLD | NEW |