Add BleMedium::GetRemotePeripheral

Added:
nearby::api::ble_v2::BlePeripheral::GetUniqueId()
nearby::api::ble_v2::BleMedium::GetRemotePeripheral(...)

Moved BlePeripheral implementation from bluetooth_adapter_* to ble_v2.*
Added G3 (test) implementation for the new methods.

PiperOrigin-RevId: 531023568
This commit is contained in:
Janusz Sobczak
2023-05-10 15:40:38 -07:00
committed by Copybara-Service
parent 69f4feaf55
commit 0901aec6e2
29 changed files with 597 additions and 354 deletions
@@ -26,6 +26,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/synchronization/mutex.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/cancellation_flag_listener.h"
#include "internal/platform/implementation/ble_v2.h"
@@ -842,5 +843,34 @@ void BleV2Medium::AdvertisementReceivedHandler(
}
}
bool BleV2Medium::GetRemotePeripheral(absl::string_view mac_address,
GetRemotePeripheralCallback callback) {
for (auto& item : peripherals_) {
if (item.second->GetAddress() == mac_address) {
callback(*(item.second));
return true;
}
}
auto peripheral = std::make_unique<BleV2Peripheral>();
peripheral->SetAddress(mac_address);
if (peripheral->GetUniqueId() == 0) {
return false;
}
BleV2Peripheral* ptr = peripheral.get();
peripherals_[peripheral->GetUniqueId()] = std::move(peripheral);
callback(*ptr);
return true;
}
bool BleV2Medium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) {
auto it = peripherals_.find(id);
if (it == peripherals_.end()) {
return false;
}
callback(*(it->second));
return true;
}
} // namespace windows
} // namespace nearby