Chromium Code Reviews| 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 TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
ditto
dvh
2015/01/30 22:45:45
Done.
| |
| 9 #import <CoreBluetooth/CoreBluetooth.h> | |
| 10 #else | |
| 11 #import <IOBluetooth/IOBluetooth.h> | |
| 12 #endif | |
| 13 | |
| 14 #include "base/mac/scoped_nsobject.h" | |
| 15 | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
no blank line
dvh
2015/01/30 22:45:45
Done.
| |
| 16 #include "device/bluetooth/bluetooth_device.h" | |
| 17 | |
| 18 @class BluetoothLowEnergyDiscoveryManagerMacBridge; | |
| 19 | |
| 20 namespace device { | |
| 21 | |
| 22 class BluetoothLowEnergyDeviceMac; | |
| 23 class BluetoothLowEnergyDiscoveryManagerMacDelegate; | |
| 24 | |
| 25 // This class will scan for bluetooth LE device on Mac. | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
Bluetooth is capitalized
dvh
2015/01/30 22:45:45
Done.
| |
| 26 class BluetoothLowEnergyDiscoveryManagerMac { | |
| 27 public: | |
| 28 // Interface for being notified of events during a device discovery session. | |
| 29 class Observer { | |
| 30 public: | |
| 31 // Called when |this| manager has found a device. | |
| 32 virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0; | |
| 33 | |
| 34 // Called when |this| manager has updated on a device. | |
| 35 virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0; | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
This interface _must_ have a virtual destructor.
dvh
2015/01/30 22:45:45
is BluetoothDiscoveryManagerMac::Observer wrong as
Avi (use Gerrit)
2015/01/30 23:18:31
Yes, it is. The style guide in "Interfaces" http:/
| |
| 36 }; | |
| 37 | |
| 38 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); | |
| 39 | |
| 40 // Returns true, if discovery is currently being performed. | |
| 41 virtual bool IsDiscovering() const; | |
| 42 | |
| 43 // Initiates a discovery session. | |
| 44 // BluetoothLowEnergyDeviceMac objects discovered within a previous | |
| 45 // discovery session will be invalid. | |
| 46 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids); | |
| 47 | |
| 48 // Stops a discovery session. | |
| 49 virtual void StopDiscovery(); | |
| 50 | |
| 51 // Returns a new BluetoothLowEnergyDiscoveryManagerMac. | |
| 52 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer); | |
| 53 | |
| 54 protected: | |
| 55 // Called when a discovery or an update of a BLE device occurred. | |
| 56 virtual void DiscoveredPeripheral(CBPeripheral* peripheral, | |
| 57 NSDictionary* advertisementData, | |
| 58 int rssi); | |
| 59 | |
| 60 // The device discovery can really be started when bluetooth is powered on. | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
Bluetooth is capitalized.
dvh
2015/01/30 22:45:45
Done.
| |
| 61 // The method TryStartDiscovery() is called when it's a good time to try to | |
| 62 // start the BLE device discovery. It will check if the discovery session has | |
| 63 // been started and if the bluetooth is powered and then really start the | |
|
Avi (use Gerrit)
2015/01/29 05:25:02
Capital B.
dvh
2015/01/30 22:45:45
Done.
| |
| 64 // CoreBluetooth BLE device discovery. | |
| 65 virtual void TryStartDiscovery(); | |
| 66 | |
| 67 private: | |
| 68 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); | |
| 69 void ClearDevices(); | |
| 70 | |
| 71 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; | |
| 72 | |
| 73 // Observer interested in notifications from us. | |
| 74 Observer* observer_; | |
| 75 | |
| 76 // Underlaying CoreBluetooth central manager. | |
| 77 base::scoped_nsobject<CBCentralManager> manager_; | |
| 78 | |
| 79 // Discovery has been initiated by calling the API StartDiscovery(). | |
| 80 bool discovering_; | |
| 81 | |
| 82 // A discovery has been initiated but has not started yet because it's | |
| 83 // waiting for bluetooth to turn on. | |
| 84 bool pending_; | |
| 85 | |
| 86 // Delegate of the central manager. | |
| 87 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; | |
| 88 | |
| 89 // Map of the device identifiers to the discovered device. | |
| 90 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; | |
| 91 | |
| 92 // List of service UUIDs to scan. | |
| 93 BluetoothDevice::UUIDList services_uuids_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); | |
| 96 }; | |
| 97 | |
| 98 } // namespace device | |
| 99 | |
| 100 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | |
| OLD | NEW |