| 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; | 65 bool IsLocal() const override; |
| 66 bool IsPrimary() const override; | 66 bool IsPrimary() const override; |
| 67 device::BluetoothDevice* GetDevice() const override; | 67 device::BluetoothDevice* GetDevice() const override; |
| 68 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics() | 68 std::vector<device::BluetoothRemoteGattCharacteristic*> GetCharacteristics() |
| 69 const override; | 69 const override; |
| 70 std::vector<device::BluetoothGattService*> GetIncludedServices() | 70 std::vector<device::BluetoothRemoteGattService*> GetIncludedServices() |
| 71 const override; | 71 const override; |
| 72 device::BluetoothGattCharacteristic* GetCharacteristic( | 72 device::BluetoothRemoteGattCharacteristic* GetCharacteristic( |
| 73 const std::string& identifier) const override; | 73 const std::string& identifier) const override; |
| 74 bool AddCharacteristic( | 74 bool AddCharacteristic( |
| 75 device::BluetoothGattCharacteristic* characteristic) override; | 75 device::BluetoothRemoteGattCharacteristic* characteristic) override; |
| 76 bool AddIncludedService(device::BluetoothGattService* service) override; | 76 bool AddIncludedService(device::BluetoothRemoteGattService* service) override; |
| 77 void Register(const base::Closure& callback, | 77 void Register(const base::Closure& callback, |
| 78 const ErrorCallback& error_callback) override; | 78 const ErrorCallback& error_callback) override; |
| 79 void Unregister(const base::Closure& callback, | 79 void Unregister(const base::Closure& callback, |
| 80 const ErrorCallback& error_callback) override; | 80 const ErrorCallback& error_callback) override; |
| 81 | 81 |
| 82 // Creates a Bluetooth GATT characteristic object and adds it to | 82 // Creates a Bluetooth GATT characteristic object and adds it to |
| 83 // |characteristics_|, DCHECKing that it has not already been created. | 83 // |characteristics_|, DCHECKing that it has not already been created. |
| 84 void CreateGattRemoteCharacteristic( | 84 void CreateGattRemoteCharacteristic( |
| 85 JNIEnv* env, | 85 JNIEnv* env, |
| 86 const base::android::JavaParamRef<jobject>& caller, | 86 const base::android::JavaParamRef<jobject>& caller, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 std::string, | 118 std::string, |
| 119 std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid>> | 119 std::unique_ptr<BluetoothRemoteGattCharacteristicAndroid>> |
| 120 characteristics_; | 120 characteristics_; |
| 121 | 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); | 122 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace device | 125 } // namespace device |
| 126 | 126 |
| 127 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ | 127 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ |
| OLD | NEW |