| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
| 7 | 7 |
| 8 #if defined(OS_IOS) | 8 #if defined(OS_IOS) |
| 9 #import <CoreBluetooth/CoreBluetooth.h> | 9 #import <CoreBluetooth/CoreBluetooth.h> |
| 10 #else | 10 #else |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class BluetoothLowEnergyDeviceMac; | 22 class BluetoothLowEnergyDeviceMac; |
| 23 class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 23 class BluetoothLowEnergyDiscoveryManagerMacDelegate; |
| 24 | 24 |
| 25 // This class will scan for Bluetooth LE device on Mac. | 25 // This class will scan for Bluetooth LE device on Mac. |
| 26 class BluetoothLowEnergyDiscoveryManagerMac { | 26 class BluetoothLowEnergyDiscoveryManagerMac { |
| 27 public: | 27 public: |
| 28 // Interface for being notified of events during a device discovery session. | 28 // Interface for being notified of events during a device discovery session. |
| 29 class Observer { | 29 class Observer { |
| 30 public: | 30 public: |
| 31 // Called when |this| manager has found a device. | 31 // Called when |this| manager has found a device or an update on a device. |
| 32 virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0; | 32 virtual void LowEnergyDeviceUpdated(CBPeripheral* peripheral, |
| 33 | 33 NSDictionary* advertisementData, |
| 34 // Called when |this| manager has updated on a device. | 34 int rssi) = 0; |
| 35 virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0; | |
| 36 | 35 |
| 37 protected: | 36 protected: |
| 38 virtual ~Observer() {} | 37 virtual ~Observer() {} |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); | 40 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); |
| 42 | 41 |
| 43 // Returns true, if discovery is currently being performed. | 42 // Returns true, if discovery is currently being performed. |
| 44 virtual bool IsDiscovering() const; | 43 virtual bool IsDiscovering() const; |
| 45 | 44 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 62 | 61 |
| 63 // The device discovery can really be started when Bluetooth is powered on. | 62 // The device discovery can really be started when Bluetooth is powered on. |
| 64 // The method TryStartDiscovery() is called when it's a good time to try to | 63 // The method TryStartDiscovery() is called when it's a good time to try to |
| 65 // start the BLE device discovery. It will check if the discovery session has | 64 // start the BLE device discovery. It will check if the discovery session has |
| 66 // been started and if the Bluetooth is powered and then really start the | 65 // been started and if the Bluetooth is powered and then really start the |
| 67 // CoreBluetooth BLE device discovery. | 66 // CoreBluetooth BLE device discovery. |
| 68 virtual void TryStartDiscovery(); | 67 virtual void TryStartDiscovery(); |
| 69 | 68 |
| 70 private: | 69 private: |
| 71 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); | 70 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); |
| 72 void ClearDevices(); | 71 |
| 72 // Private method for testing. Resets |manager_| to |manager| and set |
| 73 // |bridge_| as its delegate. |
| 74 virtual void SetManager(CBCentralManager* manager); |
| 73 | 75 |
| 74 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; | 76 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; |
| 77 friend class BluetoothAdapterMacTest; |
| 75 | 78 |
| 76 // Observer interested in notifications from us. | 79 // Observer interested in notifications from us. |
| 77 Observer* observer_; | 80 Observer* observer_; |
| 78 | 81 |
| 79 // Underlaying CoreBluetooth central manager. | 82 // Underlaying CoreBluetooth central manager. |
| 80 base::scoped_nsobject<CBCentralManager> manager_; | 83 base::scoped_nsobject<CBCentralManager> manager_; |
| 81 | 84 |
| 82 // Discovery has been initiated by calling the API StartDiscovery(). | 85 // Discovery has been initiated by calling the API StartDiscovery(). |
| 83 bool discovering_; | 86 bool discovering_; |
| 84 | 87 |
| 85 // A discovery has been initiated but has not started yet because it's | 88 // A discovery has been initiated but has not started yet because it's |
| 86 // waiting for Bluetooth to turn on. | 89 // waiting for Bluetooth to turn on. |
| 87 bool pending_; | 90 bool pending_; |
| 88 | 91 |
| 89 // Delegate of the central manager. | 92 // Delegate of the central manager. |
| 90 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; | 93 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; |
| 91 | 94 |
| 92 // Map of the device identifiers to the discovered device. | |
| 93 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; | |
| 94 | |
| 95 // List of service UUIDs to scan. | 95 // List of service UUIDs to scan. |
| 96 BluetoothDevice::UUIDList services_uuids_; | 96 BluetoothDevice::UUIDList services_uuids_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); | 98 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } // namespace device | 101 } // namespace device |
| 102 | 102 |
| 103 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | 103 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ |
| OLD | NEW |