Roll forward to cl/329875420

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I50e284b30472160a409829957b2cb3926babfede
This commit is contained in:
Alexey Polyudov
2020-09-03 02:09:56 -07:00
parent c673bf6ac0
commit d5bed12d40
39 changed files with 1210 additions and 622 deletions
+2 -1
View File
@@ -46,7 +46,8 @@ bool BleMedium::StartScanning(const std::string& service_id,
&context.peripheral, &peripheral,
peripheral.GetName().c_str());
discovered_peripheral_callback_.peripheral_discovered_cb(
context.peripheral, service_id);
context.peripheral, service_id,
/*fast_advertisement=*/false);
}
},
.peripheral_lost_cb =
+3 -2
View File
@@ -72,9 +72,10 @@ class BleMedium final {
using Platform = api::ImplementationPlatform;
struct DiscoveredPeripheralCallback {
std::function<void(BlePeripheral& peripheral,
const std::string& service_id)>
const std::string& service_id,
bool fast_advertisement)>
peripheral_discovered_cb =
DefaultCallback<BlePeripheral&, const std::string&>();
DefaultCallback<BlePeripheral&, const std::string&, bool>();
std::function<void(BlePeripheral& peripheral,
const std::string& service_id)>
peripheral_lost_cb =
+40 -36
View File
@@ -55,13 +55,13 @@ TEST_F(BleMediumTest, CanStartAdvertising) {
ble_a.StartAdvertising(service_id, advertisement_bytes);
EXPECT_TRUE(ble_b.StartScanning(
service_id, DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BlePeripheral& peripheral,
const std::string& service_id) {
found_latch.CountDown();
},
}));
service_id,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](
BlePeripheral& peripheral, const std::string& service_id,
bool fast_advertisement) { found_latch.CountDown(); },
}));
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_a.StopAdvertising(service_id));
EXPECT_TRUE(ble_b.StopScanning(service_id));
@@ -79,19 +79,19 @@ TEST_F(BleMediumTest, CanStartScanning) {
CountDownLatch found_latch(1);
CountDownLatch lost_latch(1);
ble_a.StartScanning(service_id,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BlePeripheral& peripheral,
const std::string& service_id) {
found_latch.CountDown();
},
.peripheral_lost_cb =
[&lost_latch](BlePeripheral& peripheral,
const std::string& service_id) {
lost_latch.CountDown();
},
});
ble_a.StartScanning(
service_id,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](
BlePeripheral& peripheral, const std::string& service_id,
bool fast_advertisement) { found_latch.CountDown(); },
.peripheral_lost_cb =
[&lost_latch](BlePeripheral& peripheral,
const std::string& service_id) {
lost_latch.CountDown();
},
});
EXPECT_TRUE(ble_b.StartAdvertising(service_id, advertisement_bytes));
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_b.StopAdvertising(service_id));
@@ -111,19 +111,19 @@ TEST_F(BleMediumTest, CanStopDiscovery) {
CountDownLatch found_latch(1);
CountDownLatch lost_latch(1);
ble_a.StartScanning(service_id,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BlePeripheral& peripheral,
const std::string& service_id) {
found_latch.CountDown();
},
.peripheral_lost_cb =
[&lost_latch](BlePeripheral& peripheral,
const std::string& service_id) {
lost_latch.CountDown();
},
});
ble_a.StartScanning(
service_id,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](
BlePeripheral& peripheral, const std::string& service_id,
bool fast_advertisement) { found_latch.CountDown(); },
.peripheral_lost_cb =
[&lost_latch](BlePeripheral& peripheral,
const std::string& service_id) {
lost_latch.CountDown();
},
});
EXPECT_TRUE(ble_b.StartAdvertising(service_id, advertisement_bytes));
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_a.StopScanning(service_id));
@@ -149,9 +149,13 @@ TEST_F(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch, &discovered_peripheral](
BlePeripheral& peripheral, const std::string& service_id) {
NEARBY_LOG(INFO, "Peripheral discovered: %s, %p",
peripheral.GetName().c_str(), &peripheral);
BlePeripheral& peripheral, const std::string& service_id,
bool fast_advertisement) {
NEARBY_LOG(
INFO,
"Peripheral discovered: %s, %p, fast advertisement: %d",
peripheral.GetName().c_str(), &peripheral,
fast_advertisement);
discovered_peripheral = &peripheral;
found_latch.CountDown();
},