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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 1276353005: Planned implementation of CreateGattConnection Base URL: https://chromium.googlesource.com/chromium/src.git@adapimpl-simple
Patch Set: Created 5 years, 4 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
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_low_energy_device_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index f81fdf7ba745480d662a37c7308d9a3b663a882f..74275eff362c03c09057995ba6b8b0fc2abc4942 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -6,6 +6,7 @@
#import <CoreFoundation/CoreFoundation.h>
+#include "base/bind.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/sdk_forward_declarations.h"
@@ -13,6 +14,7 @@
#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_gatt_connection_mac.h"
using device::BluetoothDevice;
using device::BluetoothLowEnergyDeviceMac;
@@ -32,10 +34,15 @@ device::BluetoothUUID BluetoothUUIDWithCBUUID(CBUUID* uuid) {
BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
CBPeripheral* peripheral,
NSDictionary* advertisement_data,
- int rssi) {
+ int rssi,
+ BluetoothAdapter* adapter,
+ CBCentralManager* central_manager)
+ : weak_ptr_factory_(this) {
DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
identifier_ = GetPeripheralIdentifier(peripheral);
hash_address_ = GetPeripheralHashAddress(peripheral);
+ adapter_ = adapter;
+ central_manager_ = central_manager;
Update(peripheral, advertisement_data, rssi);
}
@@ -184,7 +191,12 @@ void BluetoothLowEnergyDeviceMac::CancelPairing() {
void BluetoothLowEnergyDeviceMac::Disconnect(
const base::Closure& callback,
const ErrorCallback& error_callback) {
- NOTIMPLEMENTED();
+ if (!IsConnected())
+ callback.Run();
+
+ disconnect_success_callbacks_.push_back(callback);
+ disconnect_error_callbacks_.push_back(error_callback);
+ [central_manager_ cancelPeripheralConnection:peripheral_];
}
void BluetoothLowEnergyDeviceMac::Forget(const ErrorCallback& error_callback) {
@@ -208,7 +220,16 @@ void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely(
void BluetoothLowEnergyDeviceMac::CreateGattConnection(
const GattConnectionCallback& callback,
const ConnectErrorCallback& error_callback) {
- NOTIMPLEMENTED();
+ if (IsConnected()) {
+ scoped_ptr<device::BluetoothGattConnection> connection(
+ new BluetoothGattConnectionMac(adapter_, GetAddress()));
+ callback.Run(connection.Pass());
+ return;
+ }
+
+ create_gatt_connection_success_callbacks_.push_back(callback);
+ create_gatt_connection_error_callbacks_.push_back(error_callback);
+ [central_manager_ connectPeripheral:peripheral_ options:nil];
}
NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const {
@@ -252,3 +273,10 @@ CBPeripheralState BluetoothLowEnergyDeviceMac::GetPeripheralState() const {
[invocation getReturnValue:&state];
return state;
}
+
+void BluetoothLowEnergyDeviceMac::ClearConnectionCallbacks() {
+ create_gatt_connection_success_callbacks_.clear();
+ create_gatt_connection_error_callbacks_.clear();
+ disconnect_success_callbacks_.clear();
+ disconnect_error_callbacks_.clear();
+}
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698