Chromium Code Reviews| 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 <bluetooth/bluetooth.h> | 7 #include <bluetooth/bluetooth.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 mojom::BluetoothGattIDPtr char_id, | 1092 mojom::BluetoothGattIDPtr char_id, |
| 1093 const RegisterForGattNotificationCallback& callback) { | 1093 const RegisterForGattNotificationCallback& callback) { |
| 1094 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( | 1094 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( |
| 1095 std::move(remote_addr), std::move(service_id), std::move(char_id)); | 1095 std::move(remote_addr), std::move(service_id), std::move(char_id)); |
| 1096 | 1096 |
| 1097 if (!characteristic) { | 1097 if (!characteristic) { |
| 1098 LOG(WARNING) << __func__ << " Characteristic is not existed."; | 1098 LOG(WARNING) << __func__ << " Characteristic is not existed."; |
| 1099 return; | 1099 return; |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 if (characteristic->IsNotifying()) { | |
| 1103 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | |
| 1104 return; | |
| 1105 } | |
| 1106 | |
| 1107 characteristic->StartNotifySession( | 1102 characteristic->StartNotifySession( |
|
puthik_chromium
2016/07/28 22:40:31
The notifying session is always acquire here.
| |
| 1108 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, | 1103 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, |
| 1109 weak_factory_.GetWeakPtr(), callback, | 1104 weak_factory_.GetWeakPtr(), callback, |
| 1110 characteristic->GetIdentifier()), | 1105 characteristic->GetIdentifier()), |
| 1111 base::Bind(&OnGattOperationError, callback)); | 1106 base::Bind(&OnGattOperationError, callback)); |
| 1112 } | 1107 } |
| 1113 | 1108 |
| 1114 void ArcBluetoothBridge::DeregisterForGattNotification( | 1109 void ArcBluetoothBridge::DeregisterForGattNotification( |
| 1115 mojom::BluetoothAddressPtr remote_addr, | 1110 mojom::BluetoothAddressPtr remote_addr, |
| 1116 mojom::BluetoothGattServiceIDPtr service_id, | 1111 mojom::BluetoothGattServiceIDPtr service_id, |
| 1117 mojom::BluetoothGattIDPtr char_id, | 1112 mojom::BluetoothGattIDPtr char_id, |
| 1118 const DeregisterForGattNotificationCallback& callback) { | 1113 const DeregisterForGattNotificationCallback& callback) { |
| 1119 DCHECK(CalledOnValidThread()); | 1114 DCHECK(CalledOnValidThread()); |
| 1120 | 1115 |
| 1121 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( | 1116 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( |
| 1122 std::move(remote_addr), std::move(service_id), std::move(char_id)); | 1117 std::move(remote_addr), std::move(service_id), std::move(char_id)); |
| 1123 | 1118 |
| 1124 if (!characteristic) { | 1119 if (!characteristic) { |
| 1125 LOG(WARNING) << __func__ << " Characteristic is not existed."; | 1120 LOG(WARNING) << __func__ << " Characteristic is not existed."; |
| 1126 return; | 1121 return; |
| 1127 } | 1122 } |
| 1128 | 1123 |
| 1129 if (!characteristic->IsNotifying()) { | |
| 1130 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | |
| 1131 return; | |
| 1132 } | |
| 1133 | |
| 1134 std::string char_id_str = characteristic->GetIdentifier(); | 1124 std::string char_id_str = characteristic->GetIdentifier(); |
| 1125 | |
| 1126 if (!characteristic->IsNotifying()) { | |
|
ortuno
2016/07/28 22:56:00
IsNotifying() will always be true as long as there
puthik_chromium
2016/07/28 23:11:12
Since this is always true. Changed to DCHECK.
| |
| 1127 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); | |
| 1128 LOG(WARNING) << __func__ << ("Notification is stopped"); | |
|
ortuno
2016/07/28 22:21:06
I don't think this solves the problem. You are sti
puthik_chromium
2016/07/28 22:40:31
This is the Deregister function. I think delete th
ortuno
2016/07/28 22:56:00
Ah my bad. You are right.
| |
| 1129 if (notification_session_.find(char_id_str) != notification_session_.end()) | |
| 1130 notification_session_.erase(char_id_str); | |
| 1131 return; | |
| 1132 } | |
| 1133 | |
| 1135 std::unique_ptr<BluetoothGattNotifySession> notify = | 1134 std::unique_ptr<BluetoothGattNotifySession> notify = |
| 1136 std::move(notification_session_[char_id_str]); | 1135 std::move(notification_session_[char_id_str]); |
| 1137 notification_session_.erase(char_id_str); | 1136 notification_session_.erase(char_id_str); |
| 1138 notify->Stop(base::Bind(&OnGattOperationDone, callback)); | 1137 notify->Stop(base::Bind(&OnGattOperationDone, callback)); |
| 1139 } | 1138 } |
| 1140 | 1139 |
| 1141 void ArcBluetoothBridge::ReadRemoteRssi( | 1140 void ArcBluetoothBridge::ReadRemoteRssi( |
| 1142 mojom::BluetoothAddressPtr remote_addr, | 1141 mojom::BluetoothAddressPtr remote_addr, |
| 1143 const ReadRemoteRssiCallback& callback) { | 1142 const ReadRemoteRssiCallback& callback) { |
| 1144 BluetoothDevice* device = | 1143 BluetoothDevice* device = |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1651 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1653 << ") need version " << version_need; | 1652 << ") need version " << version_need; |
| 1654 return false; | 1653 return false; |
| 1655 } | 1654 } |
| 1656 | 1655 |
| 1657 bool ArcBluetoothBridge::CalledOnValidThread() { | 1656 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1658 return thread_checker_.CalledOnValidThread(); | 1657 return thread_checker_.CalledOnValidThread(); |
| 1659 } | 1658 } |
| 1660 | 1659 |
| 1661 } // namespace arc | 1660 } // namespace arc |
| OLD | NEW |