OLD | NEW |
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) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); | 103 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); |
104 | 104 |
105 private: | 105 private: |
106 friend class BluetoothAdapterMac; | 106 friend class BluetoothAdapterMac; |
107 friend class BluetoothAdapterMacTest; | 107 friend class BluetoothAdapterMacTest; |
108 friend class BluetoothLowEnergyPeripheralBridge; | 108 friend class BluetoothLowEnergyPeripheralBridge; |
109 friend class BluetoothRemoteGattServiceMac; | 109 friend class BluetoothRemoteGattServiceMac; |
110 friend class BluetoothTestMac; | 110 friend class BluetoothTestMac; |
111 friend class BluetoothRemoteGattServiceMac; | 111 friend class BluetoothRemoteGattServiceMac; |
112 | 112 |
113 // Calls the macOS to discover primary services. | 113 // Called by the adapter when the device is connected. |
| 114 void DidConnectPeripheral(); |
| 115 |
| 116 // Calls macOS to discover primary services. |
114 void DiscoverPrimaryServices(); | 117 void DiscoverPrimaryServices(); |
115 | 118 |
116 // Sends notification if this device is ready with all services discovered. | 119 // Sends notification if this device is ready with all services discovered. |
117 void SendNotificationIfDiscoveryComplete(); | 120 void SendNotificationIfDiscoveryComplete(); |
118 | 121 |
119 // Returns the Bluetooth adapter. | 122 // Returns the Bluetooth adapter. |
120 BluetoothAdapterMac* GetMacAdapter(); | 123 BluetoothAdapterMac* GetMacAdapter(); |
121 | 124 |
122 // Returns the CoreBluetooth Peripheral. | 125 // Returns the CoreBluetooth Peripheral. |
123 CBPeripheral* GetPeripheral(); | 126 CBPeripheral* GetPeripheral(); |
124 | 127 |
125 // Returns BluetoothRemoteGattServiceMac based on the CBService. | 128 // Returns BluetoothRemoteGattServiceMac based on the CBService. |
126 BluetoothRemoteGattServiceMac* GetBluetoothRemoteGattService( | 129 BluetoothRemoteGattServiceMac* GetBluetoothRemoteGattService( |
127 CBService* service) const; | 130 CBService* service) const; |
128 | 131 |
129 // Returns BluetoothRemoteGattDescriptorMac based on the CBDescriptor. | 132 // Returns BluetoothRemoteGattDescriptorMac based on the CBDescriptor. |
130 BluetoothRemoteGattDescriptorMac* GetBluetoothRemoteGattDescriptor( | 133 BluetoothRemoteGattDescriptorMac* GetBluetoothRemoteGattDescriptor( |
131 CBDescriptor* cb_descriptor) const; | 134 CBDescriptor* cb_descriptor) const; |
132 | 135 |
133 // Callback used when the CoreBluetooth Peripheral is disconnected. | 136 // Callback used when the CoreBluetooth Peripheral is disconnected. |
134 void DidDisconnectPeripheral(NSError* error); | 137 void DidDisconnectPeripheral(NSError* error); |
135 | 138 |
136 // CoreBluetooth data structure. | 139 // CoreBluetooth data structure. |
137 base::scoped_nsobject<CBPeripheral> peripheral_; | 140 base::scoped_nsobject<CBPeripheral> peripheral_; |
138 | 141 |
139 // Objective-C delegate for the CBPeripheral. | 142 // Objective-C delegate for the CBPeripheral. |
140 base::scoped_nsobject<BluetoothLowEnergyPeripheralDelegate> | 143 base::scoped_nsobject<BluetoothLowEnergyPeripheralDelegate> |
141 peripheral_delegate_; | 144 peripheral_delegate_; |
142 | 145 |
| 146 // Whether the device is connected. |
| 147 bool connected_; |
| 148 |
143 // The peripheral's identifier, as returned by [CBPeripheral identifier]. | 149 // The peripheral's identifier, as returned by [CBPeripheral identifier]. |
144 std::string identifier_; | 150 std::string identifier_; |
145 | 151 |
146 // A local address for the device created by hashing the peripheral | 152 // A local address for the device created by hashing the peripheral |
147 // identifier. | 153 // identifier. |
148 std::string hash_address_; | 154 std::string hash_address_; |
149 | 155 |
150 // Increases each time -[CBPeripheral discoverServices:] is called, and | 156 // Increases each time -[CBPeripheral discoverServices:] is called, and |
151 // decreases each time DidDiscoverPrimaryServices() is called. Once the | 157 // decreases each time DidDiscoverPrimaryServices() is called. Once the |
152 // value is set to 0, characteristics and properties are discovered. | 158 // value is set to 0, characteristics and properties are discovered. |
153 int discovery_pending_count_; | 159 int discovery_pending_count_; |
154 | 160 |
155 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | 161 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); |
156 }; | 162 }; |
157 | 163 |
158 // Stream operator for logging. | 164 // Stream operator for logging. |
159 DEVICE_BLUETOOTH_EXPORT std::ostream& operator<<( | 165 DEVICE_BLUETOOTH_EXPORT std::ostream& operator<<( |
160 std::ostream& out, | 166 std::ostream& out, |
161 const BluetoothLowEnergyDeviceMac& device); | 167 const BluetoothLowEnergyDeviceMac& device); |
162 | 168 |
163 } // namespace device | 169 } // namespace device |
164 | 170 |
165 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 171 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
OLD | NEW |