mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Multiple Service scanning implementation for G3.
PiperOrigin-RevId: 733458126
This commit is contained in:
committed by
Copybara-Service
parent
b814358f89
commit
dec2ff910a
@@ -456,7 +456,6 @@ class BleMedium {
|
||||
// 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)>
|
||||
|
||||
@@ -251,6 +251,35 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback) {
|
||||
NEARBY_LOGS(INFO) << "G3 Ble StartMultipleServicesScanning";
|
||||
|
||||
absl::MutexLock lock(&mutex_);
|
||||
multiple_services_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](
|
||||
api::ble_v2::BlePeripheral& peripheral,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
multiple_services_scan_callback_.advertisement_found_cb(
|
||||
service_uuid, peripheral, advertisement_data);
|
||||
}};
|
||||
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
/*enabled=*/true, service_uuid, internal_session_id,
|
||||
{.advertisement_found_cb =
|
||||
std::move(scan_callback.advertisement_found_cb)},
|
||||
*this);
|
||||
scanning_internal_session_ids_.insert({service_uuid, internal_session_id});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopScanning() {
|
||||
NEARBY_LOGS(INFO) << "G3 Ble StopScanning";
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
@@ -164,6 +164,10 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
MultipleServicesScanCallback callback)
|
||||
override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopScanning() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<ScanningSession> StartScanning(
|
||||
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
@@ -333,6 +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_;
|
||||
};
|
||||
|
||||
} // namespace g3
|
||||
|
||||
Reference in New Issue
Block a user