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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_device_mac.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
7 7
8 #if defined(OS_IOS) 8 #if defined(OS_IOS)
9 #import <CoreBluetooth/CoreBluetooth.h> 9 #import <CoreBluetooth/CoreBluetooth.h>
10 #else // !defined(OS_IOS) 10 #else // !defined(OS_IOS)
11 #import <IOBluetooth/IOBluetooth.h> 11 #import <IOBluetooth/IOBluetooth.h>
12 #endif // defined(OS_IOS) 12 #endif // defined(OS_IOS)
13 13
14 #include <stdint.h> 14 #include <stdint.h>
15 15
16 #include <set> 16 #include <set>
17 17
18 #include "base/mac/scoped_nsobject.h" 18 #include "base/mac/scoped_nsobject.h"
19 #include "base/mac/sdk_forward_declarations.h" 19 #include "base/mac/sdk_forward_declarations.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "crypto/sha2.h" 22 #include "crypto/sha2.h"
23 #include "device/bluetooth/bluetooth_device_mac.h" 23 #include "device/bluetooth/bluetooth_device_mac.h"
24 24
25 @class BluetoothLowEnergyPeripheralDelegate;
26
25 namespace device { 27 namespace device {
26 28
27 class BluetoothAdapterMac; 29 class BluetoothAdapterMac;
28 class BluetoothLowEnergyDiscoverManagerMac; 30 class BluetoothLowEnergyDiscoverManagerMac;
31 class BluetoothRemoteGattServiceMac;
29 32
30 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac 33 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac
31 : public BluetoothDeviceMac { 34 : public BluetoothDeviceMac {
32 public: 35 public:
33 BluetoothLowEnergyDeviceMac(BluetoothAdapterMac* adapter, 36 BluetoothLowEnergyDeviceMac(BluetoothAdapterMac* adapter,
34 CBPeripheral* peripheral, 37 CBPeripheral* peripheral,
35 NSDictionary* advertisement_data, 38 NSDictionary* advertisement_data,
36 int rssi); 39 int rssi);
37 ~BluetoothLowEnergyDeviceMac() override; 40 ~BluetoothLowEnergyDeviceMac() override;
38 41
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const ConnectToServiceCallback& callback, 83 const ConnectToServiceCallback& callback,
81 const ConnectToServiceErrorCallback& error_callback) override; 84 const ConnectToServiceErrorCallback& error_callback) override;
82 85
83 // BluetoothDeviceMac override. 86 // BluetoothDeviceMac override.
84 NSDate* GetLastUpdateTime() const override; 87 NSDate* GetLastUpdateTime() const override;
85 88
86 protected: 89 protected:
87 // BluetoothDevice override. 90 // BluetoothDevice override.
88 std::string GetDeviceName() const override; 91 std::string GetDeviceName() const override;
89 void CreateGattConnectionImpl() override; 92 void CreateGattConnectionImpl() override;
93 void DidConnectGatt() override;
90 void DisconnectGatt() override; 94 void DisconnectGatt() override;
91 95
96 // Methods for BluetoothLowEnergyPeripheralBridge.
ortuno 2016/05/06 16:03:32 nit: Methods used by BluetoothLowEnergyPeripheralB
jlebel 2016/05/07 00:16:10 Done.
97 void DidDiscoverPrimaryServices(NSError* error);
98 void DidModifyServices(NSArray* invalidatedServices);
99
92 // Updates information about the device. 100 // Updates information about the device.
93 virtual void Update(NSDictionary* advertisement_data, int rssi); 101 virtual void Update(NSDictionary* advertisement_data, int rssi);
94 102
95 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); 103 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral);
96 104
97 // Hashes and truncates the peripheral identifier to deterministically 105 // Hashes and truncates the peripheral identifier to deterministically
98 // construct an address. The use of fake addresses is a temporary fix before 106 // construct an address. The use of fake addresses is a temporary fix before
99 // we switch to using bluetooth identifiers throughout Chrome. 107 // we switch to using bluetooth identifiers throughout Chrome.
100 // http://crbug.com/507824 108 // http://crbug.com/507824
101 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); 109 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral);
102 110
103 private: 111 private:
104 friend class BluetoothAdapterMac; 112 friend class BluetoothAdapterMac;
105 friend class BluetoothAdapterMacTest; 113 friend class BluetoothAdapterMacTest;
114 friend class BluetoothLowEnergyPeripheralBridge;
106 friend class BluetoothTestMac; 115 friend class BluetoothTestMac;
107 116
108 // Returns the Bluetooth adapter. 117 // Returns the Bluetooth adapter.
109 BluetoothAdapterMac* GetMacAdapter(); 118 BluetoothAdapterMac* GetMacAdapter();
110 119
111 // Returns the CoreBluetooth Peripheral. 120 // Returns the CoreBluetooth Peripheral.
112 CBPeripheral* GetPeripheral(); 121 CBPeripheral* GetPeripheral();
113 122
123 // Returns BluetoothRemoteGattServiceMac based on the CBService.
124 BluetoothRemoteGattServiceMac* GetBluetoothRemoteGattService(
125 CBService* service) const;
126
114 // Callback used when the CoreBluetooth Peripheral is disconnected. 127 // Callback used when the CoreBluetooth Peripheral is disconnected.
115 void DidDisconnectPeripheral(BluetoothDevice::ConnectErrorCode error_code); 128 void DidDisconnectPeripheral(BluetoothDevice::ConnectErrorCode error_code);
116 129
117 // CoreBluetooth data structure. 130 // CoreBluetooth data structure.
118 base::scoped_nsobject<CBPeripheral> peripheral_; 131 base::scoped_nsobject<CBPeripheral> peripheral_;
132 base::scoped_nsobject<BluetoothLowEnergyPeripheralDelegate>
ortuno 2016/05/06 16:03:32 nit: Add comment for this member.
jlebel 2016/05/07 00:16:10 Done.
133 peripheral_delegate_;
119 134
120 // RSSI value. 135 // RSSI value.
121 int rssi_; 136 int rssi_;
122 137
123 // Whether the device is connectable. 138 // Whether the device is connectable.
124 bool connectable_; 139 bool connectable_;
125 140
126 // The peripheral's identifier, as returned by [CBPeripheral identifier]. 141 // The peripheral's identifier, as returned by [CBPeripheral identifier].
127 std::string identifier_; 142 std::string identifier_;
128 143
129 // A local address for the device created by hashing the peripheral 144 // A local address for the device created by hashing the peripheral
130 // identifier. 145 // identifier.
131 std::string hash_address_; 146 std::string hash_address_;
132 147
133 // Stores the time of the most recent call to Update(). 148 // Stores the time of the most recent call to Update().
134 base::scoped_nsobject<NSDate> last_update_time_; 149 base::scoped_nsobject<NSDate> last_update_time_;
135 150
136 // The services (identified by UUIDs) that this device provides. 151 // The services (identified by UUIDs) that this device provides.
137 std::set<BluetoothUUID> advertised_uuids_; 152 std::set<BluetoothUUID> advertised_uuids_;
138 153
139 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); 154 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac);
140 }; 155 };
141 156
142 } // namespace device 157 } // namespace device
143 158
144 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ 159 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698