diff --git a/connections/implementation/mediums/ble_v2/BUILD b/connections/implementation/mediums/ble_v2/BUILD index 17241f9e..c07c66da 100644 --- a/connections/implementation/mediums/ble_v2/BUILD +++ b/connections/implementation/mediums/ble_v2/BUILD @@ -39,7 +39,6 @@ cc_library( "//connections/implementation:__subpackages__", ], deps = [ - "//connections:core_types", "//connections/implementation/flags:connections_flags", "//connections/implementation/mediums:utils", "//internal/flags:nearby_flags", @@ -53,6 +52,7 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/numeric:int128", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h b/connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h index 5a190282..6d39fa4c 100644 --- a/connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h +++ b/connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h @@ -15,9 +15,9 @@ #ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_CALLBACK_H_ #define CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_CALLBACK_H_ -#include #include +#include "absl/functional/any_invocable.h" #include "internal/platform/ble_v2.h" #include "internal/platform/byte_array.h" @@ -27,14 +27,14 @@ namespace mediums { // Callback that is invoked when a {@link BlePeripheral} is discovered. struct DiscoveredPeripheralCallback { - std::function + absl::AnyInvocable peripheral_discovered_cb = [](BleV2Peripheral, const std::string&, const ByteArray&, bool) {}; - std::function + absl::AnyInvocable peripheral_lost_cb = [](BleV2Peripheral, const std::string&, const ByteArray&, bool) {}; }; diff --git a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc index 806cf3dc..024d6c62 100644 --- a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc +++ b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.cc @@ -28,6 +28,7 @@ #include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h" #include "connections/implementation/mediums/ble_v2/ble_utils.h" #include "connections/implementation/mediums/ble_v2/bloom_filter.h" +#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h" #include "internal/flags/nearby_flags.h" #include "internal/platform/ble_v2.h" #include "internal/platform/byte_array.h" @@ -66,7 +67,7 @@ DiscoveredPeripheralTracker::~DiscoveredPeripheralTracker() { void DiscoveredPeripheralTracker::StartTracking( const std::string& service_id, - const DiscoveredPeripheralCallback& discovered_peripheral_callback, + DiscoveredPeripheralCallback discovered_peripheral_callback, const Uuid& fast_advertisement_service_uuid) { MutexLock lock(&mutex_); @@ -129,11 +130,9 @@ void DiscoveredPeripheralTracker::ProcessFoundBleAdvertisement( void DiscoveredPeripheralTracker::ProcessLostGattAdvertisements() { MutexLock lock(&mutex_); - for (const auto& it : service_id_infos_) { + for (auto& it : service_id_infos_) { const std::string& service_id = it.first; - const ServiceIdInfo& service_id_info = it.second; - DiscoveredPeripheralCallback discovered_peripheral_callback = - service_id_info.discovered_peripheral_callback; + ServiceIdInfo& service_id_info = it.second; BleAdvertisementSet lost_gatt_advertisements = service_id_info.lost_entity_tracker->ComputeLostEntities(); @@ -145,7 +144,7 @@ void DiscoveredPeripheralTracker::ProcessLostGattAdvertisements() { BleV2Peripheral lost_peripheral = it->second.peripheral; if (lost_peripheral.IsValid()) { lost_peripheral.SetId(ByteArray(gatt_advertisement)); - discovered_peripheral_callback.peripheral_lost_cb( + service_id_info.discovered_peripheral_callback.peripheral_lost_cb( std::move(lost_peripheral), service_id, gatt_advertisement.GetData(), gatt_advertisement.IsFastAdvertisement()); @@ -525,7 +524,7 @@ void DiscoveredPeripheralTracker::HandleAdvertisementHeader( ByteArray advertisement_data{advertisement_header}; if (fetching_advertisements_.contains(advertisement_data)) { NEARBY_LOGS(VERBOSE) << ": Ignore the advertisement header due to it " - "is already in fetcing."; + "is already in fetching."; return; } diff --git a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h index fcd59951..380d6bd5 100644 --- a/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h +++ b/connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h @@ -79,7 +79,7 @@ class DiscoveredPeripheralTracker { // advertisement. void StartTracking( const std::string& service_id, - const DiscoveredPeripheralCallback& discovered_peripheral_callback, + DiscoveredPeripheralCallback discovered_peripheral_callback, const Uuid& fast_advertisement_service_uuid) ABSL_LOCKS_EXCLUDED(mutex_); // Stops tracking discoveries for a particular service Id.