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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 jobject /* BluetoothGattServiceWrapper */ bluetooth_gatt_service_wrapper, | 26 jobject /* BluetoothGattServiceWrapper */ bluetooth_gatt_service_wrapper, |
27 const std::string& instance_id, | 27 const std::string& instance_id, |
28 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { | 28 jobject /* ChromeBluetoothDevice */ chrome_bluetooth_device) { |
29 std::unique_ptr<BluetoothRemoteGattServiceAndroid> service( | 29 std::unique_ptr<BluetoothRemoteGattServiceAndroid> service( |
30 new BluetoothRemoteGattServiceAndroid(adapter, device, instance_id)); | 30 new BluetoothRemoteGattServiceAndroid(adapter, device, instance_id)); |
31 | 31 |
32 JNIEnv* env = AttachCurrentThread(); | 32 JNIEnv* env = AttachCurrentThread(); |
33 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create( | 33 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create( |
34 env, reinterpret_cast<intptr_t>(service.get()), | 34 env, reinterpret_cast<intptr_t>(service.get()), |
35 bluetooth_gatt_service_wrapper, | 35 bluetooth_gatt_service_wrapper, |
36 base::android::ConvertUTF8ToJavaString(env, instance_id).obj(), | 36 base::android::ConvertUTF8ToJavaString(env, instance_id), |
37 chrome_bluetooth_device)); | 37 chrome_bluetooth_device)); |
38 | 38 |
39 return service; | 39 return service; |
40 } | 40 } |
41 | 41 |
42 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() { | 42 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() { |
43 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr
uction( | 43 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr
uction( |
44 AttachCurrentThread(), j_service_.obj()); | 44 AttachCurrentThread(), j_service_); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) { | 48 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) { |
49 return RegisterNativesImpl( | 49 return RegisterNativesImpl( |
50 env); // Generated in ChromeBluetoothRemoteGattService_jni.h | 50 env); // Generated in ChromeBluetoothRemoteGattService_jni.h |
51 } | 51 } |
52 | 52 |
53 base::android::ScopedJavaLocalRef<jobject> | 53 base::android::ScopedJavaLocalRef<jobject> |
54 BluetoothRemoteGattServiceAndroid::GetJavaObject() { | 54 BluetoothRemoteGattServiceAndroid::GetJavaObject() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return 0x00000101; // GATT_FAILURE. No good match. | 109 return 0x00000101; // GATT_FAILURE. No good match. |
110 } | 110 } |
111 | 111 |
112 std::string BluetoothRemoteGattServiceAndroid::GetIdentifier() const { | 112 std::string BluetoothRemoteGattServiceAndroid::GetIdentifier() const { |
113 return instance_id_; | 113 return instance_id_; |
114 } | 114 } |
115 | 115 |
116 device::BluetoothUUID BluetoothRemoteGattServiceAndroid::GetUUID() const { | 116 device::BluetoothUUID BluetoothRemoteGattServiceAndroid::GetUUID() const { |
117 return device::BluetoothUUID( | 117 return device::BluetoothUUID( |
118 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattService_getUUID( | 118 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattService_getUUID( |
119 AttachCurrentThread(), j_service_.obj()))); | 119 AttachCurrentThread(), j_service_))); |
120 } | 120 } |
121 | 121 |
122 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { | 122 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { |
123 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
124 return true; | 124 return true; |
125 } | 125 } |
126 | 126 |
127 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { | 127 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { |
128 return device_; | 128 return device_; |
129 } | 129 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 BluetoothDeviceAndroid* device, | 178 BluetoothDeviceAndroid* device, |
179 const std::string& instance_id) | 179 const std::string& instance_id) |
180 : adapter_(adapter), device_(device), instance_id_(instance_id) {} | 180 : adapter_(adapter), device_(device), instance_id_(instance_id) {} |
181 | 181 |
182 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { | 182 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { |
183 if (!characteristics_.empty()) | 183 if (!characteristics_.empty()) |
184 return; | 184 return; |
185 | 185 |
186 // Java call | 186 // Java call |
187 Java_ChromeBluetoothRemoteGattService_createCharacteristics( | 187 Java_ChromeBluetoothRemoteGattService_createCharacteristics( |
188 AttachCurrentThread(), j_service_.obj()); | 188 AttachCurrentThread(), j_service_); |
189 } | 189 } |
190 | 190 |
191 } // namespace device | 191 } // namespace device |
OLD | NEW |