Mark //testing/perf target testonly.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_low_energy_discovery_manager_mac.h
blob29ad5297e623b95d13fa0fa50a994d372715517c
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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_
8 #if defined(OS_IOS)
9 #import <CoreBluetooth/CoreBluetooth.h>
10 #else
11 #import <IOBluetooth/IOBluetooth.h>
12 #endif
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/mac/sdk_forward_declarations.h"
16 #include "device/bluetooth/bluetooth_device.h"
18 @class BluetoothLowEnergyDiscoveryManagerMacBridge;
20 namespace device {
22 class BluetoothLowEnergyDeviceMac;
23 class BluetoothLowEnergyDiscoveryManagerMacDelegate;
25 // This class will scan for Bluetooth LE device on Mac.
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;
34 // Called when |this| manager has updated on a device.
35 virtual void DeviceUpdated(BluetoothLowEnergyDeviceMac* device) = 0;
37 protected:
38 virtual ~Observer() {}
41 virtual ~BluetoothLowEnergyDiscoveryManagerMac();
43 // Returns true, if discovery is currently being performed.
44 virtual bool IsDiscovering() const;
46 // Initiates a discovery session.
47 // BluetoothLowEnergyDeviceMac objects discovered within a previous
48 // discovery session will be invalid.
49 virtual void StartDiscovery(BluetoothDevice::UUIDList services_uuids);
51 // Stops a discovery session.
52 virtual void StopDiscovery();
54 // Returns a new BluetoothLowEnergyDiscoveryManagerMac.
55 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer);
57 protected:
58 // Called when a discovery or an update of a BLE device occurred.
59 virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
60 NSDictionary* advertisementData,
61 int rssi);
63 // 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
65 // 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
67 // CoreBluetooth BLE device discovery.
68 virtual void TryStartDiscovery();
70 private:
71 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer);
72 void ClearDevices();
74 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate;
76 // Observer interested in notifications from us.
77 Observer* observer_;
79 // Underlaying CoreBluetooth central manager.
80 base::scoped_nsobject<CBCentralManager> manager_;
82 // Discovery has been initiated by calling the API StartDiscovery().
83 bool discovering_;
85 // A discovery has been initiated but has not started yet because it's
86 // waiting for Bluetooth to turn on.
87 bool pending_;
89 // Delegate of the central manager.
90 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_;
92 // Map of the device identifiers to the discovered device.
93 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_;
95 // List of service UUIDs to scan.
96 BluetoothDevice::UUIDList services_uuids_;
98 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac);
101 } // namespace device
103 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_