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_SERVICE_ANDROID_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "device/bluetooth/bluetooth_gatt_service.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
17 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
18 | 18 |
19 namespace device { | 19 namespace device { |
20 | 20 |
21 class BluetoothAdapterAndroid; | 21 class BluetoothAdapterAndroid; |
22 class BluetoothDeviceAndroid; | 22 class BluetoothDeviceAndroid; |
23 class BluetoothRemoteGattCharacteristicAndroid; | 23 class BluetoothRemoteGattCharacteristicAndroid; |
24 | 24 |
25 // BluetoothRemoteGattServiceAndroid along with its owned Java class | 25 // BluetoothRemoteGattServiceAndroid along with its owned Java class |
26 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService implement | 26 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService implement |
27 // BluetoothGattService. | 27 // BluetoothRemoteGattService. |
28 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceAndroid | 28 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceAndroid |
29 : public device::BluetoothGattService { | 29 : public device::BluetoothRemoteGattService { |
30 public: | 30 public: |
31 // Create a BluetoothRemoteGattServiceAndroid instance and associated Java | 31 // Create a BluetoothRemoteGattServiceAndroid instance and associated Java |
32 // ChromeBluetoothRemoteGattService using the provided | 32 // ChromeBluetoothRemoteGattService using the provided |
33 // |bluetooth_gatt_service_wrapper|. | 33 // |bluetooth_gatt_service_wrapper|. |
34 // | 34 // |
35 // The ChromeBluetoothRemoteGattService instance will hold a Java reference | 35 // The ChromeBluetoothRemoteGattService instance will hold a Java reference |
36 // to |bluetooth_gatt_service_wrapper|. | 36 // to |bluetooth_gatt_service_wrapper|. |
37 static std::unique_ptr<BluetoothRemoteGattServiceAndroid> Create( | 37 static std::unique_ptr<BluetoothRemoteGattServiceAndroid> Create( |
38 BluetoothAdapterAndroid* adapter, | 38 BluetoothAdapterAndroid* adapter, |
39 BluetoothDeviceAndroid* device, | 39 BluetoothDeviceAndroid* device, |
40 jobject /* BluetoothGattServiceWrapper */ bluetooth_gatt_service_wrapper, | 40 jobject /* BluetoothGattServiceWrapper */ bluetooth_gatt_service_wrapper, |
41 const std::string& instance_id, | 41 const std::string& instance_id, |
42 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); | 42 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device); |
43 | 43 |
44 ~BluetoothRemoteGattServiceAndroid() override; | 44 ~BluetoothRemoteGattServiceAndroid() override; |
45 | 45 |
46 // Register C++ methods exposed to Java using JNI. | 46 // Register C++ methods exposed to Java using JNI. |
47 static bool RegisterJNI(JNIEnv* env); | 47 static bool RegisterJNI(JNIEnv* env); |
48 | 48 |
49 // Returns the associated ChromeBluetoothRemoteGattService Java object. | 49 // Returns the associated ChromeBluetoothRemoteGattService Java object. |
50 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | 50 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); |
51 | 51 |
52 // Returns a BluetoothGattService::GattErrorCode from a given | 52 // Returns a BluetoothRemoteGattService::GattErrorCode from a given |
53 // android.bluetooth.BluetoothGatt error code. | 53 // android.bluetooth.BluetoothGatt error code. |
54 // |bluetooth_gatt_code| must not be 0 == GATT_SUCCESS. | 54 // |bluetooth_gatt_code| must not be 0 == GATT_SUCCESS. |
55 static BluetoothGattService::GattErrorCode GetGattErrorCode( | 55 static BluetoothRemoteGattService::GattErrorCode GetGattErrorCode( |
56 int bluetooth_gatt_code); | 56 int bluetooth_gatt_code); |
57 | 57 |
58 // Returns an android.bluetooth.BluetoothGatt error code for a given | 58 // Returns an android.bluetooth.BluetoothGatt error code for a given |
59 // BluetoothGattService::GattErrorCode value. | 59 // BluetoothRemoteGattService::GattErrorCode value. |
60 static int GetAndroidErrorCode(BluetoothGattService::GattErrorCode); | 60 static int GetAndroidErrorCode(BluetoothRemoteGattService::GattErrorCode); |
61 | 61 |
62 // device::BluetoothGattService overrides. | 62 // device::BluetoothRemoteGattService overrides. |
63 std::string GetIdentifier() const override; | 63 std::string GetIdentifier() const override; |
64 device::BluetoothUUID GetUUID() const override; | 64 device::BluetoothUUID GetUUID() const override; |
65 bool IsLocal() const override; | |
66 bool IsPrimary() const override; | 65 bool IsPrimary() const override; |
67 device::BluetoothDevice* GetDevice() const override; | 66 device::BluetoothDevice* GetDevice() const override; |
68 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics() | 67 std::vector<device::BluetoothRemoteGattCharacteristic*> GetCharacteristics() |
69 const override; | 68 const override; |
70 std::vector<device::BluetoothGattService*> GetIncludedServices() | 69 std::vector<device::BluetoothRemoteGattService*> GetIncludedServices() |
71 const override; | 70 const override; |
72 device::BluetoothGattCharacteristic* GetCharacteristic( | 71 device::BluetoothRemoteGattCharacteristic* GetCharacteristic( |
73 const std::string& identifier) const override; | 72 const std::string& identifier) const override; |
74 bool AddCharacteristic( | |
75 device::BluetoothGattCharacteristic* characteristic) override; | |
76 bool AddIncludedService(device::BluetoothGattService* service) override; | |
77 void Register(const base::Closure& callback, | |
78 const ErrorCallback& error_callback) override; | |
79 void Unregister(const base::Closure& callback, | |
80 const ErrorCallback& error_callback) override; | |
81 | 73 |
82 // Creates a Bluetooth GATT characteristic object and adds it to | 74 // Creates a Bluetooth GATT characteristic object and adds it to |
83 // |characteristics_|, DCHECKing that it has not already been created. | 75 // |characteristics_|, DCHECKing that it has not already been created. |
84 void CreateGattRemoteCharacteristic( | 76 void CreateGattRemoteCharacteristic( |
85 JNIEnv* env, | 77 JNIEnv* env, |
86 const base::android::JavaParamRef<jobject>& caller, | 78 const base::android::JavaParamRef<jobject>& caller, |
87 const base::android::JavaParamRef<jstring>& instance_id, | 79 const base::android::JavaParamRef<jstring>& instance_id, |
88 const base::android::JavaParamRef< | 80 const base::android::JavaParamRef< |
89 jobject>& /* BluetoothGattCharacteristicWrapper */ | 81 jobject>& /* BluetoothGattCharacteristicWrapper */ |
90 bluetooth_gatt_characteristic_wrapper, | 82 bluetooth_gatt_characteristic_wrapper, |
(...skipping 27 matching lines...) Expand all Loading... |
118 std::string, | 110 std::string, |
119 std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid>> | 111 std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid>> |
120 characteristics_; | 112 characteristics_; |
121 | 113 |
122 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); | 114 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); |
123 }; | 115 }; |
124 | 116 |
125 } // namespace device | 117 } // namespace device |
126 | 118 |
127 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ | 119 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ |
OLD | NEW |