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" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 FROM_HERE, | 137 FROM_HERE, |
138 base::Bind(error_callback, | 138 base::Bind(error_callback, |
139 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 139 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( | 143 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( |
144 const ValueCallback& callback, | 144 const ValueCallback& callback, |
145 const ErrorCallback& error_callback) { | 145 const ErrorCallback& error_callback) { |
146 if (read_pending_ || write_pending_) { | 146 if (read_pending_ || write_pending_) { |
147 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS); | 147 base::MessageLoop::current()->PostTask( |
| 148 FROM_HERE, base::Bind(error_callback, |
| 149 BluetoothGattService::GATT_ERROR_IN_PROGRESS)); |
| 150 return; |
148 } | 151 } |
149 | 152 |
150 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic( | 153 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic( |
151 AttachCurrentThread(), j_characteristic_.obj())) { | 154 AttachCurrentThread(), j_characteristic_.obj())) { |
152 base::MessageLoop::current()->PostTask( | 155 base::MessageLoop::current()->PostTask( |
153 FROM_HERE, | 156 FROM_HERE, |
154 base::Bind(error_callback, | 157 base::Bind(error_callback, |
155 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 158 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
156 return; | 159 return; |
157 } | 160 } |
158 | 161 |
159 read_pending_ = true; | 162 read_pending_ = true; |
160 read_callback_ = callback; | 163 read_callback_ = callback; |
161 read_error_callback_ = error_callback; | 164 read_error_callback_ = error_callback; |
162 } | 165 } |
163 | 166 |
164 void BluetoothRemoteGattCharacteristicAndroid::WriteRemoteCharacteristic( | 167 void BluetoothRemoteGattCharacteristicAndroid::WriteRemoteCharacteristic( |
165 const std::vector<uint8>& new_value, | 168 const std::vector<uint8>& new_value, |
166 const base::Closure& callback, | 169 const base::Closure& callback, |
167 const ErrorCallback& error_callback) { | 170 const ErrorCallback& error_callback) { |
168 if (read_pending_ || write_pending_) { | 171 if (read_pending_ || write_pending_) { |
169 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS); | 172 base::MessageLoop::current()->PostTask( |
| 173 FROM_HERE, base::Bind(error_callback, |
| 174 BluetoothGattService::GATT_ERROR_IN_PROGRESS)); |
| 175 return; |
170 } | 176 } |
171 | 177 |
172 JNIEnv* env = AttachCurrentThread(); | 178 JNIEnv* env = AttachCurrentThread(); |
173 if (!Java_ChromeBluetoothRemoteGattCharacteristic_writeRemoteCharacteristic( | 179 if (!Java_ChromeBluetoothRemoteGattCharacteristic_writeRemoteCharacteristic( |
174 env, j_characteristic_.obj(), | 180 env, j_characteristic_.obj(), |
175 base::android::ToJavaByteArray(env, new_value).obj())) { | 181 base::android::ToJavaByteArray(env, new_value).obj())) { |
176 base::MessageLoop::current()->PostTask( | 182 base::MessageLoop::current()->PostTask( |
177 FROM_HERE, | 183 FROM_HERE, |
178 base::Bind(error_callback, | 184 base::Bind(error_callback, |
179 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 185 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 write_error_callback.Run( | 231 write_error_callback.Run( |
226 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); | 232 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); |
227 } | 233 } |
228 } | 234 } |
229 | 235 |
230 BluetoothRemoteGattCharacteristicAndroid:: | 236 BluetoothRemoteGattCharacteristicAndroid:: |
231 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId) | 237 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId) |
232 : instance_id_(instanceId) {} | 238 : instance_id_(instanceId) {} |
233 | 239 |
234 } // namespace device | 240 } // namespace device |
OLD | NEW |