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_adapter_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <cstdint> |
| 9 #include <limits> |
7 #include <memory> | 10 #include <memory> |
8 #include <set> | 11 #include <set> |
9 #include <string> | 12 #include <string> |
10 #include <utility> | 13 #include <utility> |
11 | 14 |
12 #include "base/bind.h" | 15 #include "base/bind.h" |
13 #include "base/location.h" | 16 #include "base/location.h" |
14 #include "base/logging.h" | 17 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
16 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
17 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" |
20 #include "build/build_config.h" | 24 #include "build/build_config.h" |
21 #include "device/bluetooth/bluetooth_common.h" | 25 #include "device/bluetooth/bluetooth_common.h" |
22 #include "device/bluetooth/bluetooth_device.h" | 26 #include "device/bluetooth/bluetooth_device.h" |
23 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 27 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
24 #include "device/bluetooth/bluetooth_socket_thread.h" | 28 #include "device/bluetooth/bluetooth_socket_thread.h" |
25 #include "device/bluetooth/bluetooth_uuid.h" | 29 #include "device/bluetooth/bluetooth_uuid.h" |
26 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" | 30 #include "device/bluetooth/bluez/bluetooth_adapter_profile_bluez.h" |
27 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" | 31 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" |
28 #include "device/bluetooth/bluez/bluetooth_audio_sink_bluez.h" | 32 #include "device/bluetooth/bluez/bluetooth_audio_sink_bluez.h" |
29 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | 33 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
30 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" | 34 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" |
31 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" | 35 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" |
32 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" | 36 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h" |
33 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" | 37 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
34 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" | 38 #include "device/bluetooth/bluez/bluetooth_socket_bluez.h" |
35 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 39 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
36 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" | 40 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" |
37 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" | 41 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
38 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 42 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
39 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" | 43 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" |
40 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" | 44 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h" |
41 #include "device/bluetooth/dbus/bluetooth_input_client.h" | 45 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 46 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h" |
42 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 47 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
43 #include "third_party/cros_system_api/dbus/service_constants.h" | 48 #include "third_party/cros_system_api/dbus/service_constants.h" |
44 | 49 |
45 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
46 #include "chromeos/system/devicetype.h" | 51 #include "chromeos/system/devicetype.h" |
47 #endif | 52 #endif |
48 | 53 |
49 using device::BluetoothAdapter; | 54 using device::BluetoothAdapter; |
50 using device::BluetoothAudioSink; | 55 using device::BluetoothAudioSink; |
51 using device::BluetoothDevice; | 56 using device::BluetoothDevice; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 VLOG(1) << "Failed to Unregister service: " << error_name << ", " | 124 VLOG(1) << "Failed to Unregister service: " << error_name << ", " |
120 << error_message; | 125 << error_message; |
121 } | 126 } |
122 error_callback.Run( | 127 error_callback.Run( |
123 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); | 128 BluetoothGattServiceBlueZ::DBusErrorToServiceError(error_name)); |
124 } | 129 } |
125 | 130 |
126 void DoNothingOnError( | 131 void DoNothingOnError( |
127 device::BluetoothGattService::GattErrorCode /*error_code*/) {} | 132 device::BluetoothGattService::GattErrorCode /*error_code*/) {} |
128 | 133 |
| 134 void SetIntervalErrorCallbackConnector( |
| 135 const device::BluetoothAdapter::AdvertisementErrorCallback& error_callback, |
| 136 const std::string& error_name, |
| 137 const std::string& error_message) { |
| 138 LOG(ERROR) << "Error while registering advertisement. error_name = " |
| 139 << error_name << ", error_message = " << error_message; |
| 140 |
| 141 device::BluetoothAdvertisement::ErrorCode code = device:: |
| 142 BluetoothAdvertisement::ErrorCode::INVALID_ADVERTISEMENT_ERROR_CODE; |
| 143 if (error_name == bluetooth_advertising_manager::kErrorInvalidArguments) { |
| 144 code = device::BluetoothAdvertisement::ErrorCode:: |
| 145 ERROR_INVALID_ADVERTISEMENT_INTERVAL; |
| 146 } |
| 147 error_callback.Run(code); |
| 148 } |
| 149 |
129 } // namespace | 150 } // namespace |
130 | 151 |
131 // static | 152 // static |
132 base::WeakPtr<BluetoothAdapter> BluetoothAdapterBlueZ::CreateAdapter( | 153 base::WeakPtr<BluetoothAdapter> BluetoothAdapterBlueZ::CreateAdapter( |
133 const InitCallback& init_callback) { | 154 const InitCallback& init_callback) { |
134 BluetoothAdapterBlueZ* adapter = new BluetoothAdapterBlueZ(init_callback); | 155 BluetoothAdapterBlueZ* adapter = new BluetoothAdapterBlueZ(init_callback); |
135 return adapter->weak_ptr_factory_.GetWeakPtr(); | 156 return adapter->weak_ptr_factory_.GetWeakPtr(); |
136 } | 157 } |
137 | 158 |
138 void BluetoothAdapterBlueZ::Shutdown() { | 159 void BluetoothAdapterBlueZ::Shutdown() { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 audio_sink->Register(options, | 456 audio_sink->Register(options, |
436 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink, | 457 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink, |
437 weak_ptr_factory_.GetWeakPtr(), callback, | 458 weak_ptr_factory_.GetWeakPtr(), callback, |
438 error_callback, audio_sink), | 459 error_callback, audio_sink), |
439 error_callback); | 460 error_callback); |
440 } | 461 } |
441 | 462 |
442 void BluetoothAdapterBlueZ::RegisterAdvertisement( | 463 void BluetoothAdapterBlueZ::RegisterAdvertisement( |
443 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, | 464 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data, |
444 const CreateAdvertisementCallback& callback, | 465 const CreateAdvertisementCallback& callback, |
445 const CreateAdvertisementErrorCallback& error_callback) { | 466 const AdvertisementErrorCallback& error_callback) { |
446 scoped_refptr<BluetoothAdvertisementBlueZ> advertisement( | 467 scoped_refptr<BluetoothAdvertisementBlueZ> advertisement( |
447 new BluetoothAdvertisementBlueZ(std::move(advertisement_data), this)); | 468 new BluetoothAdvertisementBlueZ(std::move(advertisement_data), this)); |
448 advertisement->Register(base::Bind(callback, advertisement), error_callback); | 469 advertisement->Register(base::Bind(callback, advertisement), error_callback); |
449 } | 470 } |
450 | 471 |
| 472 void BluetoothAdapterBlueZ::SetAdvertisingInterval( |
| 473 const base::TimeDelta& min, |
| 474 const base::TimeDelta& max, |
| 475 const base::Closure& callback, |
| 476 const AdvertisementErrorCallback& error_callback) { |
| 477 DCHECK(bluez::BluezDBusManager::Get()); |
| 478 uint16_t min_ms = static_cast<uint16_t>( |
| 479 std::min(static_cast<int64_t>(std::numeric_limits<uint16_t>::max()), |
| 480 min.InMilliseconds())); |
| 481 uint16_t max_ms = static_cast<uint16_t>( |
| 482 std::min(static_cast<int64_t>(std::numeric_limits<uint16_t>::max()), |
| 483 max.InMilliseconds())); |
| 484 bluez::BluezDBusManager::Get() |
| 485 ->GetBluetoothLEAdvertisingManagerClient() |
| 486 ->SetAdvertisingInterval( |
| 487 object_path_, min_ms, max_ms, callback, |
| 488 base::Bind(&SetIntervalErrorCallbackConnector, error_callback)); |
| 489 } |
| 490 |
451 device::BluetoothLocalGattService* BluetoothAdapterBlueZ::GetGattService( | 491 device::BluetoothLocalGattService* BluetoothAdapterBlueZ::GetGattService( |
452 const std::string& identifier) const { | 492 const std::string& identifier) const { |
453 const auto& service = owned_gatt_services_.find(dbus::ObjectPath(identifier)); | 493 const auto& service = owned_gatt_services_.find(dbus::ObjectPath(identifier)); |
454 return service == owned_gatt_services_.end() ? nullptr | 494 return service == owned_gatt_services_.end() ? nullptr |
455 : service->second.get(); | 495 : service->second.get(); |
456 } | 496 } |
457 | 497 |
458 void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( | 498 void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( |
459 BluetoothDevice::PairingDelegate* pairing_delegate) { | 499 BluetoothDevice::PairingDelegate* pairing_delegate) { |
460 // Check if any device is using the pairing delegate. | 500 // Check if any device is using the pairing delegate. |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { | 1727 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { |
1688 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; | 1728 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; |
1689 } else if (error_name == bluetooth_adapter::kErrorNotReady) { | 1729 } else if (error_name == bluetooth_adapter::kErrorNotReady) { |
1690 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; | 1730 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; |
1691 } | 1731 } |
1692 | 1732 |
1693 error_callback.Run(code); | 1733 error_callback.Run(code); |
1694 } | 1734 } |
1695 | 1735 |
1696 } // namespace bluez | 1736 } // namespace bluez |
OLD | NEW |