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

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

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: Address Vincent's comments Created 4 years, 9 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 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue>
11
10 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
11 #include "base/containers/scoped_ptr_hash_map.h" 13 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 15 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
14 16
15 namespace device { 17 namespace device {
16 18
17 class BluetoothAdapterAndroid; 19 class BluetoothAdapterAndroid;
18 class BluetoothRemoteGattDescriptorAndroid; 20 class BluetoothRemoteGattDescriptorAndroid;
19 class BluetoothRemoteGattServiceAndroid; 21 class BluetoothRemoteGattServiceAndroid;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override; 68 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override;
67 bool UpdateValue(const std::vector<uint8_t>& value) override; 69 bool UpdateValue(const std::vector<uint8_t>& value) override;
68 void StartNotifySession(const NotifySessionCallback& callback, 70 void StartNotifySession(const NotifySessionCallback& callback,
69 const ErrorCallback& error_callback) override; 71 const ErrorCallback& error_callback) override;
70 void ReadRemoteCharacteristic(const ValueCallback& callback, 72 void ReadRemoteCharacteristic(const ValueCallback& callback,
71 const ErrorCallback& error_callback) override; 73 const ErrorCallback& error_callback) override;
72 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, 74 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value,
73 const base::Closure& callback, 75 const base::Closure& callback,
74 const ErrorCallback& error_callback) override; 76 const ErrorCallback& error_callback) override;
75 77
78 // Called when StartNotifySession operation succeeds.
79 void OnStartNotifySessionSuccess();
80
81 // Called when StartNotifySession operation fails.
82 void OnStartNotifySessionError(BluetoothGattService::GattErrorCode error);
83
76 // Called when value changed event occurs. 84 // Called when value changed event occurs.
77 void OnChanged(JNIEnv* env, 85 void OnChanged(JNIEnv* env,
78 const base::android::JavaParamRef<jobject>& jcaller, 86 const base::android::JavaParamRef<jobject>& jcaller,
79 const base::android::JavaParamRef<jbyteArray>& value); 87 const base::android::JavaParamRef<jbyteArray>& value);
80 88
81 // Callback after Read operation completes. 89 // Called when Read operation completes.
82 void OnRead(JNIEnv* env, 90 void OnRead(JNIEnv* env,
83 const base::android::JavaParamRef<jobject>& jcaller, 91 const base::android::JavaParamRef<jobject>& jcaller,
84 int32_t status, 92 int32_t status,
85 const base::android::JavaParamRef<jbyteArray>& value); 93 const base::android::JavaParamRef<jbyteArray>& value);
86 94
87 // Callback after Write operation completes. 95 // Called when Write operation completes.
88 void OnWrite(JNIEnv* env, 96 void OnWrite(JNIEnv* env,
89 const base::android::JavaParamRef<jobject>& jcaller, 97 const base::android::JavaParamRef<jobject>& jcaller,
90 int32_t status); 98 int32_t status);
91 99
92 // Creates a Bluetooth GATT descriptor object and adds it to |descriptors_|, 100 // Creates a Bluetooth GATT descriptor object and adds it to |descriptors_|,
93 // DCHECKing that it has not already been created. 101 // DCHECKing that it has not already been created.
94 void CreateGattRemoteDescriptor( 102 void CreateGattRemoteDescriptor(
95 JNIEnv* env, 103 JNIEnv* env,
96 const base::android::JavaParamRef<jobject>& caller, 104 const base::android::JavaParamRef<jobject>& caller,
97 const base::android::JavaParamRef<jstring>& instanceId, 105 const base::android::JavaParamRef<jstring>& instanceId,
(...skipping 18 matching lines...) Expand all
116 BluetoothAdapterAndroid* adapter_; 124 BluetoothAdapterAndroid* adapter_;
117 BluetoothRemoteGattServiceAndroid* service_; 125 BluetoothRemoteGattServiceAndroid* service_;
118 126
119 // Java object 127 // Java object
120 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic. 128 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic.
121 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_; 129 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_;
122 130
123 // Adapter unique instance ID. 131 // Adapter unique instance ID.
124 std::string instance_id_; 132 std::string instance_id_;
125 133
134 // StartNotifySession callbacks and pending state.
135 typedef std::pair<NotifySessionCallback, ErrorCallback>
136 PendingStartNotifyCall;
137 std::queue<PendingStartNotifyCall> pending_start_notify_calls_;
138
126 // ReadRemoteCharacteristic callbacks and pending state. 139 // ReadRemoteCharacteristic callbacks and pending state.
127 bool read_pending_ = false; 140 bool read_pending_ = false;
128 ValueCallback read_callback_; 141 ValueCallback read_callback_;
129 ErrorCallback read_error_callback_; 142 ErrorCallback read_error_callback_;
130 143
131 // WriteRemoteCharacteristic callbacks and pending state. 144 // WriteRemoteCharacteristic callbacks and pending state.
132 bool write_pending_ = false; 145 bool write_pending_ = false;
133 base::Closure write_callback_; 146 base::Closure write_callback_;
134 ErrorCallback write_error_callback_; 147 ErrorCallback write_error_callback_;
135 148
136 std::vector<uint8_t> value_; 149 std::vector<uint8_t> value_;
137 150
138 // Map of descriptors, keyed by descriptor identifier. 151 // Map of descriptors, keyed by descriptor identifier.
139 base::ScopedPtrHashMap<std::string, 152 base::ScopedPtrHashMap<std::string,
140 scoped_ptr<BluetoothRemoteGattDescriptorAndroid>> 153 scoped_ptr<BluetoothRemoteGattDescriptorAndroid>>
141 descriptors_; 154 descriptors_;
142 155
143 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); 156 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid);
144 }; 157 };
145 158
146 } // namespace device 159 } // namespace device
147 160
148 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ 161 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698