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.
5 #include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h"
7 #include "device/bluetooth/bluetooth_adapter_mac.h"
8 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h"
12 // This class exists to bridge between the Objective-C CBCentralManagerDelegate
13 // class and our BluetoothLowEnergyDiscoveryManagerMac and BluetoothAdapterMac
15 class BluetoothLowEnergyCentralManagerBridge {
17 BluetoothLowEnergyCentralManagerBridge(
18 BluetoothLowEnergyDiscoveryManagerMac* discovery_manager,
19 BluetoothAdapterMac* adapter)
20 : discovery_manager_(discovery_manager), adapter_(adapter) {}
22 virtual ~BluetoothLowEnergyCentralManagerBridge() {}
24 virtual void DiscoveredPeripheral(CBPeripheral* peripheral,
25 NSDictionary* advertisementData,
27 discovery_manager_->DiscoveredPeripheral(peripheral, advertisementData,
31 virtual void UpdatedState() {
32 discovery_manager_->TryStartDiscovery();
33 adapter_->LowEnergyCentralManagerUpdatedState();
37 BluetoothLowEnergyDiscoveryManagerMac* discovery_manager_;
38 BluetoothAdapterMac* adapter_;
43 @implementation BluetoothLowEnergyCentralManagerDelegate
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));
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]);
63 - (void)centralManagerDidUpdateState:(CBCentralManager*)central {
64 // Notifies when the powered state of the central manager changed.
65 bridge_->UpdatedState();