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> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 device::BluetoothAdvertisement::ErrorCode code = device:: | 144 device::BluetoothAdvertisement::ErrorCode code = device:: |
145 BluetoothAdvertisement::ErrorCode::INVALID_ADVERTISEMENT_ERROR_CODE; | 145 BluetoothAdvertisement::ErrorCode::INVALID_ADVERTISEMENT_ERROR_CODE; |
146 if (error_name == bluetooth_advertising_manager::kErrorInvalidArguments) { | 146 if (error_name == bluetooth_advertising_manager::kErrorInvalidArguments) { |
147 code = device::BluetoothAdvertisement::ErrorCode:: | 147 code = device::BluetoothAdvertisement::ErrorCode:: |
148 ERROR_INVALID_ADVERTISEMENT_INTERVAL; | 148 ERROR_INVALID_ADVERTISEMENT_INTERVAL; |
149 } | 149 } |
150 error_callback.Run(code); | 150 error_callback.Run(code); |
151 } | 151 } |
152 | 152 |
| 153 void ResetAdvertisingErrorCallbackConnector( |
| 154 const device::BluetoothAdapter::AdvertisementErrorCallback& error_callback, |
| 155 const std::string& error_name, |
| 156 const std::string& error_message) { |
| 157 BLUETOOTH_LOG(ERROR) << "Error while resetting advertising. error_name = " |
| 158 << error_name << ", error_message = " << error_message; |
| 159 |
| 160 error_callback.Run( |
| 161 device::BluetoothAdvertisement::ErrorCode::ERROR_RESET_ADVERTISING); |
| 162 } |
| 163 |
153 } // namespace | 164 } // namespace |
154 | 165 |
155 // static | 166 // static |
156 base::WeakPtr<BluetoothAdapter> BluetoothAdapterBlueZ::CreateAdapter( | 167 base::WeakPtr<BluetoothAdapter> BluetoothAdapterBlueZ::CreateAdapter( |
157 const InitCallback& init_callback) { | 168 const InitCallback& init_callback) { |
158 BluetoothAdapterBlueZ* adapter = new BluetoothAdapterBlueZ(init_callback); | 169 BluetoothAdapterBlueZ* adapter = new BluetoothAdapterBlueZ(init_callback); |
159 return adapter->weak_ptr_factory_.GetWeakPtr(); | 170 return adapter->weak_ptr_factory_.GetWeakPtr(); |
160 } | 171 } |
161 | 172 |
162 void BluetoothAdapterBlueZ::Shutdown() { | 173 void BluetoothAdapterBlueZ::Shutdown() { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 uint16_t max_ms = static_cast<uint16_t>( | 526 uint16_t max_ms = static_cast<uint16_t>( |
516 std::min(static_cast<int64_t>(std::numeric_limits<uint16_t>::max()), | 527 std::min(static_cast<int64_t>(std::numeric_limits<uint16_t>::max()), |
517 max.InMilliseconds())); | 528 max.InMilliseconds())); |
518 bluez::BluezDBusManager::Get() | 529 bluez::BluezDBusManager::Get() |
519 ->GetBluetoothLEAdvertisingManagerClient() | 530 ->GetBluetoothLEAdvertisingManagerClient() |
520 ->SetAdvertisingInterval( | 531 ->SetAdvertisingInterval( |
521 object_path_, min_ms, max_ms, callback, | 532 object_path_, min_ms, max_ms, callback, |
522 base::Bind(&SetIntervalErrorCallbackConnector, error_callback)); | 533 base::Bind(&SetIntervalErrorCallbackConnector, error_callback)); |
523 } | 534 } |
524 | 535 |
| 536 void BluetoothAdapterBlueZ::ResetAdvertising( |
| 537 const base::Closure& callback, |
| 538 const AdvertisementErrorCallback& error_callback) { |
| 539 DCHECK(bluez::BluezDBusManager::Get()); |
| 540 bluez::BluezDBusManager::Get() |
| 541 ->GetBluetoothLEAdvertisingManagerClient() |
| 542 ->ResetAdvertising( |
| 543 object_path_, callback, |
| 544 base::Bind(&ResetAdvertisingErrorCallbackConnector, error_callback)); |
| 545 } |
| 546 |
525 device::BluetoothLocalGattService* BluetoothAdapterBlueZ::GetGattService( | 547 device::BluetoothLocalGattService* BluetoothAdapterBlueZ::GetGattService( |
526 const std::string& identifier) const { | 548 const std::string& identifier) const { |
527 const auto& service = owned_gatt_services_.find(dbus::ObjectPath(identifier)); | 549 const auto& service = owned_gatt_services_.find(dbus::ObjectPath(identifier)); |
528 return service == owned_gatt_services_.end() ? nullptr | 550 return service == owned_gatt_services_.end() ? nullptr |
529 : service->second.get(); | 551 : service->second.get(); |
530 } | 552 } |
531 | 553 |
532 void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( | 554 void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( |
533 BluetoothDevice::PairingDelegate* pairing_delegate) { | 555 BluetoothDevice::PairingDelegate* pairing_delegate) { |
534 // Check if any device is using the pairing delegate. | 556 // Check if any device is using the pairing delegate. |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { | 1770 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { |
1749 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; | 1771 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; |
1750 } else if (error_name == bluetooth_adapter::kErrorNotReady) { | 1772 } else if (error_name == bluetooth_adapter::kErrorNotReady) { |
1751 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; | 1773 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; |
1752 } | 1774 } |
1753 | 1775 |
1754 error_callback.Run(code); | 1776 error_callback.Run(code); |
1755 } | 1777 } |
1756 | 1778 |
1757 } // namespace bluez | 1779 } // namespace bluez |
OLD | NEW |