| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_device.h" | 5 #include "device/bluetooth/bluetooth_device.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_gatt_connection.h" | 17 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 19 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 19 #include "device/bluetooth/string_util_icu.h" | 20 #include "device/bluetooth/string_util_icu.h" |
| 20 #include "grit/bluetooth_strings.h" | 21 #include "grit/bluetooth_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 namespace device { | 24 namespace device { |
| 24 | 25 |
| 25 BluetoothDevice::DeviceUUIDs::DeviceUUIDs() = default; | 26 BluetoothDevice::DeviceUUIDs::DeviceUUIDs() = default; |
| 26 | 27 |
| 27 BluetoothDevice::DeviceUUIDs::~DeviceUUIDs() = default; | 28 BluetoothDevice::DeviceUUIDs::~DeviceUUIDs() = default; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 443 } |
| 443 | 444 |
| 444 void BluetoothDevice::ClearAdvertisementData() { | 445 void BluetoothDevice::ClearAdvertisementData() { |
| 445 inquiry_rssi_ = base::nullopt; | 446 inquiry_rssi_ = base::nullopt; |
| 446 device_uuids_.ClearAdvertisedUUIDs(); | 447 device_uuids_.ClearAdvertisedUUIDs(); |
| 447 service_data_.clear(); | 448 service_data_.clear(); |
| 448 inquiry_tx_power_ = base::nullopt; | 449 inquiry_tx_power_ = base::nullopt; |
| 449 GetAdapter()->NotifyDeviceChanged(this); | 450 GetAdapter()->NotifyDeviceChanged(this); |
| 450 } | 451 } |
| 451 | 452 |
| 453 std::vector<BluetoothRemoteGattService*> BluetoothDevice::GetPrimaryServices() { |
| 454 std::vector<BluetoothRemoteGattService*> services; |
| 455 VLOG(2) << "Looking for services."; |
| 456 for (BluetoothRemoteGattService* service : GetGattServices()) { |
| 457 VLOG(2) << "Service in cache: " << service->GetUUID().canonical_value(); |
| 458 if (service->IsPrimary()) { |
| 459 services.push_back(service); |
| 460 } |
| 461 } |
| 462 return services; |
| 463 } |
| 464 |
| 465 std::vector<BluetoothRemoteGattService*> |
| 466 BluetoothDevice::GetPrimaryServicesByUUID(const BluetoothUUID& service_uuid) { |
| 467 std::vector<BluetoothRemoteGattService*> services; |
| 468 VLOG(2) << "Looking for service: " << service_uuid.canonical_value(); |
| 469 for (BluetoothRemoteGattService* service : GetGattServices()) { |
| 470 VLOG(2) << "Service in cache: " << service->GetUUID().canonical_value(); |
| 471 if (service->GetUUID() == service_uuid && service->IsPrimary()) { |
| 472 services.push_back(service); |
| 473 } |
| 474 } |
| 475 return services; |
| 476 } |
| 477 |
| 478 std::vector<BluetoothRemoteGattCharacteristic*> |
| 479 BluetoothDevice::GetCharacteristicsByUUID( |
| 480 const std::string& service_instance_id, |
| 481 const BluetoothUUID& characteristic_uuid) { |
| 482 std::vector<BluetoothRemoteGattCharacteristic*> characteristics; |
| 483 VLOG(2) << "Looking for characteristic: " |
| 484 << characteristic_uuid.canonical_value(); |
| 485 BluetoothRemoteGattService* service = GetGattService(service_instance_id); |
| 486 if (service) { |
| 487 for (BluetoothRemoteGattCharacteristic* characteristic : |
| 488 service->GetCharacteristics()) { |
| 489 VLOG(2) << "Characteristic in cache: " |
| 490 << characteristic->GetUUID().canonical_value(); |
| 491 if (characteristic->GetUUID() == characteristic_uuid) { |
| 492 characteristics.push_back(characteristic); |
| 493 } |
| 494 } |
| 495 } |
| 496 return characteristics; |
| 497 } |
| 498 |
| 452 void BluetoothDevice::DidConnectGatt() { | 499 void BluetoothDevice::DidConnectGatt() { |
| 453 for (const auto& callback : create_gatt_connection_success_callbacks_) { | 500 for (const auto& callback : create_gatt_connection_success_callbacks_) { |
| 454 callback.Run( | 501 callback.Run( |
| 455 base::MakeUnique<BluetoothGattConnection>(adapter_, GetAddress())); | 502 base::MakeUnique<BluetoothGattConnection>(adapter_, GetAddress())); |
| 456 } | 503 } |
| 457 create_gatt_connection_success_callbacks_.clear(); | 504 create_gatt_connection_success_callbacks_.clear(); |
| 458 create_gatt_connection_error_callbacks_.clear(); | 505 create_gatt_connection_error_callbacks_.clear(); |
| 459 GetAdapter()->NotifyDeviceChanged(this); | 506 GetAdapter()->NotifyDeviceChanged(this); |
| 460 } | 507 } |
| 461 | 508 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (power < INT8_MIN) { | 568 if (power < INT8_MIN) { |
| 522 return INT8_MIN; | 569 return INT8_MIN; |
| 523 } | 570 } |
| 524 if (power > INT8_MAX) { | 571 if (power > INT8_MAX) { |
| 525 return INT8_MAX; | 572 return INT8_MAX; |
| 526 } | 573 } |
| 527 return static_cast<int8_t>(power); | 574 return static_cast<int8_t>(power); |
| 528 } | 575 } |
| 529 | 576 |
| 530 } // namespace device | 577 } // namespace device |
| OLD | NEW |