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_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.
| |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DISCOVER_MANAGER_MAC_H_ | |
7 | |
8 #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE | |
9 #import <CoreBluetooth/CoreBluetooth.h> | |
10 #else | |
11 #import <IOBluetooth/IOBluetooth.h> | |
12 #endif | |
13 | |
14 #include "base/mac/scoped_nsobject.h" | |
15 | |
16 #include "device/bluetooth/bluetooth_device.h" | |
17 | |
18 @class BluetoothLowEnergyDiscoverManagerMacBridge; | |
19 | |
20 namespace device { | |
21 | |
22 class BluetoothLowEnergyDeviceMac; | |
23 class BluetoothLowEnergyDiscoverManagerMacDelegate; | |
24 | |
25 // This class will scan for bluetooth LE device on Mac. | |
26 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
| |
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 | |
38 virtual ~BluetoothLowEnergyDiscoverManagerMac(); | |
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 BluetoothLowEnergyDiscoverManagerMac. | |
52 static BluetoothLowEnergyDiscoverManagerMac* 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, int rssi); | |
armansito
2015/01/24 17:59:38
nit: new line after this method
dvh
2015/01/27 00:14:55
Done.
| |
58 // The device discovery can really be started when bluetooth is powered on. | |
59 // The method TryStartDiscovery() is called when it's a good time to try to | |
60 // start the BLE device discovery. It will check if the discovery session has | |
61 // been started and if the bluetooth is powered and then really start the | |
62 // CoreBluetooth BLE device discovery. | |
63 virtual void TryStartDiscovery(); | |
64 | |
65 private: | |
66 explicit BluetoothLowEnergyDiscoverManagerMac(Observer* observer); | |
67 void ClearDevices(); | |
68 | |
69 friend class BluetoothLowEnergyDiscoverManagerMacDelegate; | |
70 | |
71 // 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.
| |
72 Observer* observer_; | |
73 // Underlaying CoreBluetooth central manager. | |
74 base::scoped_nsobject<CBCentralManager> manager_; | |
75 // Discovery has been initiated by calling the API StartDiscovery(). | |
76 bool discovering_; | |
77 // A discovery has been initiated but has not started yet because it's | |
78 // waiting for bluetooth to turn on. | |
79 bool pending_; | |
80 // Delegate of the central manager. | |
81 base::scoped_nsobject<BluetoothLowEnergyDiscoverManagerMacBridge> bridge_; | |
82 // Map of the device identifiers to the discovered device. | |
83 std::map<const std::string, BluetoothLowEnergyDeviceMac*> devices_; | |
84 // List of service UUIDs to scan. | |
85 BluetoothDevice::UUIDList services_uuids_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDiscoverManagerMac); | |
88 }; | |
89 | |
90 } // namespace device | |
91 | |
92 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | |
OLD | NEW |