| 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 <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } else if (error_name == bluetooth_device::kErrorAuthenticationCanceled) { | 130 } else if (error_name == bluetooth_device::kErrorAuthenticationCanceled) { |
| 131 error_code = BluetoothDevice::ERROR_AUTH_CANCELED; | 131 error_code = BluetoothDevice::ERROR_AUTH_CANCELED; |
| 132 } else if (error_name == bluetooth_device::kErrorAuthenticationRejected) { | 132 } else if (error_name == bluetooth_device::kErrorAuthenticationRejected) { |
| 133 error_code = BluetoothDevice::ERROR_AUTH_REJECTED; | 133 error_code = BluetoothDevice::ERROR_AUTH_REJECTED; |
| 134 } else if (error_name == bluetooth_device::kErrorAuthenticationTimeout) { | 134 } else if (error_name == bluetooth_device::kErrorAuthenticationTimeout) { |
| 135 error_code = BluetoothDevice::ERROR_AUTH_TIMEOUT; | 135 error_code = BluetoothDevice::ERROR_AUTH_TIMEOUT; |
| 136 } | 136 } |
| 137 return error_code; | 137 return error_code; |
| 138 } | 138 } |
| 139 | 139 |
| 140 int8_t EnsureValidRSSI(int16_t rssi) { |
| 141 return ((rssi < -128) || (rssi > 127)) ? BluetoothDevice::kUnknownRSSI : rssi; |
| 142 } |
| 143 |
| 144 int8_t EnsureValidTxPower(int16_t tx_power) { |
| 145 return ((tx_power < -127) || (tx_power > 127)) |
| 146 ? BluetoothDevice::kUnknownTxPower |
| 147 : tx_power; |
| 148 } |
| 149 |
| 140 } // namespace | 150 } // namespace |
| 141 | 151 |
| 142 namespace bluez { | 152 namespace bluez { |
| 143 | 153 |
| 144 BluetoothDeviceBlueZ::BluetoothDeviceBlueZ( | 154 BluetoothDeviceBlueZ::BluetoothDeviceBlueZ( |
| 145 BluetoothAdapterBlueZ* adapter, | 155 BluetoothAdapterBlueZ* adapter, |
| 146 const dbus::ObjectPath& object_path, | 156 const dbus::ObjectPath& object_path, |
| 147 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 157 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 148 scoped_refptr<device::BluetoothSocketThread> socket_thread) | 158 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
| 149 : BluetoothDevice(adapter), | 159 : BluetoothDevice(adapter), |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); | 319 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); |
| 310 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); | 320 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); |
| 311 iter != dbus_uuids.end(); ++iter) { | 321 iter != dbus_uuids.end(); ++iter) { |
| 312 device::BluetoothUUID uuid(*iter); | 322 device::BluetoothUUID uuid(*iter); |
| 313 DCHECK(uuid.IsValid()); | 323 DCHECK(uuid.IsValid()); |
| 314 uuids.push_back(uuid); | 324 uuids.push_back(uuid); |
| 315 } | 325 } |
| 316 return uuids; | 326 return uuids; |
| 317 } | 327 } |
| 318 | 328 |
| 319 int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { | 329 int8_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
| 320 bluez::BluetoothDeviceClient::Properties* properties = | 330 bluez::BluetoothDeviceClient::Properties* properties = |
| 321 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 331 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 322 object_path_); | 332 object_path_); |
| 323 DCHECK(properties); | 333 DCHECK(properties); |
| 324 | 334 |
| 325 if (!properties->rssi.is_valid()) | 335 if (!properties->rssi.is_valid()) |
| 326 return kUnknownPower; | 336 return kUnknownRSSI; |
| 327 | 337 |
| 328 return properties->rssi.value(); | 338 return EnsureValidRSSI(properties->rssi.value()); |
| 329 } | 339 } |
| 330 | 340 |
| 331 int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { | 341 int8_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
| 332 bluez::BluetoothDeviceClient::Properties* properties = | 342 bluez::BluetoothDeviceClient::Properties* properties = |
| 333 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 343 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 334 object_path_); | 344 object_path_); |
| 335 DCHECK(properties); | 345 DCHECK(properties); |
| 336 | 346 |
| 337 if (!properties->tx_power.is_valid()) | 347 if (!properties->tx_power.is_valid()) |
| 338 return kUnknownPower; | 348 return kUnknownTxPower; |
| 339 | 349 |
| 340 return properties->tx_power.value(); | 350 return EnsureValidTxPower(properties->tx_power.value()); |
| 341 } | 351 } |
| 342 | 352 |
| 343 bool BluetoothDeviceBlueZ::ExpectingPinCode() const { | 353 bool BluetoothDeviceBlueZ::ExpectingPinCode() const { |
| 344 return pairing_.get() && pairing_->ExpectingPinCode(); | 354 return pairing_.get() && pairing_->ExpectingPinCode(); |
| 345 } | 355 } |
| 346 | 356 |
| 347 bool BluetoothDeviceBlueZ::ExpectingPasskey() const { | 357 bool BluetoothDeviceBlueZ::ExpectingPasskey() const { |
| 348 return pairing_.get() && pairing_->ExpectingPasskey(); | 358 return pairing_.get() && pairing_->ExpectingPasskey(); |
| 349 } | 359 } |
| 350 | 360 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 gatt_services_.take_and_erase(iter->first); | 601 gatt_services_.take_and_erase(iter->first); |
| 592 | 602 |
| 593 DCHECK(adapter_); | 603 DCHECK(adapter_); |
| 594 adapter()->NotifyGattServiceRemoved(service); | 604 adapter()->NotifyGattServiceRemoved(service); |
| 595 } | 605 } |
| 596 | 606 |
| 597 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, | 607 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, |
| 598 int16_t rssi, | 608 int16_t rssi, |
| 599 int16_t transmit_power, | 609 int16_t transmit_power, |
| 600 int16_t max_transmit_power) { | 610 int16_t max_transmit_power) { |
| 601 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); | 611 callback.Run(ConnectionInfo(EnsureValidRSSI(rssi), |
| 612 EnsureValidTxPower(transmit_power), |
| 613 EnsureValidTxPower(max_transmit_power))); |
| 602 } | 614 } |
| 603 | 615 |
| 604 void BluetoothDeviceBlueZ::OnGetConnInfoError( | 616 void BluetoothDeviceBlueZ::OnGetConnInfoError( |
| 605 const ConnectionInfoCallback& callback, | 617 const ConnectionInfoCallback& callback, |
| 606 const std::string& error_name, | 618 const std::string& error_name, |
| 607 const std::string& error_message) { | 619 const std::string& error_message) { |
| 608 LOG(WARNING) << object_path_.value() | 620 LOG(WARNING) << object_path_.value() |
| 609 << ": Failed to get connection info: " << error_name << ": " | 621 << ": Failed to get connection info: " << error_name << ": " |
| 610 << error_message; | 622 << error_message; |
| 611 callback.Run(ConnectionInfo()); | 623 callback.Run(ConnectionInfo()); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 788 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
| 777 const std::string& error_name, | 789 const std::string& error_name, |
| 778 const std::string& error_message) { | 790 const std::string& error_message) { |
| 779 LOG(WARNING) << object_path_.value() | 791 LOG(WARNING) << object_path_.value() |
| 780 << ": Failed to remove device: " << error_name << ": " | 792 << ": Failed to remove device: " << error_name << ": " |
| 781 << error_message; | 793 << error_message; |
| 782 error_callback.Run(); | 794 error_callback.Run(); |
| 783 } | 795 } |
| 784 | 796 |
| 785 } // namespace bluez | 797 } // namespace bluez |
| OLD | NEW |