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 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const { | 106 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const { |
107 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
108 return 0; | 108 return 0; |
109 } | 109 } |
110 | 110 |
111 std::vector<BluetoothRemoteGattDescriptor*> | 111 std::vector<BluetoothRemoteGattDescriptor*> |
112 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const { | 112 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const { |
113 EnsureDescriptorsCreated(); | 113 EnsureDescriptorsCreated(); |
114 std::vector<BluetoothRemoteGattDescriptor*> descriptors; | 114 std::vector<BluetoothRemoteGattDescriptor*> descriptors; |
115 for (const auto& map_iter : descriptors_) | 115 for (const auto& map_iter : descriptors_) |
116 descriptors.push_back(map_iter.second); | 116 descriptors.push_back(map_iter.second.get()); |
117 return descriptors; | 117 return descriptors; |
118 } | 118 } |
119 | 119 |
120 BluetoothRemoteGattDescriptor* | 120 BluetoothRemoteGattDescriptor* |
121 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor( | 121 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor( |
122 const std::string& identifier) const { | 122 const std::string& identifier) const { |
123 EnsureDescriptorsCreated(); | 123 EnsureDescriptorsCreated(); |
124 const auto& iter = descriptors_.find(identifier); | 124 const auto& iter = descriptors_.find(identifier); |
125 if (iter == descriptors_.end()) | 125 if (iter == descriptors_.end()) |
126 return nullptr; | 126 return nullptr; |
127 return iter->second; | 127 return iter->second.get(); |
128 } | 128 } |
129 | 129 |
130 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( | 130 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( |
131 const ValueCallback& callback, | 131 const ValueCallback& callback, |
132 const ErrorCallback& error_callback) { | 132 const ErrorCallback& error_callback) { |
133 if (read_pending_ || write_pending_) { | 133 if (read_pending_ || write_pending_) { |
134 base::ThreadTaskRunnerHandle::Get()->PostTask( | 134 base::ThreadTaskRunnerHandle::Get()->PostTask( |
135 FROM_HERE, | 135 FROM_HERE, |
136 base::Bind(error_callback, | 136 base::Bind(error_callback, |
137 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); | 137 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( | 233 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( |
234 JNIEnv* env, | 234 JNIEnv* env, |
235 const JavaParamRef<jobject>& caller, | 235 const JavaParamRef<jobject>& caller, |
236 const JavaParamRef<jstring>& instanceId, | 236 const JavaParamRef<jstring>& instanceId, |
237 const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */ | 237 const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */ |
238 bluetooth_gatt_descriptor_wrapper, | 238 bluetooth_gatt_descriptor_wrapper, |
239 const JavaParamRef<jobject>& /* ChromeBluetoothDevice */ | 239 const JavaParamRef<jobject>& /* ChromeBluetoothDevice */ |
240 chrome_bluetooth_device) { | 240 chrome_bluetooth_device) { |
241 std::string instanceIdString = | 241 std::string instanceIdString = |
242 base::android::ConvertJavaStringToUTF8(env, instanceId); | 242 base::android::ConvertJavaStringToUTF8(env, instanceId); |
| 243 DCHECK(!base::ContainsKey(descriptors_, instanceIdString)); |
| 244 auto descriptor = BluetoothRemoteGattDescriptorAndroid::Create( |
| 245 instanceIdString, bluetooth_gatt_descriptor_wrapper, |
| 246 chrome_bluetooth_device); |
243 | 247 |
244 DCHECK(!descriptors_.contains(instanceIdString)); | 248 descriptors_.insert(std::make_pair(instanceIdString, std::move(descriptor))); |
245 | |
246 descriptors_.set(instanceIdString, | |
247 BluetoothRemoteGattDescriptorAndroid::Create( | |
248 instanceIdString, bluetooth_gatt_descriptor_wrapper, | |
249 chrome_bluetooth_device)); | |
250 } | 249 } |
251 | 250 |
252 void BluetoothRemoteGattCharacteristicAndroid::SubscribeToNotifications( | 251 void BluetoothRemoteGattCharacteristicAndroid::SubscribeToNotifications( |
253 BluetoothRemoteGattDescriptor* ccc_descriptor, | 252 BluetoothRemoteGattDescriptor* ccc_descriptor, |
254 const base::Closure& callback, | 253 const base::Closure& callback, |
255 const ErrorCallback& error_callback) { | 254 const ErrorCallback& error_callback) { |
256 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio
n( | 255 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio
n( |
257 AttachCurrentThread(), j_characteristic_, true)) { | 256 AttachCurrentThread(), j_characteristic_, true)) { |
258 LOG(ERROR) << "Error enabling characteristic notification"; | 257 LOG(ERROR) << "Error enabling characteristic notification"; |
259 base::ThreadTaskRunnerHandle::Get()->PostTask( | 258 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() | 298 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() |
300 const { | 299 const { |
301 if (!descriptors_.empty()) | 300 if (!descriptors_.empty()) |
302 return; | 301 return; |
303 | 302 |
304 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( | 303 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( |
305 AttachCurrentThread(), j_characteristic_); | 304 AttachCurrentThread(), j_characteristic_); |
306 } | 305 } |
307 | 306 |
308 } // namespace device | 307 } // namespace device |
OLD | NEW |