OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "device/bluetooth/bluetooth_adapter_android.h" | 9 #include "device/bluetooth/bluetooth_adapter_android.h" |
10 #include "device/bluetooth/bluetooth_device_android.h" | 10 #include "device/bluetooth/bluetooth_device_android.h" |
11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" | 11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" |
12 #include "jni/ChromeBluetoothRemoteGattService_jni.h" | 12 #include "jni/ChromeBluetoothRemoteGattService_jni.h" |
13 | 13 |
14 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
15 | 15 |
16 namespace device { | 16 namespace device { |
17 | 17 |
18 // static | 18 // static |
19 BluetoothRemoteGattServiceAndroid* BluetoothRemoteGattServiceAndroid::Create( | 19 BluetoothRemoteGattServiceAndroid* BluetoothRemoteGattServiceAndroid::Create( |
20 BluetoothAdapterAndroid* adapter, | 20 BluetoothAdapterAndroid* adapter, |
21 BluetoothDeviceAndroid* device, | 21 BluetoothDeviceAndroid* device, |
22 jobject bluetooth_remote_gatt_service_wrapper, | 22 jobject bluetooth_gatt_service_wrapper, |
23 const std::string& instanceId) { | 23 const std::string& instanceId) { |
24 BluetoothRemoteGattServiceAndroid* service = | 24 BluetoothRemoteGattServiceAndroid* service = |
25 new BluetoothRemoteGattServiceAndroid(adapter, device, instanceId); | 25 new BluetoothRemoteGattServiceAndroid(adapter, device, instanceId); |
26 | 26 |
27 JNIEnv* env = base::android::AttachCurrentThread(); | 27 JNIEnv* env = AttachCurrentThread(); |
28 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create( | 28 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create( |
29 env, reinterpret_cast<intptr_t>(service), | 29 env, reinterpret_cast<intptr_t>(service), bluetooth_gatt_service_wrapper, |
30 bluetooth_remote_gatt_service_wrapper, | |
31 base::android::ConvertUTF8ToJavaString(env, instanceId).obj())); | 30 base::android::ConvertUTF8ToJavaString(env, instanceId).obj())); |
32 | 31 |
33 return service; | 32 return service; |
34 } | 33 } |
35 | 34 |
| 35 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() { |
| 36 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr
uction( |
| 37 AttachCurrentThread(), j_service_.obj()); |
| 38 } |
| 39 |
36 // static | 40 // static |
37 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) { | 41 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) { |
38 return RegisterNativesImpl( | 42 return RegisterNativesImpl( |
39 env); // Generated in ChromeBluetoothRemoteGattService_jni.h | 43 env); // Generated in ChromeBluetoothRemoteGattService_jni.h |
40 } | 44 } |
41 | 45 |
42 base::android::ScopedJavaLocalRef<jobject> | 46 base::android::ScopedJavaLocalRef<jobject> |
43 BluetoothRemoteGattServiceAndroid::GetJavaObject() { | 47 BluetoothRemoteGattServiceAndroid::GetJavaObject() { |
44 return base::android::ScopedJavaLocalRef<jobject>(j_service_); | 48 return base::android::ScopedJavaLocalRef<jobject>(j_service_); |
45 } | 49 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 instanceIdString, | 133 instanceIdString, |
130 BluetoothRemoteGattCharacteristicAndroid::Create(instanceIdString)); | 134 BluetoothRemoteGattCharacteristicAndroid::Create(instanceIdString)); |
131 } | 135 } |
132 | 136 |
133 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( | 137 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( |
134 BluetoothAdapterAndroid* adapter, | 138 BluetoothAdapterAndroid* adapter, |
135 BluetoothDeviceAndroid* device, | 139 BluetoothDeviceAndroid* device, |
136 const std::string& instanceId) | 140 const std::string& instanceId) |
137 : adapter_(adapter), device_(device), instanceId_(instanceId) {} | 141 : adapter_(adapter), device_(device), instanceId_(instanceId) {} |
138 | 142 |
139 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() { | |
140 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr
uction( | |
141 AttachCurrentThread(), j_service_.obj()); | |
142 } | |
143 | |
144 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { | 143 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { |
145 if (!characteristics_.empty()) | 144 if (!characteristics_.empty()) |
146 return; | 145 return; |
147 | 146 |
148 // Java call | 147 // Java call |
149 Java_ChromeBluetoothRemoteGattService_ensureCharacteristicsCreated( | 148 Java_ChromeBluetoothRemoteGattService_ensureCharacteristicsCreated( |
150 AttachCurrentThread(), j_service_.obj()); | 149 AttachCurrentThread(), j_service_.obj()); |
151 } | 150 } |
152 | 151 |
153 } // namespace device | 152 } // namespace device |
OLD | NEW |