| 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 mojom::BluetoothGattIDPtr char_id, | 996 mojom::BluetoothGattIDPtr char_id, |
| 997 const RegisterForGattNotificationCallback& callback) { | 997 const RegisterForGattNotificationCallback& callback) { |
| 998 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( | 998 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( |
| 999 std::move(remote_addr), std::move(service_id), std::move(char_id)); | 999 std::move(remote_addr), std::move(service_id), std::move(char_id)); |
| 1000 | 1000 |
| 1001 if (!characteristic) { | 1001 if (!characteristic) { |
| 1002 LOG(WARNING) << __func__ << " Characteristic is not existed."; | 1002 LOG(WARNING) << __func__ << " Characteristic is not existed."; |
| 1003 return; | 1003 return; |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 if (characteristic->IsNotifying()) { | |
| 1007 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | |
| 1008 return; | |
| 1009 } | |
| 1010 | |
| 1011 characteristic->StartNotifySession( | 1006 characteristic->StartNotifySession( |
| 1012 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, | 1007 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, |
| 1013 weak_factory_.GetWeakPtr(), callback, | 1008 weak_factory_.GetWeakPtr(), callback, |
| 1014 characteristic->GetIdentifier()), | 1009 characteristic->GetIdentifier()), |
| 1015 base::Bind(&OnGattOperationError, callback)); | 1010 base::Bind(&OnGattOperationError, callback)); |
| 1016 } | 1011 } |
| 1017 | 1012 |
| 1018 void ArcBluetoothBridge::DeregisterForGattNotification( | 1013 void ArcBluetoothBridge::DeregisterForGattNotification( |
| 1019 mojom::BluetoothAddressPtr remote_addr, | 1014 mojom::BluetoothAddressPtr remote_addr, |
| 1020 mojom::BluetoothGattServiceIDPtr service_id, | 1015 mojom::BluetoothGattServiceIDPtr service_id, |
| 1021 mojom::BluetoothGattIDPtr char_id, | 1016 mojom::BluetoothGattIDPtr char_id, |
| 1022 const DeregisterForGattNotificationCallback& callback) { | 1017 const DeregisterForGattNotificationCallback& callback) { |
| 1023 DCHECK(CalledOnValidThread()); | 1018 DCHECK(CalledOnValidThread()); |
| 1024 | 1019 |
| 1025 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( | 1020 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( |
| 1026 std::move(remote_addr), std::move(service_id), std::move(char_id)); | 1021 std::move(remote_addr), std::move(service_id), std::move(char_id)); |
| 1027 | 1022 |
| 1028 if (!characteristic) { | 1023 if (!characteristic) { |
| 1029 LOG(WARNING) << __func__ << " Characteristic is not existed."; | 1024 LOG(WARNING) << __func__ << " Characteristic is not existed."; |
| 1030 return; | 1025 return; |
| 1031 } | 1026 } |
| 1032 | 1027 |
| 1033 if (!characteristic->IsNotifying()) { | |
| 1034 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | |
| 1035 return; | |
| 1036 } | |
| 1037 | |
| 1038 std::string char_id_str = characteristic->GetIdentifier(); | 1028 std::string char_id_str = characteristic->GetIdentifier(); |
| 1039 std::unique_ptr<BluetoothGattNotifySession> notify = | 1029 std::unique_ptr<BluetoothGattNotifySession> notify = |
| 1040 std::move(notification_session_[char_id_str]); | 1030 std::move(notification_session_[char_id_str]); |
| 1041 notification_session_.erase(char_id_str); | 1031 notification_session_.erase(char_id_str); |
| 1042 notify->Stop(base::Bind(&OnGattOperationDone, callback)); | 1032 notify->Stop(base::Bind(&OnGattOperationDone, callback)); |
| 1043 } | 1033 } |
| 1044 | 1034 |
| 1045 void ArcBluetoothBridge::ReadRemoteRssi( | 1035 void ArcBluetoothBridge::ReadRemoteRssi( |
| 1046 mojom::BluetoothAddressPtr remote_addr, | 1036 mojom::BluetoothAddressPtr remote_addr, |
| 1047 const ReadRemoteRssiCallback& callback) { | 1037 const ReadRemoteRssiCallback& callback) { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1522 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1533 << ") need version " << version_need; | 1523 << ") need version " << version_need; |
| 1534 return false; | 1524 return false; |
| 1535 } | 1525 } |
| 1536 | 1526 |
| 1537 bool ArcBluetoothBridge::CalledOnValidThread() { | 1527 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1538 return thread_checker_.CalledOnValidThread(); | 1528 return thread_checker_.CalledOnValidThread(); |
| 1539 } | 1529 } |
| 1540 | 1530 |
| 1541 } // namespace arc | 1531 } // namespace arc |
| OLD | NEW |