OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_remote_gatt_characteristic_mac.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "device/bluetooth/bluetooth_adapter_mac.h" | 11 #include "device/bluetooth/bluetooth_adapter_mac.h" |
12 #include "device/bluetooth/bluetooth_device_mac.h" | 12 #include "device/bluetooth/bluetooth_device_mac.h" |
13 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 13 #include "device/bluetooth/bluetooth_gatt_notify_session_mac.h" |
14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
15 | 15 |
16 namespace device { | 16 namespace device { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 static BluetoothGattCharacteristic::Properties ConvertProperties( | 20 static BluetoothGattCharacteristic::Properties ConvertProperties( |
21 CBCharacteristicProperties cb_property) { | 21 CBCharacteristicProperties cb_property) { |
22 BluetoothGattCharacteristic::Properties result = | 22 BluetoothGattCharacteristic::Properties result = |
23 BluetoothGattCharacteristic::PROPERTY_NONE; | 23 BluetoothGattCharacteristic::PROPERTY_NONE; |
(...skipping 103 matching lines...) Loading... |
127 const std::string& identifier) const { | 127 const std::string& identifier) const { |
128 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
129 return nullptr; | 129 return nullptr; |
130 } | 130 } |
131 | 131 |
132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( | 132 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( |
133 const NotifySessionCallback& callback, | 133 const NotifySessionCallback& callback, |
134 const ErrorCallback& error_callback) { | 134 const ErrorCallback& error_callback) { |
135 if (IsNotifying()) { | 135 if (IsNotifying()) { |
136 VLOG(2) << "Already notifying. Creating notify session."; | 136 VLOG(2) << "Already notifying. Creating notify session."; |
137 std::unique_ptr<BluetoothGattNotifySession> notify_session( | 137 std::unique_ptr<BluetoothGattNotifySessionMac> notify_session( |
138 new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())); | 138 new BluetoothGattNotifySessionMac(weak_ptr_factory_.GetWeakPtr())); |
139 base::ThreadTaskRunnerHandle::Get()->PostTask( | 139 base::ThreadTaskRunnerHandle::Get()->PostTask( |
140 FROM_HERE, | 140 FROM_HERE, |
141 base::Bind(callback, base::Passed(std::move(notify_session)))); | 141 base::Bind(callback, base::Passed(std::move(notify_session)))); |
142 return; | 142 return; |
143 } | 143 } |
144 | 144 |
145 if (!SupportsNotificationsOrIndications()) { | 145 if (!SupportsNotificationsOrIndications()) { |
146 base::ThreadTaskRunnerHandle::Get()->PostTask( | 146 base::ThreadTaskRunnerHandle::Get()->PostTask( |
147 FROM_HERE, | 147 FROM_HERE, |
148 base::Bind(error_callback, | 148 base::Bind(error_callback, |
(...skipping 67 matching lines...) Loading... |
216 forCharacteristic:cb_characteristic_ | 216 forCharacteristic:cb_characteristic_ |
217 type:write_type]; | 217 type:write_type]; |
218 if (write_type == CBCharacteristicWriteWithoutResponse) { | 218 if (write_type == CBCharacteristicWriteWithoutResponse) { |
219 base::ThreadTaskRunnerHandle::Get()->PostTask( | 219 base::ThreadTaskRunnerHandle::Get()->PostTask( |
220 FROM_HERE, | 220 FROM_HERE, |
221 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, | 221 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, |
222 base::Unretained(this), nil)); | 222 base::Unretained(this), nil)); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( | |
227 BluetoothRemoteGattDescriptor* ccc_descriptor, | |
228 const base::Closure& callback, | |
229 const ErrorCallback& error_callback) { | |
230 // TODO(http://crbug.com/633191): Implement this method | |
231 NOTIMPLEMENTED(); | |
232 } | |
233 | |
234 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( | |
235 BluetoothRemoteGattDescriptor* ccc_descriptor, | |
236 const base::Closure& callback, | |
237 const ErrorCallback& error_callback) { | |
238 // TODO(http://crbug.com/633191): Implement this method | |
239 NOTIMPLEMENTED(); | |
240 } | |
241 | |
242 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { | 226 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { |
243 // This method is called when the characteristic is read and when a | 227 // This method is called when the characteristic is read and when a |
244 // notification is received. | 228 // notification is received. |
245 if (characteristic_value_read_or_write_in_progress_) { | 229 if (characteristic_value_read_or_write_in_progress_) { |
246 std::pair<ValueCallback, ErrorCallback> callbacks; | 230 std::pair<ValueCallback, ErrorCallback> callbacks; |
247 callbacks.swap(read_characteristic_value_callbacks_); | 231 callbacks.swap(read_characteristic_value_callbacks_); |
248 characteristic_value_read_or_write_in_progress_ = false; | 232 characteristic_value_read_or_write_in_progress_ = false; |
249 if (error) { | 233 if (error) { |
250 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " | 234 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " |
251 << base::SysNSStringToUTF8(error.domain) | 235 << base::SysNSStringToUTF8(error.domain) |
(...skipping 63 matching lines...) Loading... |
315 << ", error code: " << error.code << ", localized description: " | 299 << ", error code: " << error.code << ", localized description: " |
316 << base::SysNSStringToUTF8(error.localizedDescription); | 300 << base::SysNSStringToUTF8(error.localizedDescription); |
317 BluetoothGattService::GattErrorCode error_code = | 301 BluetoothGattService::GattErrorCode error_code = |
318 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 302 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
319 for (const auto& callback : reentrant_safe_callbacks) { | 303 for (const auto& callback : reentrant_safe_callbacks) { |
320 callback.second.Run(error_code); | 304 callback.second.Run(error_code); |
321 } | 305 } |
322 return; | 306 return; |
323 } | 307 } |
324 for (const auto& callback : reentrant_safe_callbacks) { | 308 for (const auto& callback : reentrant_safe_callbacks) { |
325 callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>( | 309 callback.first.Run(base::MakeUnique<BluetoothGattNotifySessionMac>( |
326 weak_ptr_factory_.GetWeakPtr())); | 310 weak_ptr_factory_.GetWeakPtr())); |
327 } | 311 } |
328 } | 312 } |
329 | 313 |
330 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { | 314 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { |
331 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; | 315 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; |
332 } | 316 } |
333 | 317 |
334 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { | 318 bool BluetoothRemoteGattCharacteristicMac::IsWritable() const { |
335 BluetoothGattCharacteristic::Properties properties = GetProperties(); | 319 BluetoothGattCharacteristic::Properties properties = GetProperties(); |
(...skipping 12 matching lines...) Loading... |
348 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) | 332 return (GetProperties() & BluetoothGattCharacteristic::PROPERTY_WRITE) |
349 ? CBCharacteristicWriteWithResponse | 333 ? CBCharacteristicWriteWithResponse |
350 : CBCharacteristicWriteWithoutResponse; | 334 : CBCharacteristicWriteWithoutResponse; |
351 } | 335 } |
352 | 336 |
353 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() | 337 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() |
354 const { | 338 const { |
355 return cb_characteristic_.get(); | 339 return cb_characteristic_.get(); |
356 } | 340 } |
357 } // namespace device. | 341 } // namespace device. |
OLD | NEW |