Chromium Code Reviews| 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_gatt_notify_session_android.h" | |
| 13 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 14 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" | 15 #include "jni/ChromeBluetoothRemoteGattCharacteristic_jni.h" |
| 15 | 16 |
| 16 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 17 | 18 |
| 18 namespace device { | 19 namespace device { |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> | 22 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> |
| 22 BluetoothRemoteGattCharacteristicAndroid::Create( | 23 BluetoothRemoteGattCharacteristicAndroid::Create( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 47 return RegisterNativesImpl( | 48 return RegisterNativesImpl( |
| 48 env); // Generated in ChromeBluetoothRemoteGattCharacteristic_jni.h | 49 env); // Generated in ChromeBluetoothRemoteGattCharacteristic_jni.h |
| 49 } | 50 } |
| 50 | 51 |
| 51 base::android::ScopedJavaLocalRef<jobject> | 52 base::android::ScopedJavaLocalRef<jobject> |
| 52 BluetoothRemoteGattCharacteristicAndroid::GetJavaObject() { | 53 BluetoothRemoteGattCharacteristicAndroid::GetJavaObject() { |
| 53 return base::android::ScopedJavaLocalRef<jobject>(j_characteristic_); | 54 return base::android::ScopedJavaLocalRef<jobject>(j_characteristic_); |
| 54 } | 55 } |
| 55 | 56 |
| 56 std::string BluetoothRemoteGattCharacteristicAndroid::GetIdentifier() const { | 57 std::string BluetoothRemoteGattCharacteristicAndroid::GetIdentifier() const { |
| 57 return instanceId_; | 58 return instance_id_; |
| 58 } | 59 } |
| 59 | 60 |
| 60 BluetoothUUID BluetoothRemoteGattCharacteristicAndroid::GetUUID() const { | 61 BluetoothUUID BluetoothRemoteGattCharacteristicAndroid::GetUUID() const { |
| 61 return device::BluetoothUUID(ConvertJavaStringToUTF8( | 62 return device::BluetoothUUID(ConvertJavaStringToUTF8( |
| 62 Java_ChromeBluetoothRemoteGattCharacteristic_getUUID( | 63 Java_ChromeBluetoothRemoteGattCharacteristic_getUUID( |
| 63 AttachCurrentThread(), j_characteristic_.obj()))); | 64 AttachCurrentThread(), j_characteristic_.obj()))); |
| 64 } | 65 } |
| 65 | 66 |
| 66 bool BluetoothRemoteGattCharacteristicAndroid::IsLocal() const { | 67 bool BluetoothRemoteGattCharacteristicAndroid::IsLocal() const { |
| 67 return false; | 68 return false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 117 |
| 117 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue( | 118 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue( |
| 118 const std::vector<uint8>& value) { | 119 const std::vector<uint8>& value) { |
| 119 NOTIMPLEMENTED(); | 120 NOTIMPLEMENTED(); |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| 123 void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession( | 124 void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession( |
| 124 const NotifySessionCallback& callback, | 125 const NotifySessionCallback& callback, |
| 125 const ErrorCallback& error_callback) { | 126 const ErrorCallback& error_callback) { |
| 126 NOTIMPLEMENTED(); | 127 if (Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession( |
|
ortuno
2015/11/06 02:30:06
Should we check the characteristic's properties be
scheib
2015/11/06 02:56:57
Done.
| |
| 128 AttachCurrentThread(), j_characteristic_.obj())) { | |
| 129 scoped_ptr<device::BluetoothGattNotifySession> notify_session( | |
| 130 new BluetoothGattNotifySessionAndroid(instance_id_)); | |
| 131 base::MessageLoop::current()->PostTask( | |
| 132 FROM_HERE, base::Bind(callback, base::Passed(¬ify_session))); | |
|
ortuno
2015/11/06 02:30:06
nit: I don't think you need the '&'. Passed takes
scheib
2015/11/06 02:56:57
Options are:
base::Passed(&thing)
base::Passed(thi
| |
| 133 } else { | |
|
ortuno
2015/11/06 02:30:06
nit: you can save yourself some indentation if you
scheib
2015/11/06 02:56:57
/shrug/ I sort of prefer the if __ else __ symmetr
| |
| 134 base::MessageLoop::current()->PostTask( | |
| 135 FROM_HERE, | |
| 136 base::Bind(error_callback, | |
| 137 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | |
| 138 } | |
| 127 } | 139 } |
| 128 | 140 |
| 129 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( | 141 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( |
| 130 const ValueCallback& callback, | 142 const ValueCallback& callback, |
| 131 const ErrorCallback& error_callback) { | 143 const ErrorCallback& error_callback) { |
| 132 if (read_pending_ || write_pending_) { | 144 if (read_pending_ || write_pending_) { |
| 133 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS); | 145 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS); |
| 134 } | 146 } |
| 135 | 147 |
| 136 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic( | 148 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 && !write_callback.is_null()) { | 220 && !write_callback.is_null()) { |
| 209 write_callback.Run(); | 221 write_callback.Run(); |
| 210 } else if (!write_error_callback.is_null()) { | 222 } else if (!write_error_callback.is_null()) { |
| 211 write_error_callback.Run( | 223 write_error_callback.Run( |
| 212 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); | 224 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); |
| 213 } | 225 } |
| 214 } | 226 } |
| 215 | 227 |
| 216 BluetoothRemoteGattCharacteristicAndroid:: | 228 BluetoothRemoteGattCharacteristicAndroid:: |
| 217 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId) | 229 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId) |
| 218 : instanceId_(instanceId) {} | 230 : instance_id_(instanceId) {} |
| 219 | 231 |
| 220 } // namespace device | 232 } // namespace device |
| OLD | NEW |