Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: device/bluetooth/bluez/bluetooth_adapter_bluez.cc

Issue 2483783005: bluetooth: bluez: Implement RetrieveGattConnectedDevicesWithDiscoveryFilter (Closed)
Patch Set: Clean up Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h" 45 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h"
46 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 46 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
47 #include "third_party/cros_system_api/dbus/service_constants.h" 47 #include "third_party/cros_system_api/dbus/service_constants.h"
48 48
49 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
50 #include "chromeos/system/devicetype.h" 50 #include "chromeos/system/devicetype.h"
51 #endif 51 #endif
52 52
53 using device::BluetoothAdapter; 53 using device::BluetoothAdapter;
54 using device::BluetoothDevice; 54 using device::BluetoothDevice;
55 using UUIDSet = device::BluetoothDevice::UUIDSet;
55 using device::BluetoothDiscoveryFilter; 56 using device::BluetoothDiscoveryFilter;
56 using device::BluetoothSocket; 57 using device::BluetoothSocket;
57 using device::BluetoothUUID; 58 using device::BluetoothUUID;
58 using device::UMABluetoothDiscoverySessionOutcome; 59 using device::UMABluetoothDiscoverySessionOutcome;
59 60
60 namespace { 61 namespace {
61 62
62 // The agent path is relatively meaningless since BlueZ only permits one to 63 // The agent path is relatively meaningless since BlueZ only permits one to
63 // exist per D-Bus connection, it just has to be unique within Chromium. 64 // exist per D-Bus connection, it just has to be unique within Chromium.
64 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; 65 const char kAgentPath[] = "/org/chromium/bluetooth_agent";
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return false; 392 return false;
392 393
393 bluez::BluetoothAdapterClient::Properties* properties = 394 bluez::BluetoothAdapterClient::Properties* properties =
394 bluez::BluezDBusManager::Get() 395 bluez::BluezDBusManager::Get()
395 ->GetBluetoothAdapterClient() 396 ->GetBluetoothAdapterClient()
396 ->GetProperties(object_path_); 397 ->GetProperties(object_path_);
397 398
398 return properties->discovering.value(); 399 return properties->discovering.value();
399 } 400 }
400 401
402 std::unordered_map<BluetoothDevice*, UUIDSet>
403 BluetoothAdapterBlueZ::RetrieveGattConnectedDevicesWithDiscoveryFilter(
404 const BluetoothDiscoveryFilter& discovery_filter) {
405 std::unordered_map<BluetoothDevice*, UUIDSet> connected_devices;
406
407 std::set<BluetoothUUID> filter_uuids;
408 discovery_filter.GetUUIDs(filter_uuids);
409
410 for (BluetoothDevice* device : GetDevices()) {
411 if (device->IsGattConnected() &&
412 (device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) {
413 UUIDSet device_uuids = device->GetUUIDs();
414
415 UUIDSet intersection;
416 for (const BluetoothUUID& uuid : filter_uuids) {
417 if (base::ContainsKey(device_uuids, uuid)) {
418 intersection.insert(uuid);
419 }
420 }
421
422 if (filter_uuids.empty() || !intersection.empty()) {
423 connected_devices[device] = std::move(intersection);
424 }
425 }
426 }
427
428 return connected_devices;
429 }
430
401 BluetoothAdapterBlueZ::UUIDList BluetoothAdapterBlueZ::GetUUIDs() const { 431 BluetoothAdapterBlueZ::UUIDList BluetoothAdapterBlueZ::GetUUIDs() const {
402 bluez::BluetoothAdapterClient::Properties* properties = 432 bluez::BluetoothAdapterClient::Properties* properties =
403 bluez::BluezDBusManager::Get() 433 bluez::BluezDBusManager::Get()
404 ->GetBluetoothAdapterClient() 434 ->GetBluetoothAdapterClient()
405 ->GetProperties(object_path_); 435 ->GetProperties(object_path_);
406 DCHECK(properties); 436 DCHECK(properties);
407 437
408 std::vector<std::string> uuids = properties->uuids.value(); 438 std::vector<std::string> uuids = properties->uuids.value();
409 439
410 return UUIDList(uuids.begin(), uuids.end()); 440 return UUIDList(uuids.begin(), uuids.end());
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) { 1734 } else if (error_name == bluetooth_adapter::kErrorAlreadyExists) {
1705 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS; 1735 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_RECORD_ALREADY_EXISTS;
1706 } else if (error_name == bluetooth_adapter::kErrorNotReady) { 1736 } else if (error_name == bluetooth_adapter::kErrorNotReady) {
1707 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY; 1737 code = BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY;
1708 } 1738 }
1709 1739
1710 error_callback.Run(code); 1740 error_callback.Run(code);
1711 } 1741 }
1712 1742
1713 } // namespace bluez 1743 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluez/bluetooth_adapter_bluez.h ('k') | device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698