| 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 "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_adapter_android.h" |
| 14 #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" | 15 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 17 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" | 17 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" |
| 18 | 18 |
| 19 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
| 20 | 20 |
| 21 namespace device { | 21 namespace device { |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> | 24 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> |
| 25 BluetoothRemoteGattCharacteristicAndroid::Create( | 25 BluetoothRemoteGattCharacteristicAndroid::Create( |
| 26 BluetoothAdapterAndroid* adapter, | 26 BluetoothAdapterAndroid* adapter, |
| 27 BluetoothRemoteGattServiceAndroid* service, |
| 27 const std::string& instance_id, | 28 const std::string& instance_id, |
| 28 jobject /* BluetoothGattCharacteristicWrapper */ | 29 jobject /* BluetoothGattCharacteristicWrapper */ |
| 29 bluetooth_gatt_characteristic_wrapper, | 30 bluetooth_gatt_characteristic_wrapper, |
| 30 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { | 31 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { |
| 31 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> characteristic( | 32 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> characteristic( |
| 32 new BluetoothRemoteGattCharacteristicAndroid(adapter, instance_id)); | 33 new BluetoothRemoteGattCharacteristicAndroid(adapter, service, |
| 34 instance_id)); |
| 33 | 35 |
| 34 JNIEnv* env = AttachCurrentThread(); | 36 JNIEnv* env = AttachCurrentThread(); |
| 35 characteristic->j_characteristic_.Reset( | 37 characteristic->j_characteristic_.Reset( |
| 36 Java_ChromeBluetoothRemoteGattCharacteristic_create( | 38 Java_ChromeBluetoothRemoteGattCharacteristic_create( |
| 37 env, reinterpret_cast<intptr_t>(characteristic.get()), | 39 env, reinterpret_cast<intptr_t>(characteristic.get()), |
| 38 bluetooth_gatt_characteristic_wrapper, | 40 bluetooth_gatt_characteristic_wrapper, |
| 39 base::android::ConvertUTF8ToJavaString(env, instance_id).obj(), | 41 base::android::ConvertUTF8ToJavaString(env, instance_id).obj(), |
| 40 chrome_bluetooth_device)); | 42 chrome_bluetooth_device)); |
| 41 | 43 |
| 42 return characteristic; | 44 return characteristic; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 73 return false; | 75 return false; |
| 74 } | 76 } |
| 75 | 77 |
| 76 const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicAndroid::GetValue() | 78 const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicAndroid::GetValue() |
| 77 const { | 79 const { |
| 78 return value_; | 80 return value_; |
| 79 } | 81 } |
| 80 | 82 |
| 81 BluetoothGattService* BluetoothRemoteGattCharacteristicAndroid::GetService() | 83 BluetoothGattService* BluetoothRemoteGattCharacteristicAndroid::GetService() |
| 82 const { | 84 const { |
| 83 NOTIMPLEMENTED(); | 85 return service_; |
| 84 return nullptr; | |
| 85 } | 86 } |
| 86 | 87 |
| 87 BluetoothGattCharacteristic::Properties | 88 BluetoothGattCharacteristic::Properties |
| 88 BluetoothRemoteGattCharacteristicAndroid::GetProperties() const { | 89 BluetoothRemoteGattCharacteristicAndroid::GetProperties() const { |
| 89 return Java_ChromeBluetoothRemoteGattCharacteristic_getProperties( | 90 return Java_ChromeBluetoothRemoteGattCharacteristic_getProperties( |
| 90 AttachCurrentThread(), j_characteristic_.obj()); | 91 AttachCurrentThread(), j_characteristic_.obj()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 BluetoothGattCharacteristic::Permissions | 94 BluetoothGattCharacteristic::Permissions |
| 94 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const { | 95 BluetoothRemoteGattCharacteristicAndroid::GetPermissions() const { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 260 |
| 260 DCHECK(!descriptors_.contains(instanceIdString)); | 261 DCHECK(!descriptors_.contains(instanceIdString)); |
| 261 | 262 |
| 262 descriptors_.set(instanceIdString, | 263 descriptors_.set(instanceIdString, |
| 263 BluetoothRemoteGattDescriptorAndroid::Create( | 264 BluetoothRemoteGattDescriptorAndroid::Create( |
| 264 instanceIdString, bluetooth_gatt_descriptor_wrapper, | 265 instanceIdString, bluetooth_gatt_descriptor_wrapper, |
| 265 chrome_bluetooth_device)); | 266 chrome_bluetooth_device)); |
| 266 } | 267 } |
| 267 | 268 |
| 268 BluetoothRemoteGattCharacteristicAndroid:: | 269 BluetoothRemoteGattCharacteristicAndroid:: |
| 269 BluetoothRemoteGattCharacteristicAndroid(BluetoothAdapterAndroid* adapter, | 270 BluetoothRemoteGattCharacteristicAndroid( |
| 270 const std::string& instance_id) | 271 BluetoothAdapterAndroid* adapter, |
| 271 : adapter_(adapter), instance_id_(instance_id) {} | 272 BluetoothRemoteGattServiceAndroid* service, |
| 273 const std::string& instance_id) |
| 274 : adapter_(adapter), service_(service), instance_id_(instance_id) {} |
| 272 | 275 |
| 273 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() | 276 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() |
| 274 const { | 277 const { |
| 275 if (!descriptors_.empty()) | 278 if (!descriptors_.empty()) |
| 276 return; | 279 return; |
| 277 | 280 |
| 278 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( | 281 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( |
| 279 AttachCurrentThread(), j_characteristic_.obj()); | 282 AttachCurrentThread(), j_characteristic_.obj()); |
| 280 } | 283 } |
| 281 | 284 |
| 282 } // namespace device | 285 } // namespace device |
| OLD | NEW |