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 protected: |
| 37 virtual ~Observer() {} |
| 38 }; |
| 39 |
| 40 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); |
| 41 |
| 42 // Returns true, if discovery is currently being performed. |
| 43 virtual bool IsDiscovering() const; |
| 44 |
| 45 // Initiates a discovery session. |
| 46 // BluetoothLowEnergyDeviceMac objects discovered within a previous |
| 47 // discovery session will be invalid. |
| 48 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids); |
| 49 |
| 50 // Stops a discovery session. |
| 51 virtual void StopDiscovery(); |
| 52 |
| 53 // Returns a new BluetoothLowEnergyDiscoveryManagerMac. |
| 54 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer); |
| 55 |
| 56 protected: |
| 57 // Called when a discovery or an update of a BLE device occurred. |
| 58 virtual void DiscoveredPeripheral(CBPeripheral* peripheral, |
| 59 NSDictionary* advertisementData, |
| 60 int rssi); |
| 61 |
| 62 // The device discovery can really be started when Bluetooth is powered on. |
| 63 // The method TryStartDiscovery() is called when it's a good time to try to |
| 64 // start the BLE device discovery. It will check if the discovery session has |
| 65 // been started and if the Bluetooth is powered and then really start the |
| 66 // CoreBluetooth BLE device discovery. |
| 67 virtual void TryStartDiscovery(); |
| 68 |
| 69 private: |
| 70 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); |
| 71 void ClearDevices(); |
| 72 |
| 73 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; |
| 74 |
| 75 // Observer interested in notifications from us. |
| 76 Observer* observer_; |
| 77 |
| 78 // Underlaying CoreBluetooth central manager. |
| 79 base::scoped_nsobject<CBCentralManager> manager_; |
| 80 |
| 81 // Discovery has been initiated by calling the API StartDiscovery(). |
| 82 bool discovering_; |
| 83 |
| 84 // A discovery has been initiated but has not started yet because it's |
| 85 // waiting for Bluetooth to turn on. |
| 86 bool pending_; |
| 87 |
| 88 // Delegate of the central manager. |
| 89 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; |
| 90 |
| 91 // Map of the device identifiers to the discovered device. |
| 92 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; |
| 93 |
| 94 // List of service UUIDs to scan. |
| 95 BluetoothDevice::UUIDList services_uuids_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); |
| 98 }; |
| 99 |
| 100 } // namespace device |
| 101 |
| 102 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
OLD | NEW |