| 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/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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_bluez.h" | |
| 18 #include "device/bluetooth/bluetooth_gatt_connection_bluez.h" | |
| 19 #include "device/bluetooth/bluetooth_pairing_bluez.h" | |
| 20 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" | |
| 21 #include "device/bluetooth/bluetooth_socket.h" | 17 #include "device/bluetooth/bluetooth_socket.h" |
| 22 #include "device/bluetooth/bluetooth_socket_bluez.h" | |
| 23 #include "device/bluetooth/bluetooth_socket_thread.h" | 18 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 24 #include "device/bluetooth/bluetooth_uuid.h" | 19 #include "device/bluetooth/bluetooth_uuid.h" |
| 20 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
| 21 #include "device/bluetooth/bluez/bluetooth_gatt_connection_bluez.h" |
| 22 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
| 23 #include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h" |
| 24 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" |
| 25 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 25 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 26 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 26 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 27 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 27 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 28 #include "device/bluetooth/dbus/bluetooth_input_client.h" | 28 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 29 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 29 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 30 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 31 |
| 32 using device::BluetoothDevice; | 32 using device::BluetoothDevice; |
| 33 using device::BluetoothGattService; | 33 using device::BluetoothRemoteGattService; |
| 34 using device::BluetoothSocket; | 34 using device::BluetoothSocket; |
| 35 using device::BluetoothUUID; | 35 using device::BluetoothUUID; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // Histogram enumerations for pairing results. | 39 // Histogram enumerations for pairing results. |
| 40 enum UMAPairingResult { | 40 enum UMAPairingResult { |
| 41 UMA_PAIRING_RESULT_SUCCESS, | 41 UMA_PAIRING_RESULT_SUCCESS, |
| 42 UMA_PAIRING_RESULT_INPROGRESS, | 42 UMA_PAIRING_RESULT_INPROGRESS, |
| 43 UMA_PAIRING_RESULT_FAILED, | 43 UMA_PAIRING_RESULT_FAILED, |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 VLOG(2) << "Remote GATT service does not belong to this device."; | 555 VLOG(2) << "Remote GATT service does not belong to this device."; |
| 556 return; | 556 return; |
| 557 } | 557 } |
| 558 | 558 |
| 559 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); | 559 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); |
| 560 | 560 |
| 561 BluetoothRemoteGattServiceBlueZ* service = | 561 BluetoothRemoteGattServiceBlueZ* service = |
| 562 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); | 562 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); |
| 563 | 563 |
| 564 gatt_services_.set(service->GetIdentifier(), | 564 gatt_services_.set(service->GetIdentifier(), |
| 565 std::unique_ptr<BluetoothGattService>(service)); | 565 std::unique_ptr<BluetoothRemoteGattService>(service)); |
| 566 DCHECK(service->object_path() == object_path); | 566 DCHECK(service->object_path() == object_path); |
| 567 DCHECK(service->GetUUID().IsValid()); | 567 DCHECK(service->GetUUID().IsValid()); |
| 568 | 568 |
| 569 DCHECK(adapter_); | 569 DCHECK(adapter_); |
| 570 adapter()->NotifyGattServiceAdded(service); | 570 adapter()->NotifyGattServiceAdded(service); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void BluetoothDeviceBlueZ::GattServiceRemoved( | 573 void BluetoothDeviceBlueZ::GattServiceRemoved( |
| 574 const dbus::ObjectPath& object_path) { | 574 const dbus::ObjectPath& object_path) { |
| 575 GattServiceMap::const_iterator iter = | 575 GattServiceMap::const_iterator iter = |
| 576 gatt_services_.find(object_path.value()); | 576 gatt_services_.find(object_path.value()); |
| 577 if (iter == gatt_services_.end()) { | 577 if (iter == gatt_services_.end()) { |
| 578 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); | 578 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); |
| 579 return; | 579 return; |
| 580 } | 580 } |
| 581 | 581 |
| 582 BluetoothRemoteGattServiceBlueZ* service = | 582 BluetoothRemoteGattServiceBlueZ* service = |
| 583 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second); | 583 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second); |
| 584 | 584 |
| 585 VLOG(1) << "Removing remote GATT service with UUID: '" | 585 VLOG(1) << "Removing remote GATT service with UUID: '" |
| 586 << service->GetUUID().canonical_value() | 586 << service->GetUUID().canonical_value() |
| 587 << "' from device: " << GetAddress(); | 587 << "' from device: " << GetAddress(); |
| 588 | 588 |
| 589 DCHECK(service->object_path() == object_path); | 589 DCHECK(service->object_path() == object_path); |
| 590 std::unique_ptr<BluetoothGattService> scoped_service = | 590 std::unique_ptr<BluetoothRemoteGattService> scoped_service = |
| 591 gatt_services_.take_and_erase(iter->first); | 591 gatt_services_.take_and_erase(iter->first); |
| 592 | 592 |
| 593 DCHECK(adapter_); | 593 DCHECK(adapter_); |
| 594 adapter()->NotifyGattServiceRemoved(service); | 594 adapter()->NotifyGattServiceRemoved(service); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, | 597 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, |
| 598 int16_t rssi, | 598 int16_t rssi, |
| 599 int16_t transmit_power, | 599 int16_t transmit_power, |
| 600 int16_t max_transmit_power) { | 600 int16_t max_transmit_power) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 776 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
| 777 const std::string& error_name, | 777 const std::string& error_name, |
| 778 const std::string& error_message) { | 778 const std::string& error_message) { |
| 779 LOG(WARNING) << object_path_.value() | 779 LOG(WARNING) << object_path_.value() |
| 780 << ": Failed to remove device: " << error_name << ": " | 780 << ": Failed to remove device: " << error_name << ": " |
| 781 << error_message; | 781 << error_message; |
| 782 error_callback.Run(); | 782 error_callback.Run(); |
| 783 } | 783 } |
| 784 | 784 |
| 785 } // namespace bluez | 785 } // namespace bluez |
| OLD | NEW |