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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return RegisterNativesImpl( | 48 return RegisterNativesImpl( |
49 env); // Generated in ChromeBluetoothRemoteGattService_jni.h | 49 env); // Generated in ChromeBluetoothRemoteGattService_jni.h |
50 } | 50 } |
51 | 51 |
52 base::android::ScopedJavaLocalRef<jobject> | 52 base::android::ScopedJavaLocalRef<jobject> |
53 BluetoothRemoteGattServiceAndroid::GetJavaObject() { | 53 BluetoothRemoteGattServiceAndroid::GetJavaObject() { |
54 return base::android::ScopedJavaLocalRef<jobject>(j_service_); | 54 return base::android::ScopedJavaLocalRef<jobject>(j_service_); |
55 } | 55 } |
56 | 56 |
57 // static | 57 // static |
58 BluetoothGattService::GattErrorCode | 58 BluetoothRemoteGattService::GattErrorCode |
59 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(int bluetooth_gatt_code) { | 59 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(int bluetooth_gatt_code) { |
60 DCHECK(bluetooth_gatt_code != 0) << "Only errors valid. 0 == GATT_SUCCESS."; | 60 DCHECK(bluetooth_gatt_code != 0) << "Only errors valid. 0 == GATT_SUCCESS."; |
61 | 61 |
62 // TODO(scheib) Create new BluetoothGattService::GattErrorCode enums for | 62 // TODO(scheib) Create new BluetoothRemoteGattService::GattErrorCode enums for |
63 // android values not yet represented. http://crbug.com/548498 | 63 // android values not yet represented. http://crbug.com/548498 |
64 switch (bluetooth_gatt_code) { // android.bluetooth.BluetoothGatt values: | 64 switch (bluetooth_gatt_code) { // android.bluetooth.BluetoothGatt values: |
65 case 0x00000101: // GATT_FAILURE | 65 case 0x00000101: // GATT_FAILURE |
66 return GATT_ERROR_FAILED; | 66 return GATT_ERROR_FAILED; |
67 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH | 67 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH |
68 return GATT_ERROR_INVALID_LENGTH; | 68 return GATT_ERROR_INVALID_LENGTH; |
69 case 0x00000002: // GATT_READ_NOT_PERMITTED | 69 case 0x00000002: // GATT_READ_NOT_PERMITTED |
70 return GATT_ERROR_NOT_PERMITTED; | 70 return GATT_ERROR_NOT_PERMITTED; |
71 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED | 71 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED |
72 return GATT_ERROR_NOT_SUPPORTED; | 72 return GATT_ERROR_NOT_SUPPORTED; |
73 case 0x00000003: // GATT_WRITE_NOT_PERMITTED | 73 case 0x00000003: // GATT_WRITE_NOT_PERMITTED |
74 return GATT_ERROR_NOT_PERMITTED; | 74 return GATT_ERROR_NOT_PERMITTED; |
75 default: | 75 default: |
76 VLOG(1) << "Unhandled status: " << bluetooth_gatt_code; | 76 VLOG(1) << "Unhandled status: " << bluetooth_gatt_code; |
77 return BluetoothGattService::GATT_ERROR_UNKNOWN; | 77 return BluetoothRemoteGattService::GATT_ERROR_UNKNOWN; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 // static | 81 // static |
82 int BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode( | 82 int BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode( |
83 BluetoothGattService::GattErrorCode error_code) { | 83 BluetoothRemoteGattService::GattErrorCode error_code) { |
84 // TODO(scheib) Create new BluetoothGattService::GattErrorCode enums for | 84 // TODO(scheib) Create new BluetoothRemoteGattService::GattErrorCode enums for |
85 // android values not yet represented. http://crbug.com/548498 | 85 // android values not yet represented. http://crbug.com/548498 |
86 switch (error_code) { // Return values from android.bluetooth.BluetoothGatt: | 86 switch (error_code) { // Return values from android.bluetooth.BluetoothGatt: |
87 case GATT_ERROR_UNKNOWN: | 87 case GATT_ERROR_UNKNOWN: |
88 return 0x00000101; // GATT_FAILURE. No good match. | 88 return 0x00000101; // GATT_FAILURE. No good match. |
89 case GATT_ERROR_FAILED: | 89 case GATT_ERROR_FAILED: |
90 return 0x00000101; // GATT_FAILURE | 90 return 0x00000101; // GATT_FAILURE |
91 case GATT_ERROR_IN_PROGRESS: | 91 case GATT_ERROR_IN_PROGRESS: |
92 return 0x00000101; // GATT_FAILURE. No good match. | 92 return 0x00000101; // GATT_FAILURE. No good match. |
93 case GATT_ERROR_INVALID_LENGTH: | 93 case GATT_ERROR_INVALID_LENGTH: |
94 return 0x0000000d; // GATT_INVALID_ATTRIBUTE_LENGTH | 94 return 0x0000000d; // GATT_INVALID_ATTRIBUTE_LENGTH |
(...skipping 29 matching lines...) Expand all Loading... |
124 | 124 |
125 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { | 125 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { |
126 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { | 130 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { |
131 return device_; | 131 return device_; |
132 } | 132 } |
133 | 133 |
134 std::vector<device::BluetoothGattCharacteristic*> | 134 std::vector<device::BluetoothRemoteGattCharacteristic*> |
135 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const { | 135 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const { |
136 EnsureCharacteristicsCreated(); | 136 EnsureCharacteristicsCreated(); |
137 std::vector<device::BluetoothGattCharacteristic*> characteristics; | 137 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
138 for (const auto& map_iter : characteristics_) | 138 for (const auto& map_iter : characteristics_) |
139 characteristics.push_back(map_iter.second); | 139 characteristics.push_back(map_iter.second); |
140 return characteristics; | 140 return characteristics; |
141 } | 141 } |
142 | 142 |
143 std::vector<device::BluetoothGattService*> | 143 std::vector<device::BluetoothRemoteGattService*> |
144 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const { | 144 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const { |
145 NOTIMPLEMENTED(); | 145 NOTIMPLEMENTED(); |
146 return std::vector<device::BluetoothGattService*>(); | 146 return std::vector<device::BluetoothRemoteGattService*>(); |
147 } | 147 } |
148 | 148 |
149 device::BluetoothGattCharacteristic* | 149 device::BluetoothRemoteGattCharacteristic* |
150 BluetoothRemoteGattServiceAndroid::GetCharacteristic( | 150 BluetoothRemoteGattServiceAndroid::GetCharacteristic( |
151 const std::string& identifier) const { | 151 const std::string& identifier) const { |
152 EnsureCharacteristicsCreated(); | 152 EnsureCharacteristicsCreated(); |
153 const auto& iter = characteristics_.find(identifier); | 153 const auto& iter = characteristics_.find(identifier); |
154 if (iter == characteristics_.end()) | 154 if (iter == characteristics_.end()) |
155 return nullptr; | 155 return nullptr; |
156 return iter->second; | 156 return iter->second; |
157 } | 157 } |
158 | 158 |
159 bool BluetoothRemoteGattServiceAndroid::AddCharacteristic( | 159 bool BluetoothRemoteGattServiceAndroid::AddCharacteristic( |
160 device::BluetoothGattCharacteristic* characteristic) { | 160 device::BluetoothRemoteGattCharacteristic* characteristic) { |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 bool BluetoothRemoteGattServiceAndroid::AddIncludedService( | 164 bool BluetoothRemoteGattServiceAndroid::AddIncludedService( |
165 device::BluetoothGattService* service) { | 165 device::BluetoothRemoteGattService* service) { |
166 return false; | 166 return false; |
167 } | 167 } |
168 | 168 |
169 void BluetoothRemoteGattServiceAndroid::Register( | 169 void BluetoothRemoteGattServiceAndroid::Register( |
170 const base::Closure& callback, | 170 const base::Closure& callback, |
171 const ErrorCallback& error_callback) { | 171 const ErrorCallback& error_callback) { |
172 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); | 172 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); |
173 } | 173 } |
174 | 174 |
175 void BluetoothRemoteGattServiceAndroid::Unregister( | 175 void BluetoothRemoteGattServiceAndroid::Unregister( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { | 207 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { |
208 if (!characteristics_.empty()) | 208 if (!characteristics_.empty()) |
209 return; | 209 return; |
210 | 210 |
211 // Java call | 211 // Java call |
212 Java_ChromeBluetoothRemoteGattService_createCharacteristics( | 212 Java_ChromeBluetoothRemoteGattService_createCharacteristics( |
213 AttachCurrentThread(), j_service_.obj()); | 213 AttachCurrentThread(), j_service_.obj()); |
214 } | 214 } |
215 | 215 |
216 } // namespace device | 216 } // namespace device |
OLD | NEW |