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

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

Issue 2649473002: bluetooth: Add control for reading/writing of descriptor values to internals page. (Closed)
Patch Set: Merge upstream Created 3 years, 10 months 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/device.h ('k') | device/bluetooth/public/interfaces/device.mojom » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/device.h" 10 #include "device/bluetooth/device.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return; 206 return;
207 } 207 }
208 208
209 std::vector<mojom::DescriptorInfoPtr> descriptors; 209 std::vector<mojom::DescriptorInfoPtr> descriptors;
210 210
211 for (const auto* descriptor : characteristic->GetDescriptors()) { 211 for (const auto* descriptor : characteristic->GetDescriptors()) {
212 mojom::DescriptorInfoPtr descriptor_info = mojom::DescriptorInfo::New(); 212 mojom::DescriptorInfoPtr descriptor_info = mojom::DescriptorInfo::New();
213 213
214 descriptor_info->id = descriptor->GetIdentifier(); 214 descriptor_info->id = descriptor->GetIdentifier();
215 descriptor_info->uuid = descriptor->GetUUID(); 215 descriptor_info->uuid = descriptor->GetUUID();
216 descriptor_info->last_known_value = descriptor->GetValue();
217
216 descriptors.push_back(std::move(descriptor_info)); 218 descriptors.push_back(std::move(descriptor_info));
217 } 219 }
218 220
219 callback.Run(std::move(descriptors)); 221 callback.Run(std::move(descriptors));
220 } 222 }
221 223
224 void Device::ReadValueForDescriptor(
225 const std::string& service_id,
226 const std::string& characteristic_id,
227 const std::string& descriptor_id,
228 const ReadValueForDescriptorCallback& callback) {
229 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
230 DCHECK(device);
231
232 device::BluetoothRemoteGattService* service =
233 device->GetGattService(service_id);
234 if (!service) {
235 callback.Run(mojom::GattResult::SERVICE_NOT_FOUND,
236 base::nullopt /* value */);
237 return;
238 }
239
240 device::BluetoothRemoteGattCharacteristic* characteristic =
241 service->GetCharacteristic(characteristic_id);
242 if (!characteristic) {
243 callback.Run(mojom::GattResult::CHARACTERISTIC_NOT_FOUND,
244 base::nullopt /* value */);
245 return;
246 }
247
248 device::BluetoothRemoteGattDescriptor* descriptor =
249 characteristic->GetDescriptor(descriptor_id);
250 if (!descriptor) {
251 callback.Run(mojom::GattResult::DESCRIPTOR_NOT_FOUND,
252 base::nullopt /* value */);
253 return;
254 }
255
256 descriptor->ReadRemoteDescriptor(
257 base::Bind(&Device::OnReadRemoteDescriptor,
258 weak_ptr_factory_.GetWeakPtr(), callback),
259 base::Bind(&Device::OnReadRemoteDescriptorError,
260 weak_ptr_factory_.GetWeakPtr(), callback));
261 }
262
263 void Device::WriteValueForDescriptor(
264 const std::string& service_id,
265 const std::string& characteristic_id,
266 const std::string& descriptor_id,
267 const std::vector<uint8_t>& value,
268 const WriteValueForDescriptorCallback& callback) {
269 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
270 DCHECK(device);
271
272 device::BluetoothRemoteGattService* service =
273 device->GetGattService(service_id);
274 if (!service) {
275 callback.Run(mojom::GattResult::SERVICE_NOT_FOUND);
276 return;
277 }
278
279 device::BluetoothRemoteGattCharacteristic* characteristic =
280 service->GetCharacteristic(characteristic_id);
281 if (!characteristic) {
282 callback.Run(mojom::GattResult::CHARACTERISTIC_NOT_FOUND);
283 return;
284 }
285
286 device::BluetoothRemoteGattDescriptor* descriptor =
287 characteristic->GetDescriptor(descriptor_id);
288 if (!descriptor) {
289 callback.Run(mojom::GattResult::DESCRIPTOR_NOT_FOUND);
290 return;
291 }
292
293 descriptor->WriteRemoteDescriptor(
294 value, base::Bind(&Device::OnWriteRemoteDescriptor,
295 weak_ptr_factory_.GetWeakPtr(), callback),
296 base::Bind(&Device::OnWriteRemoteDescriptorError,
297 weak_ptr_factory_.GetWeakPtr(), callback));
298 }
299
222 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, 300 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
223 std::unique_ptr<device::BluetoothGattConnection> connection) 301 std::unique_ptr<device::BluetoothGattConnection> connection)
224 : adapter_(std::move(adapter)), 302 : adapter_(std::move(adapter)),
225 connection_(std::move(connection)), 303 connection_(std::move(connection)),
226 weak_ptr_factory_(this) { 304 weak_ptr_factory_(this) {
227 adapter_->AddObserver(this); 305 adapter_->AddObserver(this);
228 } 306 }
229 307
230 void Device::GetServicesImpl(const GetServicesCallback& callback) { 308 void Device::GetServicesImpl(const GetServicesCallback& callback) {
231 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); 309 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 const WriteValueForCharacteristicCallback& callback) { 347 const WriteValueForCharacteristicCallback& callback) {
270 callback.Run(mojom::GattResult::SUCCESS); 348 callback.Run(mojom::GattResult::SUCCESS);
271 } 349 }
272 350
273 void Device::OnWriteRemoteCharacteristicError( 351 void Device::OnWriteRemoteCharacteristicError(
274 const WriteValueForCharacteristicCallback& callback, 352 const WriteValueForCharacteristicCallback& callback,
275 device::BluetoothGattService::GattErrorCode error_code) { 353 device::BluetoothGattService::GattErrorCode error_code) {
276 callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code)); 354 callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code));
277 } 355 }
278 356
357 void Device::OnReadRemoteDescriptor(
358 const ReadValueForDescriptorCallback& callback,
359 const std::vector<uint8_t>& value) {
360 callback.Run(mojom::GattResult::SUCCESS, std::move(value));
361 }
362
363 void Device::OnReadRemoteDescriptorError(
364 const ReadValueForDescriptorCallback& callback,
365 device::BluetoothGattService::GattErrorCode error_code) {
366 callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code),
367 base::nullopt /* value */);
368 }
369
370 void Device::OnWriteRemoteDescriptor(
371 const WriteValueForDescriptorCallback& callback) {
372 callback.Run(mojom::GattResult::SUCCESS);
373 }
374
375 void Device::OnWriteRemoteDescriptorError(
376 const WriteValueForDescriptorCallback& callback,
377 device::BluetoothGattService::GattErrorCode error_code) {
378 callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code));
379 }
380
279 const std::string& Device::GetAddress() { 381 const std::string& Device::GetAddress() {
280 return connection_->GetDeviceAddress(); 382 return connection_->GetDeviceAddress();
281 } 383 }
282 384
283 } // namespace bluetooth 385 } // namespace bluetooth
OLDNEW
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/public/interfaces/device.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698