Chromium Code Reviews| 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 #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 "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" | |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 13 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 13 | 14 |
| 14 namespace device { | 15 namespace device { |
| 15 | 16 |
| 17 class BluetoothAdapterAndroid; | |
| 18 class BluetoothRemoteGattDescriptorAndroid; | |
| 19 | |
| 16 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class | 20 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class |
| 17 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic | 21 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic |
| 18 // implement BluetootGattCharacteristic. | 22 // implement BluetootGattCharacteristic. |
| 19 // | 23 // |
| 20 // TODO(crbug.com/551634): When notifications are enabled characteristic updates | 24 // TODO(crbug.com/551634): When notifications are enabled characteristic updates |
| 21 // should call observers' GattCharacteristicValueChanged. | 25 // should call observers' GattCharacteristicValueChanged. |
| 22 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid | 26 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid |
| 23 : public BluetoothGattCharacteristic { | 27 : public BluetoothGattCharacteristic { |
| 24 public: | 28 public: |
| 25 // Create a BluetoothRemoteGattCharacteristicAndroid instance and associated | 29 // Create a BluetoothRemoteGattCharacteristicAndroid instance and associated |
| 26 // Java | 30 // Java |
| 27 // ChromeBluetoothRemoteGattCharacteristic using the provided | 31 // ChromeBluetoothRemoteGattCharacteristic using the provided |
| 28 // |bluetooth_gatt_characteristic_wrapper|. | 32 // |bluetooth_gatt_characteristic_wrapper|. |
| 29 // | 33 // |
| 30 // The ChromeBluetoothRemoteGattCharacteristic instance will hold a Java | 34 // The ChromeBluetoothRemoteGattCharacteristic instance will hold a Java |
| 31 // reference | 35 // reference |
| 32 // to |bluetooth_gatt_characteristic_wrapper|. | 36 // to |bluetooth_gatt_characteristic_wrapper|. |
| 33 static scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( | 37 static scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( |
| 38 BluetoothAdapterAndroid* adapter, | |
| 34 const std::string& instance_id, | 39 const std::string& instance_id, |
| 35 jobject /* BluetoothGattCharacteristicWrapper */ | 40 jobject /* BluetoothGattCharacteristicWrapper */ |
| 36 bluetooth_gatt_characteristic_wrapper, | 41 bluetooth_gatt_characteristic_wrapper, |
| 37 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); | 42 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); |
| 38 | 43 |
| 39 ~BluetoothRemoteGattCharacteristicAndroid() override; | 44 ~BluetoothRemoteGattCharacteristicAndroid() override; |
| 40 | 45 |
| 41 // Register C++ methods exposed to Java using JNI. | 46 // Register C++ methods exposed to Java using JNI. |
| 42 static bool RegisterJNI(JNIEnv* env); | 47 static bool RegisterJNI(JNIEnv* env); |
| 43 | 48 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 70 void OnRead(JNIEnv* env, | 75 void OnRead(JNIEnv* env, |
| 71 const base::android::JavaParamRef<jobject>& jcaller, | 76 const base::android::JavaParamRef<jobject>& jcaller, |
| 72 int32_t status, | 77 int32_t status, |
| 73 const base::android::JavaParamRef<jbyteArray>& value); | 78 const base::android::JavaParamRef<jbyteArray>& value); |
| 74 | 79 |
| 75 // Callback after Write operation completes. | 80 // Callback after Write operation completes. |
| 76 void OnWrite(JNIEnv* env, | 81 void OnWrite(JNIEnv* env, |
| 77 const base::android::JavaParamRef<jobject>& jcaller, | 82 const base::android::JavaParamRef<jobject>& jcaller, |
| 78 int32_t status); | 83 int32_t status); |
| 79 | 84 |
| 85 // Creates a Bluetooth GATT descriptor object and adds it to |descriptors_| | |
|
Jeffrey Yasskin
2016/01/12 21:53:54
Add a comma before 'DCHECKing'.
scheib
2016/01/12 23:16:56
Done.
| |
| 86 // DCHECKing that it has not already been created. | |
| 87 void CreateGattRemoteDescriptor( | |
| 88 JNIEnv* env, | |
| 89 const base::android::JavaParamRef<jobject>& caller, | |
| 90 const base::android::JavaParamRef<jstring>& instanceId, | |
| 91 const base::android::JavaParamRef< | |
| 92 jobject>& /* BluetoothGattDescriptorWrapper */ | |
| 93 bluetooth_gatt_descriptor_wrapper, | |
| 94 const base::android::JavaParamRef< | |
| 95 jobject>& /* ChromeBluetoothCharacteristic */ | |
| 96 chrome_bluetooth_characteristic); | |
| 97 | |
| 80 private: | 98 private: |
| 81 BluetoothRemoteGattCharacteristicAndroid(const std::string& instance_id); | 99 BluetoothRemoteGattCharacteristicAndroid(BluetoothAdapterAndroid* adapter, |
| 100 const std::string& instance_id); | |
| 101 | |
| 102 // Populates |descriptors_| from Java objects if necessary. | |
| 103 void EnsureDescriptorsCreated() const; | |
| 104 | |
| 105 // The adapter associated with this service. It's ok to store a raw pointer | |
| 106 // here since |adapter_| indirectly owns this instance. | |
| 107 BluetoothAdapterAndroid* adapter_; | |
| 82 | 108 |
| 83 // Java object | 109 // Java object |
| 84 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic. | 110 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic. |
| 85 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_; | 111 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_; |
| 86 | 112 |
| 87 // Adapter unique instance ID. | 113 // Adapter unique instance ID. |
| 88 std::string instance_id_; | 114 std::string instance_id_; |
| 89 | 115 |
| 90 // ReadRemoteCharacteristic callbacks and pending state. | 116 // ReadRemoteCharacteristic callbacks and pending state. |
| 91 bool read_pending_ = false; | 117 bool read_pending_ = false; |
| 92 ValueCallback read_callback_; | 118 ValueCallback read_callback_; |
| 93 ErrorCallback read_error_callback_; | 119 ErrorCallback read_error_callback_; |
| 94 | 120 |
| 95 // WriteRemoteCharacteristic callbacks and pending state. | 121 // WriteRemoteCharacteristic callbacks and pending state. |
| 96 bool write_pending_ = false; | 122 bool write_pending_ = false; |
| 97 base::Closure write_callback_; | 123 base::Closure write_callback_; |
| 98 ErrorCallback write_error_callback_; | 124 ErrorCallback write_error_callback_; |
| 99 | 125 |
| 100 std::vector<uint8_t> value_; | 126 std::vector<uint8_t> value_; |
| 101 | 127 |
| 128 // Map of descriptors, keyed by descriptor identifier. | |
| 129 base::ScopedPtrHashMap<std::string, | |
| 130 scoped_ptr<BluetoothRemoteGattDescriptorAndroid>> | |
| 131 descriptors_; | |
| 132 | |
| 102 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); | 133 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); |
| 103 }; | 134 }; |
| 104 | 135 |
| 105 } // namespace device | 136 } // namespace device |
| 106 | 137 |
| 107 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ | 138 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ |
| OLD | NEW |