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 <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
13 #include "base/containers/scoped_ptr_hash_map.h" | 13 #include "base/containers/scoped_ptr_hash_map.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
16 | 17 |
17 namespace device { | 18 namespace device { |
18 | 19 |
19 class BluetoothAdapterAndroid; | 20 class BluetoothAdapterAndroid; |
20 class BluetoothRemoteGattDescriptorAndroid; | 21 class BluetoothRemoteGattDescriptorAndroid; |
21 class BluetoothRemoteGattServiceAndroid; | 22 class BluetoothRemoteGattServiceAndroid; |
22 | 23 |
23 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class | 24 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class |
24 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic | 25 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic |
25 // implement BluetootGattCharacteristic. | 26 // implement BluetootGattCharacteristic. |
26 // | 27 // |
27 // TODO(crbug.com/551634): When notifications are enabled characteristic updates | 28 // TODO(crbug.com/551634): When notifications are enabled characteristic updates |
28 // should call observers' GattCharacteristicValueChanged. | 29 // should call observers' GattCharacteristicValueChanged. |
29 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid | 30 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid |
30 : public BluetoothGattCharacteristic { | 31 : public BluetoothRemoteGattCharacteristic { |
31 public: | 32 public: |
32 // Create a BluetoothRemoteGattCharacteristicAndroid instance and associated | 33 // Create a BluetoothRemoteGattCharacteristicAndroid instance and associated |
33 // Java | 34 // Java |
34 // ChromeBluetoothRemoteGattCharacteristic using the provided | 35 // ChromeBluetoothRemoteGattCharacteristic using the provided |
35 // |bluetooth_gatt_characteristic_wrapper|. | 36 // |bluetooth_gatt_characteristic_wrapper|. |
36 // | 37 // |
37 // The ChromeBluetoothRemoteGattCharacteristic instance will hold a Java | 38 // The ChromeBluetoothRemoteGattCharacteristic instance will hold a Java |
38 // reference | 39 // reference |
39 // to |bluetooth_gatt_characteristic_wrapper|. | 40 // to |bluetooth_gatt_characteristic_wrapper|. |
40 static std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( | 41 static std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( |
41 BluetoothAdapterAndroid* adapter, | 42 BluetoothAdapterAndroid* adapter, |
42 BluetoothRemoteGattServiceAndroid* service, | 43 BluetoothRemoteGattServiceAndroid* service, |
43 const std::string& instance_id, | 44 const std::string& instance_id, |
44 jobject /* BluetoothGattCharacteristicWrapper */ | 45 jobject /* BluetoothGattCharacteristicWrapper */ |
45 bluetooth_gatt_characteristic_wrapper, | 46 bluetooth_gatt_characteristic_wrapper, |
46 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); | 47 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); |
47 | 48 |
48 ~BluetoothRemoteGattCharacteristicAndroid() override; | 49 ~BluetoothRemoteGattCharacteristicAndroid() override; |
49 | 50 |
50 // Register C++ methods exposed to Java using JNI. | 51 // Register C++ methods exposed to Java using JNI. |
51 static bool RegisterJNI(JNIEnv* env); | 52 static bool RegisterJNI(JNIEnv* env); |
52 | 53 |
53 // Returns the associated ChromeBluetoothRemoteGattCharacteristic Java object. | 54 // Returns the associated ChromeBluetoothRemoteGattCharacteristic Java object. |
54 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | 55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); |
55 | 56 |
56 // BluetoothGattCharacteristic interface: | 57 // BluetoothRemoteGattCharacteristic interface: |
57 std::string GetIdentifier() const override; | 58 std::string GetIdentifier() const override; |
58 BluetoothUUID GetUUID() const override; | 59 BluetoothUUID GetUUID() const override; |
59 bool IsLocal() const override; | |
60 const std::vector<uint8_t>& GetValue() const override; | 60 const std::vector<uint8_t>& GetValue() const override; |
61 BluetoothGattService* 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; | 64 bool IsNotifying() const override; |
65 std::vector<BluetoothGattDescriptor*> GetDescriptors() const override; | 65 std::vector<BluetoothRemoteGattDescriptor*> GetDescriptors() const override; |
66 BluetoothGattDescriptor* GetDescriptor( | 66 BluetoothRemoteGattDescriptor* GetDescriptor( |
67 const std::string& identifier) const override; | 67 const std::string& identifier) const override; |
68 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override; | |
69 bool UpdateValue(const std::vector<uint8_t>& value) override; | |
70 void StartNotifySession(const NotifySessionCallback& callback, | 68 void StartNotifySession(const NotifySessionCallback& callback, |
71 const ErrorCallback& error_callback) override; | 69 const ErrorCallback& error_callback) override; |
72 void ReadRemoteCharacteristic(const ValueCallback& callback, | 70 void ReadRemoteCharacteristic(const ValueCallback& callback, |
73 const ErrorCallback& error_callback) override; | 71 const ErrorCallback& error_callback) override; |
74 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, | 72 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, |
75 const base::Closure& callback, | 73 const base::Closure& callback, |
76 const ErrorCallback& error_callback) override; | 74 const ErrorCallback& error_callback) override; |
77 | 75 |
78 // Called when StartNotifySession operation succeeds. | 76 // Called when StartNotifySession operation succeeds. |
79 void OnStartNotifySessionSuccess(); | 77 void OnStartNotifySessionSuccess(); |
80 | 78 |
81 // Called when StartNotifySession operation fails. | 79 // Called when StartNotifySession operation fails. |
82 void OnStartNotifySessionError(BluetoothGattService::GattErrorCode error); | 80 void OnStartNotifySessionError( |
| 81 BluetoothRemoteGattService::GattErrorCode error); |
83 | 82 |
84 // Called when value changed event occurs. | 83 // Called when value changed event occurs. |
85 void OnChanged(JNIEnv* env, | 84 void OnChanged(JNIEnv* env, |
86 const base::android::JavaParamRef<jobject>& jcaller, | 85 const base::android::JavaParamRef<jobject>& jcaller, |
87 const base::android::JavaParamRef<jbyteArray>& value); | 86 const base::android::JavaParamRef<jbyteArray>& value); |
88 | 87 |
89 // Called when Read operation completes. | 88 // Called when Read operation completes. |
90 void OnRead(JNIEnv* env, | 89 void OnRead(JNIEnv* env, |
91 const base::android::JavaParamRef<jobject>& jcaller, | 90 const base::android::JavaParamRef<jobject>& jcaller, |
92 int32_t status, | 91 int32_t status, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 base::ScopedPtrHashMap<std::string, | 151 base::ScopedPtrHashMap<std::string, |
153 std::unique_ptr<BluetoothRemoteGattDescriptorAndroid>> | 152 std::unique_ptr<BluetoothRemoteGattDescriptorAndroid>> |
154 descriptors_; | 153 descriptors_; |
155 | 154 |
156 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); | 155 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); |
157 }; | 156 }; |
158 | 157 |
159 } // namespace device | 158 } // namespace device |
160 | 159 |
161 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ | 160 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ |
OLD | NEW |