Chromium Code Reviews| Index: device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h |
| diff --git a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5178a6059a860a716538247b950c325269d9e1b |
| --- /dev/null |
| +++ b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVER_MANAGER_MAC_H_ |
|
armansito
2015/01/24 17:59:37
The header is named *_discovery_manager_* but ever
dvh
2015/01/27 00:14:55
Done.
|
| +#define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVER_MANAGER_MAC_H_ |
| + |
| +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE |
| +#import <CoreBluetooth/CoreBluetooth.h> |
| +#else |
| +#import <IOBluetooth/IOBluetooth.h> |
| +#endif |
| + |
| +#include "base/mac/scoped_nsobject.h" |
| + |
| +#include "device/bluetooth/bluetooth_device.h" |
| + |
| +@class BluetoothLowEnergyDiscoverManagerMacBridge; |
| + |
| +namespace device { |
| + |
| +class BluetoothLowEnergyDeviceMac; |
| +class BluetoothLowEnergyDiscoverManagerMacDelegate; |
| + |
| +// This class will scan for bluetooth LE device on Mac. |
| +class BluetoothLowEnergyDiscoverManagerMac { |
|
armansito
2015/01/24 17:59:37
This class should inherit from BluetoothDiscoveryM
dvh
2015/01/27 00:14:55
Does it make sense to inherit from BluetoothDiscov
armansito
2015/01/29 04:37:18
No, I like keeping the LE stuff separate from Blue
|
| + public: |
| + // Interface for being notified of events during a device discovery session. |
| + class Observer { |
| + public: |
| + // Called when |this| manager has found a device. |
| + virtual void DeviceFound(BluetoothLowEnergyDeviceMac* device) = 0; |
| + |
| + // Called when |this| manager has updated on a device. |
| + virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0; |
| + }; |
| + |
| + virtual ~BluetoothLowEnergyDiscoverManagerMac(); |
| + |
| + // Returns true, if discovery is currently being performed. |
| + virtual bool IsDiscovering() const; |
| + |
| + // Initiates a discovery session. |
| + // BluetoothLowEnergyDeviceMac objects discovered within a previous |
| + // discovery session will be invalid. |
| + virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids); |
| + |
| + // Stops a discovery session. |
| + virtual void StopDiscovery(); |
| + |
| + // Returns a new BluetoothLowEnergyDiscoverManagerMac. |
| + static BluetoothLowEnergyDiscoverManagerMac* Create(Observer* observer); |
| + |
| + protected: |
| + // Called when a discovery or an update of a BLE device occurred. |
| + virtual void DiscoveredPeripheral(CBPeripheral* peripheral, |
| + NSDictionary* advertisementData, int rssi); |
|
armansito
2015/01/24 17:59:38
nit: new line after this method
dvh
2015/01/27 00:14:55
Done.
|
| + // The device discovery can really be started when bluetooth is powered on. |
| + // The method TryStartDiscovery() is called when it's a good time to try to |
| + // start the BLE device discovery. It will check if the discovery session has |
| + // been started and if the bluetooth is powered and then really start the |
| + // CoreBluetooth BLE device discovery. |
| + virtual void TryStartDiscovery(); |
| + |
| + private: |
| + explicit BluetoothLowEnergyDiscoverManagerMac(Observer* observer); |
| + void ClearDevices(); |
| + |
| + friend class BluetoothLowEnergyDiscoverManagerMacDelegate; |
| + |
| + // Observer interested in notifications from us. |
|
armansito
2015/01/24 17:59:37
nit: Please add a new line after member declaratio
dvh
2015/01/27 00:14:55
Done.
|
| + Observer* observer_; |
| + // Underlaying CoreBluetooth central manager. |
| + base::scoped_nsobject<CBCentralManager> manager_; |
| + // Discovery has been initiated by calling the API StartDiscovery(). |
| + bool discovering_; |
| + // A discovery has been initiated but has not started yet because it's |
| + // waiting for bluetooth to turn on. |
| + bool pending_; |
| + // Delegate of the central manager. |
| + base::scoped_nsobject<BluetoothLowEnergyDiscoverManagerMacBridge> bridge_; |
| + // Map of the device identifiers to the discovered device. |
| + std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; |
| + // List of service UUIDs to scan. |
| + BluetoothDevice::UUIDList services_uuids_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoverManagerMac); |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |