Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
ortuno
2016/05/06 16:03:33
nit: 2016
jlebel
2016/05/07 00:16:11
Done.
| |
| 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_peripheral_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 CBPeripheralDelegate | |
| 13 // class and our BluetoothLowEnergyDiscoveryManagerMac and BluetoothAdapterMac | |
| 14 // classes. | |
|
ortuno
2016/05/06 16:03:33
Out of curiosity: why do we need this class? Why c
jlebel
2016/05/07 00:16:11
I'm following the pattern that already exist for B
ortuno
2016/05/09 19:54:00
It's OK. I just wanted to know the background for
| |
| 15 class BluetoothLowEnergyPeripheralBridge { | |
| 16 public: | |
| 17 BluetoothLowEnergyPeripheralBridge(BluetoothLowEnergyDeviceMac* device_mac) | |
| 18 : device_mac_(device_mac) {} | |
| 19 | |
| 20 virtual ~BluetoothLowEnergyPeripheralBridge() {} | |
|
ortuno
2016/05/06 16:03:33
Why do you need the virtual here?
jlebel
2016/05/07 00:16:11
Done.
| |
| 21 | |
| 22 void DidModifyServices(NSArray* invalidatedServices) { | |
| 23 device_mac_->DidModifyServices(invalidatedServices); | |
| 24 } | |
| 25 | |
| 26 void DidDiscoverPrimaryServices(NSError* error) { | |
| 27 device_mac_->DidDiscoverPrimaryServices(error); | |
| 28 }; | |
| 29 | |
| 30 CBPeripheral* GetPeripheral() { return device_mac_->GetPeripheral(); } | |
| 31 | |
| 32 private: | |
| 33 BluetoothLowEnergyDeviceMac* device_mac_; | |
| 34 }; | |
| 35 | |
| 36 } // namespace device | |
| 37 | |
| 38 @implementation BluetoothLowEnergyPeripheralDelegate | |
| 39 | |
| 40 - (id)initWithBluetoothLowEnergyDeviceMac: | |
| 41 (device::BluetoothLowEnergyDeviceMac*)device_mac { | |
| 42 if ((self = [super init])) { | |
| 43 bridge_.reset(new device::BluetoothLowEnergyPeripheralBridge(device_mac)); | |
| 44 } | |
| 45 return self; | |
| 46 } | |
| 47 | |
| 48 - (void)dealloc { | |
| 49 [bridge_->GetPeripheral() setDelegate:nil]; | |
| 50 [super dealloc]; | |
| 51 } | |
| 52 | |
| 53 - (void)peripheral:(CBPeripheral*)peripheral | |
| 54 didModifyServices:(NSArray*)invalidatedServices { | |
| 55 bridge_->DidModifyServices(invalidatedServices); | |
| 56 } | |
| 57 | |
| 58 - (void)peripheral:(CBPeripheral*)peripheral | |
| 59 didDiscoverServices:(NSError*)error { | |
| 60 bridge_->DidDiscoverPrimaryServices(error); | |
| 61 } | |
| 62 | |
| 63 @end | |
| OLD | NEW |