Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_android.cc

Issue 1412963004: bluetooth: android: Implement Characteristic GetIdentifier, fix Service IDs too. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_android.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_remote_gatt_service_wrapper,
23 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 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create( 28 service->j_service_.Reset(Java_ChromeBluetoothRemoteGattService_create(
28 AttachCurrentThread(), reinterpret_cast<intptr_t>(service), 29 env, reinterpret_cast<intptr_t>(service),
29 bluetooth_remote_gatt_service_wrapper)); 30 bluetooth_remote_gatt_service_wrapper,
31 base::android::ConvertUTF8ToJavaString(env, instanceId).obj()));
30 32
31 return service; 33 return service;
32 } 34 }
33 35
34 // static 36 // static
35 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) { 37 bool BluetoothRemoteGattServiceAndroid::RegisterJNI(JNIEnv* env) {
36 return RegisterNativesImpl( 38 return RegisterNativesImpl(
37 env); // Generated in ChromeBluetoothRemoteGattService_jni.h 39 env); // Generated in ChromeBluetoothRemoteGattService_jni.h
38 } 40 }
39 41
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 JNIEnv* env, 118 JNIEnv* env,
117 jobject caller, 119 jobject caller,
118 const jstring& instanceId, 120 const jstring& instanceId,
119 jobject /* BluetoothGattCharacteristicWrapper */ 121 jobject /* BluetoothGattCharacteristicWrapper */
120 bluetooth_gatt_characteristic_wrapper) { 122 bluetooth_gatt_characteristic_wrapper) {
121 std::string instanceIdString = 123 std::string instanceIdString =
122 base::android::ConvertJavaStringToUTF8(env, instanceId); 124 base::android::ConvertJavaStringToUTF8(env, instanceId);
123 125
124 DCHECK(!characteristics_.contains(instanceIdString)); 126 DCHECK(!characteristics_.contains(instanceIdString));
125 127
126 characteristics_.set(instanceIdString, 128 characteristics_.set(
127 BluetoothRemoteGattCharacteristicAndroid::Create()); 129 instanceIdString,
130 BluetoothRemoteGattCharacteristicAndroid::Create(instanceIdString));
128 } 131 }
129 132
130 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid( 133 BluetoothRemoteGattServiceAndroid::BluetoothRemoteGattServiceAndroid(
131 BluetoothAdapterAndroid* adapter, 134 BluetoothAdapterAndroid* adapter,
132 BluetoothDeviceAndroid* device, 135 BluetoothDeviceAndroid* device,
133 std::string instanceId) 136 const std::string& instanceId)
134 : adapter_(adapter), device_(device), instanceId_(instanceId) {} 137 : adapter_(adapter), device_(device), instanceId_(instanceId) {}
135 138
136 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() { 139 BluetoothRemoteGattServiceAndroid::~BluetoothRemoteGattServiceAndroid() {
137 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr uction( 140 Java_ChromeBluetoothRemoteGattService_onBluetoothRemoteGattServiceAndroidDestr uction(
138 AttachCurrentThread(), j_service_.obj()); 141 AttachCurrentThread(), j_service_.obj());
139 } 142 }
140 143
141 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { 144 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const {
142 if (!characteristics_.empty()) 145 if (!characteristics_.empty())
143 return; 146 return;
144 147
145 // Java call 148 // Java call
146 Java_ChromeBluetoothRemoteGattService_ensureCharacteristicsCreated( 149 Java_ChromeBluetoothRemoteGattService_ensureCharacteristicsCreated(
147 AttachCurrentThread(), j_service_.obj()); 150 AttachCurrentThread(), j_service_.obj());
148 } 151 }
149 152
150 } // namespace device 153 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_android.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698