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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1538173003: Implementing GATT connection/disconnect on OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing chromium.gyp_env Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void BluetoothAdapterMac::SetCentralManagerForTesting( 225 void BluetoothAdapterMac::SetCentralManagerForTesting(
226 CBCentralManager* central_manager) { 226 CBCentralManager* central_manager) {
227 CHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); 227 CHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
228 [central_manager performSelector:@selector(setDelegate:) 228 [central_manager performSelector:@selector(setDelegate:)
229 withObject:low_energy_central_manager_delegate_]; 229 withObject:low_energy_central_manager_delegate_];
230 low_energy_central_manager_.reset(central_manager); 230 low_energy_central_manager_.reset(central_manager);
231 low_energy_discovery_manager_->SetCentralManager( 231 low_energy_discovery_manager_->SetCentralManager(
232 low_energy_central_manager_.get()); 232 low_energy_central_manager_.get());
233 } 233 }
234 234
235 CBCentralManager* BluetoothAdapterMac::GetCentralManagerForTesting() {
236 return low_energy_central_manager_;
237 }
238
235 void BluetoothAdapterMac::RemovePairingDelegateInternal( 239 void BluetoothAdapterMac::RemovePairingDelegateInternal(
236 BluetoothDevice::PairingDelegate* pairing_delegate) { 240 BluetoothDevice::PairingDelegate* pairing_delegate) {
237 } 241 }
238 242
239 void BluetoothAdapterMac::AddDiscoverySession( 243 void BluetoothAdapterMac::AddDiscoverySession(
240 BluetoothDiscoveryFilter* discovery_filter, 244 BluetoothDiscoveryFilter* discovery_filter,
241 const base::Closure& callback, 245 const base::Closure& callback,
242 const DiscoverySessionErrorCallback& error_callback) { 246 const DiscoverySessionErrorCallback& error_callback) {
243 DVLOG(1) << __func__; 247 DVLOG(1) << __func__;
244 if (num_discovery_sessions_ > 0) { 248 if (num_discovery_sessions_ > 0) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 534 }
531 } 535 }
532 536
533 void BluetoothAdapterMac::AddPairedDevices() { 537 void BluetoothAdapterMac::AddPairedDevices() {
534 // Add any new paired devices. 538 // Add any new paired devices.
535 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 539 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
536 ClassicDeviceAdded(device); 540 ClassicDeviceAdded(device);
537 } 541 }
538 } 542 }
539 543
544 void BluetoothAdapterMac::CreateGattConnection(
545 BluetoothLowEnergyDeviceMac* device_mac) {
546 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_
547 options:nil];
548 }
549
550 void BluetoothAdapterMac::DidConnectPeripheral(CBPeripheral* peripheral) {
551 std::string device_address =
552 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
553 // Try to find device from |devices_| with key |device_address|,
554 // if has no entry in the map, disconnect the peripheral.
555 DevicesMap::const_iterator iter = devices_.find(device_address);
556 if (iter == devices_.end()) {
557 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
558 return;
559 }
560 BluetoothLowEnergyDeviceMac* device_mac =
561 static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
562 device_mac->GattConnected();
563 }
564
565 void BluetoothAdapterMac::DisconnectGatt(
566 BluetoothLowEnergyDeviceMac* device_mac) {
567 [low_energy_central_manager_
568 cancelPeripheralConnection:device_mac->peripheral_];
569 }
570
540 } // namespace device 571 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698