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 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h" |
| 6 |
| 7 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 8 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h" |
| 9 |
| 10 namespace device { |
| 11 |
| 12 // This class exists to bridge between the Objective-C CBCentralManagerDelegate |
| 13 // class and our BluetoothLowEnergyDiscoveryManagerMac and BluetoothAdapterMac |
| 14 // classes. |
| 15 class BluetoothLowEnergyCentralManagerBridge { |
| 16 public: |
| 17 BluetoothLowEnergyCentralManagerBridge( |
| 18 BluetoothLowEnergyDiscoveryManagerMac* discovery_manager, |
| 19 BluetoothAdapterMac* adapter) |
| 20 : discovery_manager_(discovery_manager), adapter_(adapter) {} |
| 21 |
| 22 virtual ~BluetoothLowEnergyCentralManagerBridge() {} |
| 23 |
| 24 virtual void DiscoveredPeripheral(CBPeripheral* peripheral, |
| 25 NSDictionary* advertisementData, |
| 26 int rssi) { |
| 27 discovery_manager_->DiscoveredPeripheral(peripheral, advertisementData, |
| 28 rssi); |
| 29 } |
| 30 |
| 31 virtual void UpdatedState() { |
| 32 discovery_manager_->TryStartDiscovery(); |
| 33 adapter_->LowEnergyCentralManagerUpdatedState(); |
| 34 } |
| 35 |
| 36 private: |
| 37 BluetoothLowEnergyDiscoveryManagerMac* discovery_manager_; |
| 38 BluetoothAdapterMac* adapter_; |
| 39 }; |
| 40 |
| 41 } // namespace device |
| 42 |
| 43 @implementation BluetoothLowEnergyCentralManagerDelegate |
| 44 |
| 45 - (id)initWithDiscoveryManager: |
| 46 (device::BluetoothLowEnergyDiscoveryManagerMac*)discovery_manager |
| 47 andAdapter:(device::BluetoothAdapterMac*)adapter { |
| 48 if ((self = [super init])) { |
| 49 bridge_.reset(new device::BluetoothLowEnergyCentralManagerBridge( |
| 50 discovery_manager, adapter)); |
| 51 } |
| 52 return self; |
| 53 } |
| 54 |
| 55 - (void)centralManager:(CBCentralManager*)central |
| 56 didDiscoverPeripheral:(CBPeripheral*)peripheral |
| 57 advertisementData:(NSDictionary*)advertisementData |
| 58 RSSI:(NSNumber*)RSSI { |
| 59 // Notifies the discovery of a device. |
| 60 bridge_->DiscoveredPeripheral(peripheral, advertisementData, [RSSI intValue]); |
| 61 } |
| 62 |
| 63 - (void)centralManagerDidUpdateState:(CBCentralManager*)central { |
| 64 // Notifies when the powered state of the central manager changed. |
| 65 bridge_->UpdatedState(); |
| 66 } |
| 67 |
| 68 @end |
OLD | NEW |