Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc

Issue 1574773002: bluetooth: android: Initial basic Descriptors implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-code-cleanup-
Patch Set: addressed j again Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "device/bluetooth/bluetooth_adapter_android.h"
13 #include "device/bluetooth/bluetooth_gatt_notify_session_android.h" 14 #include "device/bluetooth/bluetooth_gatt_notify_session_android.h"
15 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h"
14 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" 16 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h"
15 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" 17 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h"
16 18
17 using base::android::AttachCurrentThread; 19 using base::android::AttachCurrentThread;
18 20
19 namespace device { 21 namespace device {
20 22
21 // static 23 // static
22 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> 24 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid>
23 BluetoothRemoteGattCharacteristicAndroid::Create( 25 BluetoothRemoteGattCharacteristicAndroid::Create(
26 BluetoothAdapterAndroid* adapter,
24 const std::string& instance_id, 27 const std::string& instance_id,
25 jobject /* BluetoothGattCharacteristicWrapper */ 28 jobject /* BluetoothGattCharacteristicWrapper */
26 bluetooth_gatt_characteristic_wrapper, 29 bluetooth_gatt_characteristic_wrapper,
27 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { 30 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) {
28 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> characteristic( 31 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> characteristic(
29 new BluetoothRemoteGattCharacteristicAndroid(instance_id)); 32 new BluetoothRemoteGattCharacteristicAndroid(adapter, instance_id));
30 33
34 JNIEnv* env = AttachCurrentThread();
31 characteristic->j_characteristic_.Reset( 35 characteristic->j_characteristic_.Reset(
32 Java_ChromeBluetoothRemoteGattCharacteristic_create( 36 Java_ChromeBluetoothRemoteGattCharacteristic_create(
33 AttachCurrentThread(), 37 env, reinterpret_cast<intptr_t>(characteristic.get()),
34 reinterpret_cast<intptr_t>(characteristic.get()), 38 bluetooth_gatt_characteristic_wrapper,
35 bluetooth_gatt_characteristic_wrapper, chrome_bluetooth_device)); 39 base::android::ConvertUTF8ToJavaString(env, instance_id).obj(),
40 chrome_bluetooth_device));
36 41
37 return characteristic; 42 return characteristic;
38 } 43 }
39 44
40 BluetoothRemoteGattCharacteristicAndroid:: 45 BluetoothRemoteGattCharacteristicAndroid::
41 ~BluetoothRemoteGattCharacteristicAndroid() { 46 ~BluetoothRemoteGattCharacteristicAndroid() {
42 Java_ChromeBluetoothRemoteGattCharacteristic_onBluetoothRemoteGattCharacterist icAndroidDestruction( 47 Java_ChromeBluetoothRemoteGattCharacteristic_onBluetoothRemoteGattCharacterist icAndroidDestruction(
43 AttachCurrentThread(), j_characteristic_.obj()); 48 AttachCurrentThread(), j_characteristic_.obj());
44 } 49 }
45 50
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return 0; 96 return 0;
92 } 97 }
93 98
94 bool BluetoothRemoteGattCharacteristicAndroid::IsNotifying() const { 99 bool BluetoothRemoteGattCharacteristicAndroid::IsNotifying() const {
95 NOTIMPLEMENTED(); 100 NOTIMPLEMENTED();
96 return false; 101 return false;
97 } 102 }
98 103
99 std::vector<BluetoothGattDescriptor*> 104 std::vector<BluetoothGattDescriptor*>
100 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const { 105 BluetoothRemoteGattCharacteristicAndroid::GetDescriptors() const {
101 NOTIMPLEMENTED(); 106 EnsureDescriptorsCreated();
102 return std::vector<BluetoothGattDescriptor*>(); 107 std::vector<BluetoothGattDescriptor*> descriptors;
108 for (const auto& map_iter : descriptors_)
109 descriptors.push_back(map_iter.second);
110 return descriptors;
103 } 111 }
104 112
105 BluetoothGattDescriptor* 113 BluetoothGattDescriptor*
106 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor( 114 BluetoothRemoteGattCharacteristicAndroid::GetDescriptor(
107 const std::string& identifier) const { 115 const std::string& identifier) const {
108 NOTIMPLEMENTED(); 116 EnsureDescriptorsCreated();
109 return nullptr; 117 const auto& iter = descriptors_.find(identifier);
118 if (iter == descriptors_.end())
119 return nullptr;
120 return iter->second;
110 } 121 }
111 122
112 bool BluetoothRemoteGattCharacteristicAndroid::AddDescriptor( 123 bool BluetoothRemoteGattCharacteristicAndroid::AddDescriptor(
113 BluetoothGattDescriptor* descriptor) { 124 BluetoothGattDescriptor* descriptor) {
114 NOTIMPLEMENTED(); 125 NOTIMPLEMENTED();
115 return false; 126 return false;
116 } 127 }
117 128
118 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue( 129 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue(
119 const std::vector<uint8_t>& value) { 130 const std::vector<uint8_t>& value) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 239
229 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS 240 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS
230 && !write_callback.is_null()) { 241 && !write_callback.is_null()) {
231 write_callback.Run(); 242 write_callback.Run();
232 } else if (!write_error_callback.is_null()) { 243 } else if (!write_error_callback.is_null()) {
233 write_error_callback.Run( 244 write_error_callback.Run(
234 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); 245 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
235 } 246 }
236 } 247 }
237 248
249 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor(
250 JNIEnv* env,
251 const JavaParamRef<jobject>& caller,
252 const JavaParamRef<jstring>& instanceId,
253 const JavaParamRef<jobject>& /* BluetoothGattDescriptorWrapper */
254 bluetooth_gatt_descriptor_wrapper,
255 const JavaParamRef<jobject>& /* ChromeBluetoothDevice */
256 chrome_bluetooth_device) {
257 std::string instanceIdString =
258 base::android::ConvertJavaStringToUTF8(env, instanceId);
259
260 DCHECK(!descriptors_.contains(instanceIdString));
261
262 descriptors_.set(instanceIdString,
263 BluetoothRemoteGattDescriptorAndroid::Create(
264 instanceIdString, bluetooth_gatt_descriptor_wrapper,
265 chrome_bluetooth_device));
266 }
267
238 BluetoothRemoteGattCharacteristicAndroid:: 268 BluetoothRemoteGattCharacteristicAndroid::
239 BluetoothRemoteGattCharacteristicAndroid(const std::string& instance_id) 269 BluetoothRemoteGattCharacteristicAndroid(BluetoothAdapterAndroid* adapter,
240 : instance_id_(instance_id) {} 270 const std::string& instance_id)
271 : adapter_(adapter), instance_id_(instance_id) {}
272
273 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated()
274 const {
275 if (!descriptors_.empty())
276 return;
277
278 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors(
279 AttachCurrentThread(), j_characteristic_.obj());
280 }
241 281
242 } // namespace device 282 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698