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

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

Issue 1422463012: bluetooth: android: Implement StartNotifySession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed ortuno Created 5 years, 1 month 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_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
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
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 // TODO(crbug.com/551634): Check characteristic properties and return a better
128 // error code if notifications aren't permitted.
129 if (Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession(
130 AttachCurrentThread(), j_characteristic_.obj())) {
131 scoped_ptr<device::BluetoothGattNotifySession> notify_session(
132 new BluetoothGattNotifySessionAndroid(instance_id_));
133 base::MessageLoop::current()->PostTask(
134 FROM_HERE, base::Bind(callback, base::Passed(&notify_session)));
135 } else {
136 base::MessageLoop::current()->PostTask(
137 FROM_HERE,
138 base::Bind(error_callback,
139 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
140 }
127 } 141 }
128 142
129 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( 143 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic(
130 const ValueCallback& callback, 144 const ValueCallback& callback,
131 const ErrorCallback& error_callback) { 145 const ErrorCallback& error_callback) {
132 if (read_pending_ || write_pending_) { 146 if (read_pending_ || write_pending_) {
133 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS); 147 error_callback.Run(BluetoothGattService::GATT_ERROR_IN_PROGRESS);
134 } 148 }
135 149
136 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic( 150 if (!Java_ChromeBluetoothRemoteGattCharacteristic_readRemoteCharacteristic(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 && !write_callback.is_null()) { 222 && !write_callback.is_null()) {
209 write_callback.Run(); 223 write_callback.Run();
210 } else if (!write_error_callback.is_null()) { 224 } else if (!write_error_callback.is_null()) {
211 write_error_callback.Run( 225 write_error_callback.Run(
212 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); 226 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
213 } 227 }
214 } 228 }
215 229
216 BluetoothRemoteGattCharacteristicAndroid:: 230 BluetoothRemoteGattCharacteristicAndroid::
217 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId) 231 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId)
218 : instanceId_(instanceId) {} 232 : instance_id_(instanceId) {}
219 233
220 } // namespace device 234 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698