mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
remove callback for multiple services scan
PiperOrigin-RevId: 733518623
This commit is contained in:
committed by
Copybara-Service
parent
270c23cb7f
commit
b6dc3348a4
@@ -97,8 +97,7 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
|
||||
bool BleV2Medium::StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback) {
|
||||
api::ble_v2::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (scanning_enabled_) {
|
||||
NEARBY_LOGS(INFO) << "Ble Scanning already enabled; impl=" << GetImpl();
|
||||
@@ -106,11 +105,10 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
}
|
||||
bool success = impl_->StartMultipleServicesScanning(
|
||||
service_uuids, tx_power_level,
|
||||
api::ble_v2::BleMedium::MultipleServicesScanCallback{
|
||||
api::ble_v2::BleMedium::ScanCallback{
|
||||
.advertisement_found_cb =
|
||||
[this](const Uuid& service_uuid,
|
||||
api::ble_v2::BlePeripheral& peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
[this](api::ble_v2::BlePeripheral& peripheral,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!peripherals_.contains(&peripheral)) {
|
||||
NEARBY_LOGS(INFO) << "Peripheral impl=" << &peripheral
|
||||
@@ -120,12 +118,12 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
|
||||
BleV2Peripheral proxy(*this, peripheral);
|
||||
if (!scanning_enabled_) return;
|
||||
multiple_services_scan_callback_.advertisement_found_cb(
|
||||
service_uuid, std::move(proxy), advertisement_data);
|
||||
scan_callback_.advertisement_found_cb(std::move(proxy),
|
||||
advertisement_data);
|
||||
},
|
||||
});
|
||||
if (success) {
|
||||
multiple_services_scan_callback_ = std::move(callback);
|
||||
scan_callback_ = std::move(callback);
|
||||
peripherals_.clear();
|
||||
scanning_enabled_ = true;
|
||||
NEARBY_LOGS(INFO) << "Ble Scanning enabled; impl=" << GetImpl();
|
||||
|
||||
@@ -354,16 +354,6 @@ class BleV2Medium final {
|
||||
const api::ble_v2::BleAdvertisementData&>();
|
||||
};
|
||||
|
||||
// A wrapper callback for BLE scan results targeting multiple services.
|
||||
struct MultipleServicesScanCallback {
|
||||
absl::AnyInvocable<void(
|
||||
const Uuid& service_uuid, BleV2Peripheral peripheral,
|
||||
const api::ble_v2::BleAdvertisementData& advertisement_data)>
|
||||
advertisement_found_cb =
|
||||
nearby::DefaultCallback<const Uuid&, BleV2Peripheral,
|
||||
const api::ble_v2::BleAdvertisementData&>();
|
||||
};
|
||||
|
||||
struct ServerGattConnectionCallback {
|
||||
using BlePeripheral = api::ble_v2::BlePeripheral;
|
||||
using GattCharacteristic = api::ble_v2::GattCharacteristic;
|
||||
@@ -425,7 +415,7 @@ class BleV2Medium final {
|
||||
// Returns true once the BLE multiple services scan has been initiated.
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback);
|
||||
ScanCallback callback);
|
||||
|
||||
// This interface will be deprecated soon.
|
||||
// TODO(b/271305977) remove this function.
|
||||
@@ -476,8 +466,6 @@ class BleV2Medium final {
|
||||
absl::flat_hash_set<api::ble_v2::BlePeripheral*> peripherals_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
ScanCallback scan_callback_ ABSL_GUARDED_BY(mutex_);
|
||||
MultipleServicesScanCallback multiple_services_scan_callback_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
bool scanning_enabled_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -167,9 +167,8 @@ TEST_P(BleV2MediumTest, CanConnectToServiceWithMultipleServices) {
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
const Uuid& service_uuid, BleV2Peripheral peripheral,
|
||||
BleV2Peripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
EXPECT_EQ(service_uuid, Uuid(1234, 5678));
|
||||
discovered_peripheral = std::move(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
@@ -242,14 +241,13 @@ TEST_P(BleV2MediumTest, CanDiscoverMultipleServices) {
|
||||
std::vector<Uuid>{service_uuid_a, service_uuid_b}, kTxPowerLevel,
|
||||
{.advertisement_found_cb =
|
||||
[&found_latch, &found_service_a, &found_service_b, &service_uuid_a,
|
||||
&service_uuid_b](const Uuid& service_uuid,
|
||||
BleV2Peripheral peripheral,
|
||||
&service_uuid_b](BleV2Peripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
if (service_uuid == service_uuid_a) {
|
||||
if (advertisement_data.service_data.contains(service_uuid_a)) {
|
||||
found_service_a = true;
|
||||
}
|
||||
|
||||
if (service_uuid == service_uuid_b) {
|
||||
if (advertisement_data.service_data.contains(service_uuid_b)) {
|
||||
found_service_b = true;
|
||||
}
|
||||
if (found_service_a && found_service_b) {
|
||||
|
||||
@@ -445,24 +445,6 @@ class BleMedium {
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) = 0;
|
||||
|
||||
// Callback for BLE scans targeting multiple services.
|
||||
//
|
||||
// service_uuid: The UUID of the service discovered in the scan result.
|
||||
// peripheral: A platform-owned object representing the discovered
|
||||
// peripheral. This object's lifetime extends for the duration of any
|
||||
// connection to the device.
|
||||
// advertisement_data: A combination of advertisement and scan response data.
|
||||
//
|
||||
// This callback is invoked for every discovered advertisement , even if the
|
||||
// same advertisement has been seen previously.
|
||||
//
|
||||
struct MultipleServicesScanCallback {
|
||||
absl::AnyInvocable<void(const Uuid& service_uuid, BlePeripheral& peripheral,
|
||||
const BleAdvertisementData& advertisement_data)>
|
||||
advertisement_found_cb =
|
||||
[](const Uuid&, BlePeripheral&, const BleAdvertisementData&) {};
|
||||
};
|
||||
|
||||
// Starts multiple services scanning and returns whether or not it was
|
||||
// successful.
|
||||
//
|
||||
@@ -473,7 +455,7 @@ class BleMedium {
|
||||
|
||||
virtual bool StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids, TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback) {
|
||||
ScanCallback callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -253,26 +253,24 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
|
||||
bool BleV2Medium::StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback) {
|
||||
api::ble_v2::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
NEARBY_LOGS(INFO) << "G3 Ble StartMultipleServicesScanning";
|
||||
|
||||
absl::MutexLock lock(&mutex_);
|
||||
multiple_services_scan_callback_ = std::move(callback);
|
||||
scan_callback_ = std::move(callback);
|
||||
for (const auto& service_uuid : service_uuids) {
|
||||
auto internal_session_id = Prng().NextUint32();
|
||||
ScanCallback scan_callback = {
|
||||
.advertisement_found_cb = [this, service_uuid](
|
||||
ScanCallback multiple_scan_callback = {
|
||||
.advertisement_found_cb = [this](
|
||||
api::ble_v2::BlePeripheral& peripheral,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
multiple_services_scan_callback_.advertisement_found_cb(
|
||||
service_uuid, peripheral, advertisement_data);
|
||||
scan_callback_.advertisement_found_cb(peripheral, advertisement_data);
|
||||
}};
|
||||
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
/*enabled=*/true, service_uuid, internal_session_id,
|
||||
{.advertisement_found_cb =
|
||||
std::move(scan_callback.advertisement_found_cb)},
|
||||
std::move(multiple_scan_callback.advertisement_found_cb)},
|
||||
*this);
|
||||
scanning_internal_session_ids_.insert({service_uuid, internal_session_id});
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback)
|
||||
ScanCallback callback)
|
||||
override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopScanning() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<ScanningSession> StartScanning(
|
||||
@@ -337,7 +337,7 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
absl::flat_hash_set<std::pair<Uuid, std::uint32_t>>
|
||||
scanning_internal_session_ids_ ABSL_GUARDED_BY(mutex_);
|
||||
bool is_extended_advertisements_available_ = false;
|
||||
MultipleServicesScanCallback multiple_services_scan_callback_;
|
||||
ScanCallback scan_callback_;
|
||||
};
|
||||
|
||||
} // namespace g3
|
||||
|
||||
Reference in New Issue
Block a user