| 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 "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_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 26 matching lines...) Expand all Loading... |
| 37 descriptor->j_descriptor_.Reset( | 37 descriptor->j_descriptor_.Reset( |
| 38 Java_ChromeBluetoothRemoteGattDescriptor_create( | 38 Java_ChromeBluetoothRemoteGattDescriptor_create( |
| 39 AttachCurrentThread(), reinterpret_cast<intptr_t>(descriptor.get()), | 39 AttachCurrentThread(), reinterpret_cast<intptr_t>(descriptor.get()), |
| 40 bluetooth_gatt_descriptor_wrapper, chrome_bluetooth_device)); | 40 bluetooth_gatt_descriptor_wrapper, chrome_bluetooth_device)); |
| 41 | 41 |
| 42 return descriptor; | 42 return descriptor; |
| 43 } | 43 } |
| 44 | 44 |
| 45 BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() { | 45 BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() { |
| 46 Java_ChromeBluetoothRemoteGattDescriptor_onBluetoothRemoteGattDescriptorAndroi
dDestruction( | 46 Java_ChromeBluetoothRemoteGattDescriptor_onBluetoothRemoteGattDescriptorAndroi
dDestruction( |
| 47 AttachCurrentThread(), j_descriptor_.obj()); | 47 AttachCurrentThread(), j_descriptor_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 bool BluetoothRemoteGattDescriptorAndroid::RegisterJNI(JNIEnv* env) { | 51 bool BluetoothRemoteGattDescriptorAndroid::RegisterJNI(JNIEnv* env) { |
| 52 return RegisterNativesImpl( | 52 return RegisterNativesImpl( |
| 53 env); // Generated in ChromeBluetoothRemoteGattDescriptor_jni.h | 53 env); // Generated in ChromeBluetoothRemoteGattDescriptor_jni.h |
| 54 } | 54 } |
| 55 | 55 |
| 56 base::android::ScopedJavaLocalRef<jobject> | 56 base::android::ScopedJavaLocalRef<jobject> |
| 57 BluetoothRemoteGattDescriptorAndroid::GetJavaObject() { | 57 BluetoothRemoteGattDescriptorAndroid::GetJavaObject() { |
| 58 return base::android::ScopedJavaLocalRef<jobject>(j_descriptor_); | 58 return base::android::ScopedJavaLocalRef<jobject>(j_descriptor_); |
| 59 } | 59 } |
| 60 | 60 |
| 61 std::string BluetoothRemoteGattDescriptorAndroid::GetIdentifier() const { | 61 std::string BluetoothRemoteGattDescriptorAndroid::GetIdentifier() const { |
| 62 return instance_id_; | 62 return instance_id_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 BluetoothUUID BluetoothRemoteGattDescriptorAndroid::GetUUID() const { | 65 BluetoothUUID BluetoothRemoteGattDescriptorAndroid::GetUUID() const { |
| 66 return device::BluetoothUUID( | 66 return device::BluetoothUUID( |
| 67 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( | 67 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( |
| 68 AttachCurrentThread(), j_descriptor_.obj()))); | 68 AttachCurrentThread(), j_descriptor_))); |
| 69 } | 69 } |
| 70 | 70 |
| 71 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() | 71 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() |
| 72 const { | 72 const { |
| 73 return value_; | 73 return value_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 BluetoothRemoteGattCharacteristic* | 76 BluetoothRemoteGattCharacteristic* |
| 77 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { | 77 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { |
| 78 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 const ErrorCallback& error_callback) { | 90 const ErrorCallback& error_callback) { |
| 91 if (read_pending_ || write_pending_) { | 91 if (read_pending_ || write_pending_) { |
| 92 base::ThreadTaskRunnerHandle::Get()->PostTask( | 92 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 93 FROM_HERE, | 93 FROM_HERE, |
| 94 base::Bind(error_callback, | 94 base::Bind(error_callback, |
| 95 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); | 95 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (!Java_ChromeBluetoothRemoteGattDescriptor_readRemoteDescriptor( | 99 if (!Java_ChromeBluetoothRemoteGattDescriptor_readRemoteDescriptor( |
| 100 AttachCurrentThread(), j_descriptor_.obj())) { | 100 AttachCurrentThread(), j_descriptor_)) { |
| 101 base::ThreadTaskRunnerHandle::Get()->PostTask( | 101 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 102 FROM_HERE, | 102 FROM_HERE, |
| 103 base::Bind(error_callback, | 103 base::Bind(error_callback, |
| 104 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 104 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 read_pending_ = true; | 108 read_pending_ = true; |
| 109 read_callback_ = callback; | 109 read_callback_ = callback; |
| 110 read_error_callback_ = error_callback; | 110 read_error_callback_ = error_callback; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( | 113 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( |
| 114 const std::vector<uint8_t>& new_value, | 114 const std::vector<uint8_t>& new_value, |
| 115 const base::Closure& callback, | 115 const base::Closure& callback, |
| 116 const ErrorCallback& error_callback) { | 116 const ErrorCallback& error_callback) { |
| 117 if (read_pending_ || write_pending_) { | 117 if (read_pending_ || write_pending_) { |
| 118 base::ThreadTaskRunnerHandle::Get()->PostTask( | 118 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 119 FROM_HERE, | 119 FROM_HERE, |
| 120 base::Bind(error_callback, | 120 base::Bind(error_callback, |
| 121 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); | 121 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 | 124 |
| 125 JNIEnv* env = AttachCurrentThread(); | 125 JNIEnv* env = AttachCurrentThread(); |
| 126 if (!Java_ChromeBluetoothRemoteGattDescriptor_writeRemoteDescriptor( | 126 if (!Java_ChromeBluetoothRemoteGattDescriptor_writeRemoteDescriptor( |
| 127 env, j_descriptor_.obj(), | 127 env, j_descriptor_, base::android::ToJavaByteArray(env, new_value))) { |
| 128 base::android::ToJavaByteArray(env, new_value).obj())) { | |
| 129 base::ThreadTaskRunnerHandle::Get()->PostTask( | 128 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 130 FROM_HERE, | 129 FROM_HERE, |
| 131 base::Bind(error_callback, | 130 base::Bind(error_callback, |
| 132 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 131 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
| 133 return; | 132 return; |
| 134 } | 133 } |
| 135 | 134 |
| 136 write_pending_ = true; | 135 write_pending_ = true; |
| 137 write_callback_ = callback; | 136 write_callback_ = callback; |
| 138 write_error_callback_ = error_callback; | 137 write_error_callback_ = error_callback; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 write_error_callback.Run( | 181 write_error_callback.Run( |
| 183 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); | 182 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); |
| 184 } | 183 } |
| 185 } | 184 } |
| 186 | 185 |
| 187 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( | 186 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( |
| 188 const std::string& instance_id) | 187 const std::string& instance_id) |
| 189 : instance_id_(instance_id) {} | 188 : instance_id_(instance_id) {} |
| 190 | 189 |
| 191 } // namespace device | 190 } // namespace device |
| OLD | NEW |