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 "base/android/jni_android.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 10 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
10 | 11 |
11 namespace device { | 12 namespace device { |
12 | 13 |
13 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class | 14 // BluetoothRemoteGattCharacteristicAndroid along with its owned Java class |
14 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic | 15 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic |
15 // implement BluetootGattCharacteristic. | 16 // implement BluetootGattCharacteristic. |
16 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid | 17 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicAndroid |
17 : public BluetoothGattCharacteristic { | 18 : public BluetoothGattCharacteristic { |
18 public: | 19 public: |
19 // Create a BluetoothRemoteGattServiceAndroid instance and associated Java | 20 // Create a BluetoothRemoteGattCharacteristicAndroid instance and associated |
20 // ChromeBluetoothRemoteGattService using the provided | 21 // Java |
21 // |bluetooth_remote_gatt_service_wrapper|. | 22 // ChromeBluetoothRemoteGattCharacteristic using the provided |
| 23 // |bluetooth_gatt_characteristic_wrapper|. |
22 // | 24 // |
23 // The ChromeBluetoothRemoteGattService instance will hold a Java reference | 25 // The ChromeBluetoothRemoteGattCharacteristic instance will hold a Java |
24 // to |bluetooth_remote_gatt_service_wrapper|. | 26 // reference |
25 // | 27 // to |bluetooth_gatt_characteristic_wrapper|. |
26 // TODO(scheib): Actually create the Java object. crbug.com/545682 | |
27 static scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( | 28 static scoped_ptr<BluetoothRemoteGattCharacteristicAndroid> Create( |
28 const std::string& instanceId); | 29 const std::string& instanceId, |
| 30 jobject /* BluetoothGattCharacteristicWrapper */ |
| 31 bluetooth_gatt_characteristic_wrapper); |
29 | 32 |
30 ~BluetoothRemoteGattCharacteristicAndroid() override; | 33 ~BluetoothRemoteGattCharacteristicAndroid() override; |
31 | 34 |
| 35 // Register C++ methods exposed to Java using JNI. |
| 36 static bool RegisterJNI(JNIEnv* env); |
| 37 |
32 // BluetoothGattCharacteristic interface: | 38 // BluetoothGattCharacteristic interface: |
33 std::string GetIdentifier() const override; | 39 std::string GetIdentifier() const override; |
34 BluetoothUUID GetUUID() const override; | 40 BluetoothUUID GetUUID() const override; |
35 bool IsLocal() const override; | 41 bool IsLocal() const override; |
36 const std::vector<uint8>& GetValue() const override; | 42 const std::vector<uint8>& GetValue() const override; |
37 BluetoothGattService* GetService() const override; | 43 BluetoothGattService* GetService() const override; |
38 Properties GetProperties() const override; | 44 Properties GetProperties() const override; |
39 Permissions GetPermissions() const override; | 45 Permissions GetPermissions() const override; |
40 bool IsNotifying() const override; | 46 bool IsNotifying() const override; |
41 std::vector<BluetoothGattDescriptor*> GetDescriptors() const override; | 47 std::vector<BluetoothGattDescriptor*> GetDescriptors() const override; |
42 BluetoothGattDescriptor* GetDescriptor( | 48 BluetoothGattDescriptor* GetDescriptor( |
43 const std::string& identifier) const override; | 49 const std::string& identifier) const override; |
44 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override; | 50 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override; |
45 bool UpdateValue(const std::vector<uint8>& value) override; | 51 bool UpdateValue(const std::vector<uint8>& value) override; |
46 void StartNotifySession(const NotifySessionCallback& callback, | 52 void StartNotifySession(const NotifySessionCallback& callback, |
47 const ErrorCallback& error_callback) override; | 53 const ErrorCallback& error_callback) override; |
48 void ReadRemoteCharacteristic(const ValueCallback& callback, | 54 void ReadRemoteCharacteristic(const ValueCallback& callback, |
49 const ErrorCallback& error_callback) override; | 55 const ErrorCallback& error_callback) override; |
50 void WriteRemoteCharacteristic(const std::vector<uint8>& new_value, | 56 void WriteRemoteCharacteristic(const std::vector<uint8>& new_value, |
51 const base::Closure& callback, | 57 const base::Closure& callback, |
52 const ErrorCallback& error_callback) override; | 58 const ErrorCallback& error_callback) override; |
53 | 59 |
54 private: | 60 private: |
55 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId); | 61 BluetoothRemoteGattCharacteristicAndroid(const std::string& instanceId); |
56 | 62 |
| 63 // Java object |
| 64 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattCharacteristic. |
| 65 base::android::ScopedJavaGlobalRef<jobject> j_characteristic_; |
| 66 |
57 // Adapter unique instance ID. | 67 // Adapter unique instance ID. |
58 std::string instanceId_; | 68 std::string instanceId_; |
59 | 69 |
60 std::vector<uint8> value_; | 70 std::vector<uint8> value_; |
61 | 71 |
62 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); | 72 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicAndroid); |
63 }; | 73 }; |
64 | 74 |
65 } // namespace device | 75 } // namespace device |
66 | 76 |
67 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ | 77 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_ANDROID_H_ |
OLD | NEW |