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

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

Issue 1712593002: bluetooth: android: Confirm the notify session after the descriptor has been written. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added the comment that Gio requested Created 4 years, 10 months 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 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 "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 13 matching lines...) Expand all
24 const std::string& instance_id, 24 const std::string& instance_id,
25 jobject /* BluetoothGattDescriptorWrapper */ 25 jobject /* BluetoothGattDescriptorWrapper */
26 bluetooth_gatt_descriptor_wrapper, 26 bluetooth_gatt_descriptor_wrapper,
27 jobject /* chromeBluetoothDevice */ 27 jobject /* chromeBluetoothDevice */
28 chrome_bluetooth_device) { 28 chrome_bluetooth_device) {
29 scoped_ptr<BluetoothRemoteGattDescriptorAndroid> descriptor( 29 scoped_ptr<BluetoothRemoteGattDescriptorAndroid> descriptor(
30 new BluetoothRemoteGattDescriptorAndroid(instance_id)); 30 new BluetoothRemoteGattDescriptorAndroid(instance_id));
31 31
32 descriptor->j_descriptor_.Reset( 32 descriptor->j_descriptor_.Reset(
33 Java_ChromeBluetoothRemoteGattDescriptor_create( 33 Java_ChromeBluetoothRemoteGattDescriptor_create(
34 AttachCurrentThread(), 34 AttachCurrentThread(), reinterpret_cast<intptr_t>(descriptor.get()),
35 // TODO(scheib) Will eventually need to pass c++ pointer:
36 // reinterpret_cast<intptr_t>(descriptor.get()),
37 bluetooth_gatt_descriptor_wrapper, chrome_bluetooth_device)); 35 bluetooth_gatt_descriptor_wrapper, chrome_bluetooth_device));
38 36
39 return descriptor; 37 return descriptor;
40 } 38 }
41 39
42 BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() { 40 BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() {
43 Java_ChromeBluetoothRemoteGattDescriptor_onBluetoothRemoteGattDescriptorAndroi dDestruction( 41 Java_ChromeBluetoothRemoteGattDescriptor_onBluetoothRemoteGattDescriptorAndroi dDestruction(
44 AttachCurrentThread(), j_descriptor_.obj()); 42 AttachCurrentThread(), j_descriptor_.obj());
45 } 43 }
46 44
(...skipping 17 matching lines...) Expand all
64 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( 62 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID(
65 AttachCurrentThread(), j_descriptor_.obj()))); 63 AttachCurrentThread(), j_descriptor_.obj())));
66 } 64 }
67 65
68 bool BluetoothRemoteGattDescriptorAndroid::IsLocal() const { 66 bool BluetoothRemoteGattDescriptorAndroid::IsLocal() const {
69 return false; 67 return false;
70 } 68 }
71 69
72 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() 70 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue()
73 const { 71 const {
74 NOTIMPLEMENTED(); 72 return value_;
75 static std::vector<uint8_t> empty_value;
76 return empty_value;
77 } 73 }
78 74
79 BluetoothGattCharacteristic* 75 BluetoothGattCharacteristic*
80 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { 76 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const {
81 NOTIMPLEMENTED(); 77 NOTIMPLEMENTED();
82 return nullptr; 78 return nullptr;
83 } 79 }
84 80
85 BluetoothGattCharacteristic::Permissions 81 BluetoothGattCharacteristic::Permissions
86 BluetoothRemoteGattDescriptorAndroid::GetPermissions() const { 82 BluetoothRemoteGattDescriptorAndroid::GetPermissions() const {
87 NOTIMPLEMENTED(); 83 NOTIMPLEMENTED();
88 return 0; 84 return 0;
89 } 85 }
90 86
91 void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor( 87 void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor(
92 const ValueCallback& callback, 88 const ValueCallback& callback,
93 const ErrorCallback& error_callback) { 89 const ErrorCallback& error_callback) {
94 NOTIMPLEMENTED(); 90 if (read_pending_ || write_pending_) {
95 base::MessageLoop::current()->PostTask( 91 base::MessageLoop::current()->PostTask(
96 FROM_HERE, 92 FROM_HERE, base::Bind(error_callback,
97 base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED)); 93 BluetoothGattService::GATT_ERROR_IN_PROGRESS));
94 return;
95 }
96
97 if (!Java_ChromeBluetoothRemoteGattDescriptor_readRemoteDescriptor(
98 AttachCurrentThread(), j_descriptor_.obj())) {
99 base::MessageLoop::current()->PostTask(
100 FROM_HERE,
101 base::Bind(error_callback,
102 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
103 return;
104 }
105
106 read_pending_ = true;
107 read_callback_ = callback;
108 read_error_callback_ = error_callback;
98 } 109 }
99 110
100 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( 111 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor(
101 const std::vector<uint8_t>& new_value, 112 const std::vector<uint8_t>& new_value,
102 const base::Closure& callback, 113 const base::Closure& callback,
103 const ErrorCallback& error_callback) { 114 const ErrorCallback& error_callback) {
104 NOTIMPLEMENTED(); 115 if (read_pending_ || write_pending_) {
105 base::MessageLoop::current()->PostTask( 116 base::MessageLoop::current()->PostTask(
106 FROM_HERE, 117 FROM_HERE, base::Bind(error_callback,
107 base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED)); 118 BluetoothGattService::GATT_ERROR_IN_PROGRESS));
119 return;
120 }
121
122 JNIEnv* env = AttachCurrentThread();
123 if (!Java_ChromeBluetoothRemoteGattDescriptor_writeRemoteDescriptor(
124 env, j_descriptor_.obj(),
125 base::android::ToJavaByteArray(env, new_value).obj())) {
126 base::MessageLoop::current()->PostTask(
127 FROM_HERE,
128 base::Bind(error_callback,
129 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
130 return;
131 }
132
133 write_pending_ = true;
134 write_callback_ = callback;
135 write_error_callback_ = error_callback;
136 }
137
138 void BluetoothRemoteGattDescriptorAndroid::OnRead(
139 JNIEnv* env,
140 const JavaParamRef<jobject>& jcaller,
141 int32_t status,
142 const JavaParamRef<jbyteArray>& value) {
143 read_pending_ = false;
144
145 // Clear callbacks before calling to avoid reentrancy issues.
146 ValueCallback read_callback = read_callback_;
147 ErrorCallback read_error_callback = read_error_callback_;
148 read_callback_.Reset();
149 read_error_callback_.Reset();
150
151 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS
152 && !read_callback.is_null()) {
153 base::android::JavaByteArrayToByteVector(env, value, &value_);
154 read_callback.Run(value_);
155 // TODO(https://crbug.com/545682): Call GattDescriptorValueChanged.
scheib 2016/02/26 04:27:01 update to descriptor bug 584369
tommyt 2016/03/01 14:45:15 Done.
156 } else if (!read_error_callback.is_null()) {
157 read_error_callback.Run(
158 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
159 }
160 }
161
162 void BluetoothRemoteGattDescriptorAndroid::OnWrite(
163 JNIEnv* env,
164 const JavaParamRef<jobject>& jcaller,
165 int32_t status) {
166 write_pending_ = false;
167
168 // Clear callbacks before calling to avoid reentrancy issues.
169 base::Closure write_callback = write_callback_;
170 ErrorCallback write_error_callback = write_error_callback_;
171 write_callback_.Reset();
172 write_error_callback_.Reset();
173
174 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS
175 && !write_callback.is_null()) {
176 write_callback.Run();
177 // TODO(https://crbug.com/545682): Call GattDescriptorValueChanged.
scheib 2016/02/26 04:27:01 update to descriptor bug 584369
tommyt 2016/03/01 14:45:15 Done.
178 } else if (!write_error_callback.is_null()) {
179 write_error_callback.Run(
180 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
181 }
108 } 182 }
109 183
110 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( 184 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid(
111 const std::string& instance_id) 185 const std::string& instance_id)
112 : instance_id_(instance_id) {} 186 : instance_id_(instance_id) {}
113 187
114 } // namespace device 188 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698