Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2638)

Unified Diff: device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm

Issue 1948763003: Adding support for service scan on OS X (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Adding disconnect with error Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm
diff --git a/device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm b/device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm
new file mode 100644
index 0000000000000000000000000000000000000000..94e81cf5a70507cbf8559f7896536f03f10bed30
--- /dev/null
+++ b/device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm
@@ -0,0 +1,63 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/bluetooth/bluetooth_low_energy_peripheral_delegate.h"
+
+#include "device/bluetooth/bluetooth_adapter_mac.h"
+#include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h"
+
+namespace device {
+
+// This class exists to bridge between the Objective-C CBPeripheralDelegate
+// class and our BluetoothLowEnergyDiscoveryManagerMac and BluetoothAdapterMac
+// 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
+class BluetoothLowEnergyPeripheralBridge {
+ public:
+ BluetoothLowEnergyPeripheralBridge(BluetoothLowEnergyDeviceMac* device_mac)
+ : device_mac_(device_mac) {}
+
+ virtual ~BluetoothLowEnergyPeripheralBridge() {}
ortuno 2016/05/06 16:03:33 Why do you need the virtual here?
jlebel 2016/05/07 00:16:11 Done.
+
+ void DidModifyServices(NSArray* invalidatedServices) {
+ device_mac_->DidModifyServices(invalidatedServices);
+ }
+
+ void DidDiscoverPrimaryServices(NSError* error) {
+ device_mac_->DidDiscoverPrimaryServices(error);
+ };
+
+ CBPeripheral* GetPeripheral() { return device_mac_->GetPeripheral(); }
+
+ private:
+ BluetoothLowEnergyDeviceMac* device_mac_;
+};
+
+} // namespace device
+
+@implementation BluetoothLowEnergyPeripheralDelegate
+
+- (id)initWithBluetoothLowEnergyDeviceMac:
+ (device::BluetoothLowEnergyDeviceMac*)device_mac {
+ if ((self = [super init])) {
+ bridge_.reset(new device::BluetoothLowEnergyPeripheralBridge(device_mac));
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [bridge_->GetPeripheral() setDelegate:nil];
+ [super dealloc];
+}
+
+- (void)peripheral:(CBPeripheral*)peripheral
+ didModifyServices:(NSArray*)invalidatedServices {
+ bridge_->DidModifyServices(invalidatedServices);
+}
+
+- (void)peripheral:(CBPeripheral*)peripheral
+ didDiscoverServices:(NSError*)error {
+ bridge_->DidDiscoverPrimaryServices(error);
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698