Commit d962927b authored by Tim Song's avatar Tim Song Committed by Commit Bot

Create a CBPeripheralManager in the BluetoothAdapterMac and its associated delegate.

BUG=846881

Change-Id: Ib6e12ce1d2e6bbeaf85e6ba6727a1079adc699e9
Reviewed-on: https://chromium-review.googlesource.com/1130012
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarGustavo Sacomoto <sacomoto@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575557}
parent 6f205c70
......@@ -156,6 +156,8 @@ component("bluetooth") {
"bluetooth_low_energy_discovery_manager_mac.mm",
"bluetooth_low_energy_peripheral_delegate.h",
"bluetooth_low_energy_peripheral_delegate.mm",
"bluetooth_low_energy_peripheral_manager_delegate.h",
"bluetooth_low_energy_peripheral_manager_delegate.mm",
"bluetooth_low_energy_win.cc",
"bluetooth_low_energy_win.h",
"bluetooth_remote_gatt_characteristic.cc",
......
......@@ -31,6 +31,7 @@
@class NSDate;
@class BluetoothLowEnergyCentralManagerDelegate;
@class BluetoothLowEnergyPeripheralManagerDelegate;
namespace device {
......@@ -151,6 +152,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
// Returns the CBCentralManager instance.
CBCentralManager* GetCentralManager();
// Returns the CBPeripheralManager instance.
CBPeripheralManager* GetPeripheralManager();
// Allow the mocking out of getting the HostController state for testing.
void SetHostControllerStateFunctionForTesting(
HostControllerStateFunction controller_state_function);
......@@ -167,6 +171,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
friend class BluetoothTestMac;
friend class BluetoothAdapterMacTest;
friend class BluetoothLowEnergyCentralManagerBridge;
friend class BluetoothLowEnergyPeripheralManagerBridge;
BluetoothAdapterMac();
~BluetoothAdapterMac() override;
......@@ -264,6 +269,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
base::scoped_nsobject<BluetoothLowEnergyCentralManagerDelegate>
low_energy_central_manager_delegate_;
// Underlying CoreBluetooth CBPeripheralManager and its delegate.
base::scoped_nsobject<CBPeripheralManager> low_energy_peripheral_manager_;
base::scoped_nsobject<BluetoothLowEnergyPeripheralManagerDelegate>
low_energy_peripheral_manager_delegate_;
base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac);
......
......@@ -30,6 +30,7 @@
#include "device/bluetooth/bluetooth_discovery_session.h"
#include "device/bluetooth/bluetooth_discovery_session_outcome.h"
#include "device/bluetooth/bluetooth_low_energy_central_manager_delegate.h"
#include "device/bluetooth/bluetooth_low_energy_peripheral_manager_delegate.h"
#include "device/bluetooth/bluetooth_socket_mac.h"
extern "C" {
......@@ -136,6 +137,12 @@ BluetoothAdapterMac::BluetoothAdapterMac()
queue:dispatch_get_main_queue()]);
low_energy_discovery_manager_->SetCentralManager(
low_energy_central_manager_);
low_energy_peripheral_manager_delegate_.reset(
[[BluetoothLowEnergyPeripheralManagerDelegate alloc]
initWithAdapter:this]);
low_energy_peripheral_manager_.reset([[CBPeripheralManager alloc]
initWithDelegate:low_energy_peripheral_manager_delegate_
queue:dispatch_get_main_queue()]);
}
DCHECK(classic_discovery_manager_);
}
......@@ -337,6 +344,10 @@ CBCentralManager* BluetoothAdapterMac::GetCentralManager() {
return low_energy_central_manager_;
}
CBPeripheralManager* BluetoothAdapterMac::GetPeripheralManager() {
return low_energy_peripheral_manager_;
}
void BluetoothAdapterMac::SetHostControllerStateFunctionForTesting(
HostControllerStateFunction controller_state_function) {
controller_state_function_ = std::move(controller_state_function);
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_PERIPHERAL_MANAGER_DELEGATE_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_PERIPHERAL_MANAGER_DELEGATE_H_
#include "base/mac/sdk_forward_declarations.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#if defined(OS_IOS)
#import <CoreBluetooth/CoreBluetooth.h>
#else
#import <IOBluetooth/IOBluetooth.h>
#endif
namespace device {
class BluetoothAdapterMac;
class BluetoothLowEnergyPeripheralManagerBridge;
} // namespace device
@interface BluetoothLowEnergyPeripheralManagerDelegate
: NSObject<CBPeripheralManagerDelegate> {
std::unique_ptr<device::BluetoothLowEnergyPeripheralManagerBridge> bridge_;
}
- (id)initWithAdapter:(device::BluetoothAdapterMac*)adapter;
@end
#endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_PERIPHERAL_MANAGER_DELEGATE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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_manager_delegate.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
namespace device {
// This class exists to bridge between the Objective-C
// CBPeripheralManagerDelegate class and our BluetoothAdapterMac classes.
class BluetoothLowEnergyPeripheralManagerBridge {
public:
BluetoothLowEnergyPeripheralManagerBridge(BluetoothAdapterMac* adapter)
: adapter_(adapter) {}
~BluetoothLowEnergyPeripheralManagerBridge() {}
void UpdatedState() {
// TODO(tengs): Hook this up to BluetoothAdapterMac.
}
void DidStartAdvertising(NSError* error) {
// TODO(tengs): Hook this up to BluetoothAdapterMac.
}
CBPeripheralManager* GetPeripheralManager() {
return adapter_->GetPeripheralManager();
}
private:
BluetoothAdapterMac* adapter_;
};
} // namespace device
@implementation BluetoothLowEnergyPeripheralManagerDelegate
- (id)initWithAdapter:(device::BluetoothAdapterMac*)adapter {
if ((self = [super init])) {
bridge_.reset(
new device::BluetoothLowEnergyPeripheralManagerBridge(adapter));
}
return self;
}
- (void)dealloc {
[bridge_->GetPeripheralManager() setDelegate:nil];
[super dealloc];
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager*)peripheral {
bridge_->UpdatedState();
}
- (void)peripheralManagerDidStartAdvertising:(CBPeripheralManager*)peripheral
error:(NSError*)error {
bridge_->DidStartAdvertising(error);
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment