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<BluetoothRemoteGattCharacteristic*> | |
454 BluetoothDevice::GetCharacteristicsByUUID( | |
455 const std::string& service_instance_id, | |
456 const BluetoothUUID& characteristic_uuid) { | |
457 std::vector<BluetoothRemoteGattCharacteristic*> characteristics; | |
458 VLOG(1) << "Looking for characteristic: " | |
scheib
2017/01/07 01:42:36
Change these VLOGs to be VLOG(2). Now that we're i
juncai
2017/01/09 19:29:19
Done.
| |
459 << characteristic_uuid.canonical_value(); | |
460 BluetoothRemoteGattService* service = GetGattService(service_instance_id); | |
461 if (service) { | |
462 for (BluetoothRemoteGattCharacteristic* characteristic : | |
463 service->GetCharacteristics()) { | |
464 VLOG(1) << "Characteristic in cache: " | |
465 << characteristic->GetUUID().canonical_value(); | |
466 if (characteristic->GetUUID() == characteristic_uuid) { | |
467 characteristics.push_back(characteristic); | |
468 } | |
469 } | |
470 } | |
471 return characteristics; | |
472 } | |
473 | |
474 std::vector<BluetoothRemoteGattService*> | |
475 BluetoothDevice::GetPrimaryServicesByUUID(const BluetoothUUID& service_uuid) { | |
476 std::vector<BluetoothRemoteGattService*> services; | |
477 VLOG(1) << "Looking for service: " << service_uuid.canonical_value(); | |
478 for (BluetoothRemoteGattService* service : GetGattServices()) { | |
479 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | |
480 if (service->GetUUID() == service_uuid && service->IsPrimary()) { | |
481 services.push_back(service); | |
482 } | |
483 } | |
484 return services; | |
485 } | |
486 | |
487 std::vector<BluetoothRemoteGattService*> BluetoothDevice::GetPrimaryServices() { | |
488 std::vector<BluetoothRemoteGattService*> services; | |
489 VLOG(1) << "Looking for services."; | |
490 for (BluetoothRemoteGattService* service : GetGattServices()) { | |
491 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | |
492 if (service->IsPrimary()) { | |
493 services.push_back(service); | |
494 } | |
495 } | |
496 return services; | |
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 |