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 "base/mac/sdk_forward_declarations.h" | |
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. | |
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; | |
36 | |
37 protected: | |
38 virtual ~Observer() {} | |
39 }; | |
40 | |
41 virtual ~BluetoothLowEnergyDiscoveryManagerMac(); | |
42 | |
43 // Returns true, if discovery is currently being performed. | |
44 virtual bool IsDiscovering() const; | |
45 | |
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); | |
50 | |
51 // Stops a discovery session. | |
52 virtual void StopDiscovery(); | |
53 | |
54 // Returns a new BluetoothLowEnergyDiscoveryManagerMac. | |
55 static BluetoothLowEnergyDiscoveryManagerMac* Create(Observer* observer); | |
56 | |
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); | |
62 | |
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(); | |
69 | |
70 private: | |
71 explicit BluetoothLowEnergyDiscoveryManagerMac(Observer* observer); | |
72 void ClearDevices(); | |
73 | |
74 friend class BluetoothLowEnergyDiscoveryManagerMacDelegate; | |
75 | |
76 // Observer interested in notifications from us. | |
77 Observer* observer_; | |
78 | |
79 // Underlaying CoreBluetooth central manager. | |
80 base::scoped_nsobject<CBCentralManager> manager_; | |
81 | |
82 // Discovery has been initiated by calling the API StartDiscovery(). | |
83 bool discovering_; | |
84 | |
85 // A discovery has been initiated but has not started yet because it's | |
86 // waiting for Bluetooth to turn on. | |
87 bool pending_; | |
88 | |
89 // Delegate of the central manager. | |
90 base::scoped_nsobject<BluetoothLowEnergyDiscoveryManagerMacBridge> bridge_; | |
91 | |
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. | |
96 BluetoothDevice::UUIDList services_uuids_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoveryManagerMac); | |
99 }; | |
100 | |
101 } // namespace device | |
102 | |
103 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVERY_MANAGER_MAC_H_ | |
OLD | NEW |