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

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

Issue 2051333004: Implement BluetoothGattNotifySession::Stop on Android, 2nd attempt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address new review comments Created 4 years, 4 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 <memory> 10 #include <memory>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Returns the associated ChromeBluetoothRemoteGattCharacteristic Java object. 54 // Returns the associated ChromeBluetoothRemoteGattCharacteristic Java object.
55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); 55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
56 56
57 // BluetoothRemoteGattCharacteristic interface: 57 // BluetoothRemoteGattCharacteristic interface:
58 std::string GetIdentifier() const override; 58 std::string GetIdentifier() const override;
59 BluetoothUUID GetUUID() const override; 59 BluetoothUUID GetUUID() const override;
60 const std::vector<uint8_t>& GetValue() const override; 60 const std::vector<uint8_t>& GetValue() const override;
61 BluetoothRemoteGattService* GetService() const override; 61 BluetoothRemoteGattService* GetService() const override;
62 Properties GetProperties() const override; 62 Properties GetProperties() const override;
63 Permissions GetPermissions() const override; 63 Permissions GetPermissions() const override;
64 bool IsNotifying() const override;
65 std::vector<BluetoothRemoteGattDescriptor*> GetDescriptors() const override; 64 std::vector<BluetoothRemoteGattDescriptor*> GetDescriptors() const override;
66 BluetoothRemoteGattDescriptor* GetDescriptor( 65 BluetoothRemoteGattDescriptor* GetDescriptor(
67 const std::string& identifier) const override; 66 const std::string& identifier) const override;
68 void StartNotifySession(const NotifySessionCallback& callback,
69 const ErrorCallback& error_callback) override;
70 void ReadRemoteCharacteristic(const ValueCallback& callback, 67 void ReadRemoteCharacteristic(const ValueCallback& callback,
71 const ErrorCallback& error_callback) override; 68 const ErrorCallback& error_callback) override;
72 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, 69 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value,
73 const base::Closure& callback, 70 const base::Closure& callback,
74 const ErrorCallback& error_callback) override; 71 const ErrorCallback& error_callback) override;
75 72
76 // Called when StartNotifySession operation succeeds.
77 void OnStartNotifySessionSuccess();
78
79 // Called when StartNotifySession operation fails.
80 void OnStartNotifySessionError(
81 BluetoothRemoteGattService::GattErrorCode error);
82
83 // Called when value changed event occurs. 73 // Called when value changed event occurs.
84 void OnChanged(JNIEnv* env, 74 void OnChanged(JNIEnv* env,
85 const base::android::JavaParamRef<jobject>& jcaller, 75 const base::android::JavaParamRef<jobject>& jcaller,
86 const base::android::JavaParamRef<jbyteArray>& value); 76 const base::android::JavaParamRef<jbyteArray>& value);
87 77
88 // Called when Read operation completes. 78 // Called when Read operation completes.
89 void OnRead(JNIEnv* env, 79 void OnRead(JNIEnv* env,
90 const base::android::JavaParamRef<jobject>& jcaller, 80 const base::android::JavaParamRef<jobject>& jcaller,
91 int32_t status, 81 int32_t status,
92 const base::android::JavaParamRef<jbyteArray>& value); 82 const base::android::JavaParamRef<jbyteArray>& value);
93 83
94 // Called when Write operation completes. 84 // Called when Write operation completes.
95 void OnWrite(JNIEnv* env, 85 void OnWrite(JNIEnv* env,
96 const base::android::JavaParamRef<jobject>& jcaller, 86 const base::android::JavaParamRef<jobject>& jcaller,
97 int32_t status); 87 int32_t status);
98 88
99 // Creates a Bluetooth GATT descriptor object and adds it to |descriptors_|, 89 // Creates a Bluetooth GATT descriptor object and adds it to |descriptors_|,
100 // DCHECKing that it has not already been created. 90 // DCHECKing that it has not already been created.
101 void CreateGattRemoteDescriptor( 91 void CreateGattRemoteDescriptor(
102 JNIEnv* env, 92 JNIEnv* env,
103 const base::android::JavaParamRef<jobject>& caller, 93 const base::android::JavaParamRef<jobject>& caller,
104 const base::android::JavaParamRef<jstring>& instanceId, 94 const base::android::JavaParamRef<jstring>& instanceId,
105 const base::android::JavaParamRef< 95 const base::android::JavaParamRef<
106 jobject>& /* BluetoothGattDescriptorWrapper */ 96 jobject>& /* BluetoothGattDescriptorWrapper */
107 bluetooth_gatt_descriptor_wrapper, 97 bluetooth_gatt_descriptor_wrapper,
108 const base::android::JavaParamRef< 98 const base::android::JavaParamRef<
109 jobject>& /* ChromeBluetoothCharacteristic */ 99 jobject>& /* ChromeBluetoothCharacteristic */
110 chrome_bluetooth_characteristic); 100 chrome_bluetooth_characteristic);
111 101
102 protected:
103 void SubscribeToNotifications(BluetoothRemoteGattDescriptor* ccc_descriptor,
104 const base::Closure& callback,
105 const ErrorCallback& error_callback) override;
106 void UnsubscribeFromNotifications(
107 BluetoothRemoteGattDescriptor* ccc_descriptor,
108 const base::Closure& callback,
109 const ErrorCallback& error_callback) override;
110
112 private: 111 private:
113 BluetoothRemoteGattCharacteristicAndroid( 112 BluetoothRemoteGattCharacteristicAndroid(
114 BluetoothAdapterAndroid* adapter, 113 BluetoothAdapterAndroid* adapter,
115 BluetoothRemoteGattServiceAndroid* service, 114 BluetoothRemoteGattServiceAndroid* service,
116 const std::string& instance_id); 115 const std::string& instance_id);
117 116
118 // Populates |descriptors_| from Java objects if necessary. 117 // Populates |descriptors_| from Java objects if necessary.
119 void EnsureDescriptorsCreated() const; 118 void EnsureDescriptorsCreated() const;
120 119
121 // The adapter and service associated with this characteristic. It's ok to 120 // The adapter and service associated with this characteristic. It's ok to
122 // store a raw pointers here since they indirectly own this instance. 121 // store a raw pointers here since they indirectly own this instance.
123 BluetoothAdapterAndroid* adapter_; 122 BluetoothAdapterAndroid* adapter_;
124 BluetoothRemoteGattServiceAndroid* service_; 123 BluetoothRemoteGattServiceAndroid* service_;
125 124
126 // Java object 125 // Java object
127 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic. 126 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic.
128 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_; 127 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_;
129 128
130 // Adapter unique instance ID. 129 // Adapter unique instance ID.
131 std::string instance_id_; 130 std::string instance_id_;
132 131
133 // StartNotifySession callbacks and pending state.
134 typedef std::pair<NotifySessionCallback, ErrorCallback>
135 PendingStartNotifyCall;
136 std::vector<PendingStartNotifyCall> pending_start_notify_calls_;
137
138 // ReadRemoteCharacteristic callbacks and pending state. 132 // ReadRemoteCharacteristic callbacks and pending state.
139 bool read_pending_ = false; 133 bool read_pending_ = false;
140 ValueCallback read_callback_; 134 ValueCallback read_callback_;
141 ErrorCallback read_error_callback_; 135 ErrorCallback read_error_callback_;
142 136
143 // WriteRemoteCharacteristic callbacks and pending state. 137 // WriteRemoteCharacteristic callbacks and pending state.
144 bool write_pending_ = false; 138 bool write_pending_ = false;
145 base::Closure write_callback_; 139 base::Closure write_callback_;
146 ErrorCallback write_error_callback_; 140 ErrorCallback write_error_callback_;
147 141
148 std::vector<uint8_t> value_; 142 std::vector<uint8_t> value_;
149 143
150 // Map of descriptors, keyed by descriptor identifier. 144 // Map of descriptors, keyed by descriptor identifier.
151 base::ScopedPtrHashMap<std::string, 145 base::ScopedPtrHashMap<std::string,
152 std::unique_ptr<BluetoothRemoteGattDescriptorAndroid>> 146 std::unique_ptr<BluetoothRemoteGattDescriptorAndroid>>
153 descriptors_; 147 descriptors_;
154 148
155 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); 149 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid);
156 }; 150 };
157 151
158 } // namespace device 152 } // namespace device
159 153
160 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ 154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698