OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bluez/bluetooth_device_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 UUIDSet uuids; | 368 UUIDSet uuids; |
369 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); | 369 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); |
370 for (const std::string& dbus_uuid : dbus_uuids) { | 370 for (const std::string& dbus_uuid : dbus_uuids) { |
371 device::BluetoothUUID uuid(dbus_uuid); | 371 device::BluetoothUUID uuid(dbus_uuid); |
372 DCHECK(uuid.IsValid()); | 372 DCHECK(uuid.IsValid()); |
373 uuids.insert(std::move(uuid)); | 373 uuids.insert(std::move(uuid)); |
374 } | 374 } |
375 return uuids; | 375 return uuids; |
376 } | 376 } |
377 | 377 |
378 BluetoothDevice::UUIDSet BluetoothDeviceBlueZ::GetServiceDataUUIDs() const { | |
379 bluez::BluetoothDeviceClient::Properties* properties = | |
380 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | |
381 object_path_); | |
382 DCHECK(properties); | |
383 | |
384 UUIDSet uuids; | |
385 | |
386 if (!properties->service_data.is_valid()) | |
387 return uuids; | |
388 | |
389 for (const auto& pair : properties->service_data.value()) { | |
390 device::BluetoothUUID uuid(pair.first); | |
391 DCHECK(uuid.IsValid()); | |
392 uuids.insert(std::move(uuid)); | |
393 } | |
394 | |
395 return uuids; | |
396 } | |
397 | |
398 const std::vector<uint8_t>* BluetoothDeviceBlueZ::GetServiceDataForUUID( | |
399 const BluetoothUUID& uuid) const { | |
400 bluez::BluetoothDeviceClient::Properties* properties = | |
401 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | |
402 object_path_); | |
403 DCHECK(properties); | |
404 | |
405 if (!properties->service_data.is_valid()) | |
406 return nullptr; | |
407 | |
408 const auto& dbus_service_data = properties->service_data.value(); | |
409 auto it = std::find_if( | |
410 dbus_service_data.begin(), dbus_service_data.end(), | |
411 [&uuid](const std::pair<std::string, std::vector<uint8_t>>& entry) { | |
412 return uuid.canonical_value() == | |
413 device::BluetoothUUID(entry.first).canonical_value(); | |
414 }); | |
415 | |
416 if (it == dbus_service_data.end()) | |
417 return nullptr; | |
418 | |
419 return &it->second; | |
420 } | |
421 | |
378 base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryRSSI() const { | 422 base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
379 bluez::BluetoothDeviceClient::Properties* properties = | 423 bluez::BluetoothDeviceClient::Properties* properties = |
380 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 424 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
381 object_path_); | 425 object_path_); |
382 DCHECK(properties); | 426 DCHECK(properties); |
383 | 427 |
384 if (!properties->rssi.is_valid()) | 428 if (!properties->rssi.is_valid()) |
385 return base::nullopt; | 429 return base::nullopt; |
386 | 430 |
387 // BlueZ uses int16_t because there is no int8_t for DBus, so we should never | 431 // BlueZ uses int16_t because there is no int8_t for DBus, so we should never |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 base::Bind(&BluetoothDeviceBlueZ::OnConnectError, | 792 base::Bind(&BluetoothDeviceBlueZ::OnConnectError, |
749 weak_ptr_factory_.GetWeakPtr(), after_pairing, | 793 weak_ptr_factory_.GetWeakPtr(), after_pairing, |
750 error_callback)); | 794 error_callback)); |
751 } | 795 } |
752 | 796 |
753 void BluetoothDeviceBlueZ::OnConnect(bool after_pairing, | 797 void BluetoothDeviceBlueZ::OnConnect(bool after_pairing, |
754 const base::Closure& callback) { | 798 const base::Closure& callback) { |
755 if (--num_connecting_calls_ == 0) | 799 if (--num_connecting_calls_ == 0) |
756 adapter()->NotifyDeviceChanged(this); | 800 adapter()->NotifyDeviceChanged(this); |
757 | 801 |
758 DCHECK(num_connecting_calls_ >= 0); | 802 DCHECK_GE(num_connecting_calls_, 0); |
Rahul Chaturvedi
2016/09/27 20:52:59
Cleanup should be in its own CL. Usually conflatin
puthik_chromium
2016/09/27 21:04:07
Acknowledged.
Will fix this once I got your full c
puthik_chromium
2016/10/06 01:49:56
Done.
| |
759 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ | 803 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ |
760 << " still in progress"; | 804 << " still in progress"; |
761 | 805 |
762 SetTrusted(); | 806 SetTrusted(); |
763 | 807 |
764 if (after_pairing) | 808 if (after_pairing) |
765 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", | 809 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", |
766 UMA_PAIRING_RESULT_SUCCESS, | 810 UMA_PAIRING_RESULT_SUCCESS, |
767 UMA_PAIRING_RESULT_COUNT); | 811 UMA_PAIRING_RESULT_COUNT); |
768 | 812 |
769 callback.Run(); | 813 callback.Run(); |
770 } | 814 } |
771 | 815 |
772 void BluetoothDeviceBlueZ::OnCreateGattConnection( | 816 void BluetoothDeviceBlueZ::OnCreateGattConnection( |
773 const GattConnectionCallback& callback) { | 817 const GattConnectionCallback& callback) { |
774 std::unique_ptr<device::BluetoothGattConnection> conn( | 818 std::unique_ptr<device::BluetoothGattConnection> conn( |
775 new BluetoothGattConnectionBlueZ(adapter_, GetAddress(), object_path_)); | 819 new BluetoothGattConnectionBlueZ(adapter_, GetAddress(), object_path_)); |
776 callback.Run(std::move(conn)); | 820 callback.Run(std::move(conn)); |
777 } | 821 } |
778 | 822 |
779 void BluetoothDeviceBlueZ::OnConnectError( | 823 void BluetoothDeviceBlueZ::OnConnectError( |
780 bool after_pairing, | 824 bool after_pairing, |
781 const ConnectErrorCallback& error_callback, | 825 const ConnectErrorCallback& error_callback, |
782 const std::string& error_name, | 826 const std::string& error_name, |
783 const std::string& error_message) { | 827 const std::string& error_message) { |
784 if (--num_connecting_calls_ == 0) | 828 if (--num_connecting_calls_ == 0) |
785 adapter()->NotifyDeviceChanged(this); | 829 adapter()->NotifyDeviceChanged(this); |
786 | 830 |
787 DCHECK(num_connecting_calls_ >= 0); | 831 DCHECK_GE(num_connecting_calls_, 0); |
788 LOG(WARNING) << object_path_.value() | 832 LOG(WARNING) << object_path_.value() |
789 << ": Failed to connect device: " << error_name << ": " | 833 << ": Failed to connect device: " << error_name << ": " |
790 << error_message; | 834 << error_message; |
791 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 835 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ |
792 << " still in progress"; | 836 << " still in progress"; |
793 | 837 |
794 // Determine the error code from error_name. | 838 // Determine the error code from error_name. |
795 ConnectErrorCode error_code = ERROR_UNKNOWN; | 839 ConnectErrorCode error_code = ERROR_UNKNOWN; |
796 if (error_name == bluetooth_device::kErrorFailed) { | 840 if (error_name == bluetooth_device::kErrorFailed) { |
797 error_code = ERROR_FAILED; | 841 error_code = ERROR_FAILED; |
(...skipping 18 matching lines...) Expand all Loading... | |
816 ConnectInternal(true, callback, error_callback); | 860 ConnectInternal(true, callback, error_callback); |
817 } | 861 } |
818 | 862 |
819 void BluetoothDeviceBlueZ::OnPairDuringConnectError( | 863 void BluetoothDeviceBlueZ::OnPairDuringConnectError( |
820 const ConnectErrorCallback& error_callback, | 864 const ConnectErrorCallback& error_callback, |
821 const std::string& error_name, | 865 const std::string& error_name, |
822 const std::string& error_message) { | 866 const std::string& error_message) { |
823 if (--num_connecting_calls_ == 0) | 867 if (--num_connecting_calls_ == 0) |
824 adapter()->NotifyDeviceChanged(this); | 868 adapter()->NotifyDeviceChanged(this); |
825 | 869 |
826 DCHECK(num_connecting_calls_ >= 0); | 870 DCHECK_GE(num_connecting_calls_, 0); |
827 LOG(WARNING) << object_path_.value() | 871 LOG(WARNING) << object_path_.value() |
828 << ": Failed to pair device: " << error_name << ": " | 872 << ": Failed to pair device: " << error_name << ": " |
829 << error_message; | 873 << error_message; |
830 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 874 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ |
831 << " still in progress"; | 875 << " still in progress"; |
832 | 876 |
833 EndPairing(); | 877 EndPairing(); |
834 | 878 |
835 // Determine the error code from error_name. | 879 // Determine the error code from error_name. |
836 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); | 880 ConnectErrorCode error_code = DBusErrorToConnectError(error_name); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 945 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
902 const std::string& error_name, | 946 const std::string& error_name, |
903 const std::string& error_message) { | 947 const std::string& error_message) { |
904 LOG(WARNING) << object_path_.value() | 948 LOG(WARNING) << object_path_.value() |
905 << ": Failed to remove device: " << error_name << ": " | 949 << ": Failed to remove device: " << error_name << ": " |
906 << error_message; | 950 << error_message; |
907 error_callback.Run(); | 951 error_callback.Run(); |
908 } | 952 } |
909 | 953 |
910 } // namespace bluez | 954 } // namespace bluez |
OLD | NEW |