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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 10 matching lines...) Expand all Loading... |
21 class BluetoothRemoteGattCharacteristicAndroid; | 21 class BluetoothRemoteGattCharacteristicAndroid; |
22 | 22 |
23 // BluetoothRemoteGattServiceAndroid along with its owned Java class | 23 // BluetoothRemoteGattServiceAndroid along with its owned Java class |
24 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService implement | 24 // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService implement |
25 // BluetoothGattService. | 25 // BluetoothGattService. |
26 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceAndroid | 26 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceAndroid |
27 : public device::BluetoothGattService { | 27 : public device::BluetoothGattService { |
28 public: | 28 public: |
29 // Create a BluetoothRemoteGattServiceAndroid instance and associated Java | 29 // Create a BluetoothRemoteGattServiceAndroid instance and associated Java |
30 // ChromeBluetoothRemoteGattService using the provided | 30 // ChromeBluetoothRemoteGattService using the provided |
31 // |bluetooth_remote_gatt_service_wrapper|. | 31 // |bluetooth_gatt_service_wrapper|. |
32 // | 32 // |
33 // The ChromeBluetoothRemoteGattService instance will hold a Java reference | 33 // The ChromeBluetoothRemoteGattService instance will hold a Java reference |
34 // to |bluetooth_remote_gatt_service_wrapper|. | 34 // to |bluetooth_gatt_service_wrapper|. |
35 // | 35 static scoped_ptr<BluetoothRemoteGattServiceAndroid> Create( |
36 // TODO(scheib): Return a scoped_ptr<>, but then device will need to handle | |
37 // this correctly. http://crbug.com/506416 | |
38 static BluetoothRemoteGattServiceAndroid* Create( | |
39 BluetoothAdapterAndroid* adapter, | 36 BluetoothAdapterAndroid* adapter, |
40 BluetoothDeviceAndroid* device, | 37 BluetoothDeviceAndroid* device, |
41 jobject bluetooth_remote_gatt_service_wrapper, // Java Type: | 38 jobject /* BluetoothRemoteGattServiceWrapper */ |
42 // BluetoothRemoteGattServiceWrapper | 39 bluetooth_gatt_service_wrapper, |
43 const std::string& instanceId); | 40 const std::string& instanceId); |
44 | 41 |
| 42 ~BluetoothRemoteGattServiceAndroid() override; |
| 43 |
45 // Register C++ methods exposed to Java using JNI. | 44 // Register C++ methods exposed to Java using JNI. |
46 static bool RegisterJNI(JNIEnv* env); | 45 static bool RegisterJNI(JNIEnv* env); |
47 | 46 |
48 // Returns the associated ChromeBluetoothRemoteGattService Java object. | 47 // Returns the associated ChromeBluetoothRemoteGattService Java object. |
49 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | 48 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); |
50 | 49 |
51 // device::BluetoothGattService overrides. | 50 // device::BluetoothGattService overrides. |
52 std::string GetIdentifier() const override; | 51 std::string GetIdentifier() const override; |
53 device::BluetoothUUID GetUUID() const override; | 52 device::BluetoothUUID GetUUID() const override; |
54 bool IsLocal() const override; | 53 bool IsLocal() const override; |
(...skipping 16 matching lines...) Expand all Loading... |
71 // Creates a Bluetooth GATT characteristic object and adds it to | 70 // Creates a Bluetooth GATT characteristic object and adds it to |
72 // |characteristics_| if it is not already there. | 71 // |characteristics_| if it is not already there. |
73 void CreateGattRemoteCharacteristic( | 72 void CreateGattRemoteCharacteristic( |
74 JNIEnv* env, | 73 JNIEnv* env, |
75 jobject caller, | 74 jobject caller, |
76 const jstring& instanceId, | 75 const jstring& instanceId, |
77 jobject /* BluetoothGattCharacteristicWrapper */ | 76 jobject /* BluetoothGattCharacteristicWrapper */ |
78 bluetooth_gatt_characteristic_wrapper); | 77 bluetooth_gatt_characteristic_wrapper); |
79 | 78 |
80 private: | 79 private: |
81 friend class BluetoothDeviceAndroid; | |
82 | |
83 BluetoothRemoteGattServiceAndroid(BluetoothAdapterAndroid* adapter, | 80 BluetoothRemoteGattServiceAndroid(BluetoothAdapterAndroid* adapter, |
84 BluetoothDeviceAndroid* device, | 81 BluetoothDeviceAndroid* device, |
85 const std::string& instanceId); | 82 const std::string& instanceId); |
86 ~BluetoothRemoteGattServiceAndroid() override; | |
87 | 83 |
88 // Populates |characteristics_| from Java objects if necessary. | 84 // Populates |characteristics_| from Java objects if necessary. |
89 void EnsureCharacteristicsCreated() const; | 85 void EnsureCharacteristicsCreated() const; |
90 | 86 |
91 // Java object org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService. | 87 // Java object org.chromium.device.bluetooth.ChromeBluetoothRemoteGattService. |
92 base::android::ScopedJavaGlobalRef<jobject> j_service_; | 88 base::android::ScopedJavaGlobalRef<jobject> j_service_; |
93 | 89 |
94 // The adapter associated with this service. It's ok to store a raw pointer | 90 // The adapter associated with this service. It's ok to store a raw pointer |
95 // here since |adapter_| indirectly owns this instance. | 91 // here since |adapter_| indirectly owns this instance. |
96 BluetoothAdapterAndroid* adapter_; | 92 BluetoothAdapterAndroid* adapter_; |
97 | 93 |
98 // The device this GATT service belongs to. It's ok to store a raw pointer | 94 // The device this GATT service belongs to. It's ok to store a raw pointer |
99 // here since |device_| owns this instance. | 95 // here since |device_| owns this instance. |
100 BluetoothDeviceAndroid* device_; | 96 BluetoothDeviceAndroid* device_; |
101 | 97 |
102 // Adapter unique instance ID. | 98 // Adapter unique instance ID. |
103 std::string instanceId_; | 99 std::string instanceId_; |
104 | 100 |
105 // Map of characteristics, keyed by characteristic identifier. | 101 // Map of characteristics, keyed by characteristic identifier. |
106 base::ScopedPtrHashMap<std::string, | 102 base::ScopedPtrHashMap<std::string, |
107 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid>> | 103 scoped_ptr<BluetoothRemoteGattCharacteristicAndroid>> |
108 characteristics_; | 104 characteristics_; |
109 | 105 |
110 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); | 106 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceAndroid); |
111 }; | 107 }; |
112 | 108 |
113 } // namespace device | 109 } // namespace device |
114 | 110 |
115 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ | 111 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_ANDROID_H_ |
OLD | NEW |