diff --git a/internal/platform/ble_v2.cc b/internal/platform/ble_v2.cc index 0d71bda4..2dbaf67d 100644 --- a/internal/platform/ble_v2.cc +++ b/internal/platform/ble_v2.cc @@ -43,7 +43,7 @@ BleV2Medium::StartAdvertising( api::ble_v2::AdvertiseParameters advertise_set_parameters, api::ble_v2::BleMedium::AdvertisingCallback callback) { return impl_->StartAdvertising(advertising_data, advertise_set_parameters, - callback); + std::move(callback)); } bool BleV2Medium::StartScanning(const Uuid& service_uuid, @@ -111,16 +111,18 @@ BleV2Medium::StartScanning(const Uuid& service_uuid, service_uuid, tx_power_level, api::ble_v2::BleMedium::ScanningCallback{ .start_scanning_result = - [this, callback](absl::Status status) { + [this, start_scanning_result = + std::move(callback.start_scanning_result)]( + absl::Status status) mutable { { MutexLock lock(&mutex_); if (status.ok()) { scanning_enabled_ = true; } } - callback.start_scanning_result(status); + start_scanning_result(status); }, - .advertisement_found_cb = callback.advertisement_found_cb, + .advertisement_found_cb = std::move(callback.advertisement_found_cb), }); } diff --git a/internal/platform/implementation/apple/ble.mm b/internal/platform/implementation/apple/ble.mm index 0f5ad985..3a83fa3c 100644 --- a/internal/platform/implementation/apple/ble.mm +++ b/internal/platform/implementation/apple/ble.mm @@ -370,13 +370,14 @@ bool BleMedium::StartScanning(const Uuid& service_uuid, TxPowerLevel tx_power_le central_ = [[GNCMBleCentral alloc] init]; } + __block ScanCallback callback = std::move(scan_callback); [central_ startScanningWithServiceUUID:ObjCStringFromCppString(service_uuid.Get16BitAsString()) scanResultHandler:^(NSString* peripheralID, NSData* serviceData) { BleAdvertisementData advertisement_data; advertisement_data.service_data = {{service_uuid, ByteArrayFromNSData(serviceData)}}; BlePeripheral& peripheral = adapter_->GetPeripheral(); peripheral.SetPeripheralId(CppStringFromObjCString(peripheralID)); - scan_callback.advertisement_found_cb(peripheral, advertisement_data); + callback.advertisement_found_cb(peripheral, advertisement_data); } requestConnectionHandler:^(GNCMBleConnectionRequester connectionRequester) { BlePeripheral& peripheral = adapter_->GetPeripheral(); @@ -393,8 +394,7 @@ bool BleMedium::StopScanning() { } std::unique_ptr BleMedium::StartScanning( - const Uuid& service_uuid, TxPowerLevel tx_power_level, - BleMedium::ScanningCallback callback) { + const Uuid& service_uuid, TxPowerLevel tx_power_level, BleMedium::ScanningCallback callback) { // TODO(hais): add real impl for windows StartScanning. return std::make_unique(ScanningSession{}); } diff --git a/internal/platform/implementation/ble_v2.h b/internal/platform/implementation/ble_v2.h index d617ee5d..852fa76b 100644 --- a/internal/platform/implementation/ble_v2.h +++ b/internal/platform/implementation/ble_v2.h @@ -224,19 +224,19 @@ class GattServer { struct ClientGattConnectionCallback { public: // Called when the client is disconnected from the GATT server. - std::function disconnected_cb = DefaultCallback<>(); + absl::AnyInvocable disconnected_cb = []() {}; }; // Callback for asynchronous events on the server side of a GATT connection. struct ServerGattConnectionCallback { // Called when a remote peripheral connected to us and subscribed to one of // our characteristics. - std::function + absl::AnyInvocable characteristic_subscription_cb; // Called when a remote peripheral unsubscribed from one of our // characteristics. - std::function + absl::AnyInvocable characteristic_unsubscription_cb; }; @@ -298,11 +298,11 @@ class BleMedium { AdvertiseParameters advertise_set_parameters) = 0; struct AdvertisingCallback { - std::function start_advertising_result; + absl::AnyInvocable start_advertising_result; }; struct AdvertisingSession { - std::function stop_advertising; + absl::AnyInvocable stop_advertising; }; // Async interface for StartAdertising. @@ -332,10 +332,9 @@ class BleMedium { // The peripheral is owned by platform implementation and it should outlive // for the whole peripheral(device) connection life cycle. struct ScanCallback { - std::function - advertisement_found_cb = - DefaultCallback(); + absl::AnyInvocable + advertisement_found_cb = [](BlePeripheral&, BleAdvertisementData) {}; }; // https://developer.android.com/reference/android/bluetooth/le/BluetoothLeScanner.html#startScan(java.util.List%3Candroid.bluetooth.le.ScanFilter%3E,%20android.bluetooth.le.ScanSettings,%20android.bluetooth.le.ScanCallback) @@ -359,16 +358,15 @@ class BleMedium { virtual bool StopScanning() = 0; struct ScanningSession { - std::function stop_scanning; + absl::AnyInvocable stop_scanning; }; struct ScanningCallback { - std::function start_scanning_result = - DefaultCallback(); - std::function - advertisement_found_cb = - DefaultCallback(); + absl::AnyInvocable start_scanning_result = + [](absl::Status) {}; + absl::AnyInvocable + advertisement_found_cb = [](BlePeripheral&, BleAdvertisementData) {}; }; // Async interface for StartScanning. diff --git a/internal/platform/implementation/g3/ble_v2.cc b/internal/platform/implementation/g3/ble_v2.cc index 2b9b5e71..c1e071d8 100644 --- a/internal/platform/implementation/g3/ble_v2.cc +++ b/internal/platform/implementation/g3/ble_v2.cc @@ -283,7 +283,8 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid, absl::MutexLock lock(&mutex_); MediumEnvironment::Instance().UpdateBleV2MediumForScanning( /*enabled=*/true, service_uuid, internal_session_id, - {.advertisement_found_cb = callback.advertisement_found_cb}, *this); + {.advertisement_found_cb = std::move(callback.advertisement_found_cb)}, + *this); scanning_internal_session_ids_.insert({service_uuid, internal_session_id}); return true; } @@ -310,10 +311,10 @@ std::unique_ptr BleV2Medium::StartScanning( absl::MutexLock lock(&mutex_); MediumEnvironment::Instance().UpdateBleV2MediumForScanning( - /*enabled=*/true, service_uuid, internal_session_id, callback, *this); + /*enabled=*/true, service_uuid, internal_session_id, + std::move(callback), *this); scanning_internal_session_ids_.insert({service_uuid, internal_session_id}); } - callback.start_scanning_result(absl::OkStatus()); return std::make_unique(ScanningSession{ .stop_scanning = [this, service_uuid = service_uuid, diff --git a/internal/platform/implementation/windows/ble_v2_test.cc b/internal/platform/implementation/windows/ble_v2_test.cc index a3ca4cfc..e57b0cf7 100644 --- a/internal/platform/implementation/windows/ble_v2_test.cc +++ b/internal/platform/implementation/windows/ble_v2_test.cc @@ -67,7 +67,7 @@ TEST(BleV2Medium, DISABLED_StartScanning) { }; EXPECT_TRUE(blev2_medium.StartScanning( - service_uuid, api::ble_v2::TxPowerLevel::kHigh, callback)); + service_uuid, api::ble_v2::TxPowerLevel::kHigh, std::move(callback))); EXPECT_TRUE(scan_response_notification.WaitForNotificationWithTimeout( absl::Seconds(5))); @@ -85,7 +85,7 @@ TEST(BleV2Medium, DISABLED_StopScanning) { const api::ble_v2::BleAdvertisementData& advertisement_data) {}; EXPECT_TRUE(blev2_medium.StartScanning( - service_uuid, api::ble_v2::TxPowerLevel::kHigh, callback)); + service_uuid, api::ble_v2::TxPowerLevel::kHigh, std::move(callback))); EXPECT_TRUE(blev2_medium.StopScanning()); } diff --git a/internal/platform/medium_environment.cc b/internal/platform/medium_environment.cc index 2ab17bf5..7ac3df8a 100644 --- a/internal/platform/medium_environment.cc +++ b/internal/platform/medium_environment.cc @@ -318,8 +318,7 @@ void MediumEnvironment::OnWifiLanServiceStateChanged( } } -void MediumEnvironment::RunOnMediumEnvironmentThread( - std::function runnable) { +void MediumEnvironment::RunOnMediumEnvironmentThread(Runnable runnable) { job_count_++; executor_.Execute(std::move(runnable)); } @@ -582,7 +581,8 @@ void MediumEnvironment::UpdateBleV2MediumForScanning( RunOnMediumEnvironmentThread([this, &medium, scanning_service_uuid = scanning_service_uuid, internal_session_id = internal_session_id, - callback = std::move(callback), enabled]() { + callback = std::move(callback), + enabled]() mutable { auto it = ble_v2_mediums_.find(&medium); if (it == ble_v2_mediums_.end()) { NEARBY_LOGS(INFO) @@ -598,8 +598,8 @@ void MediumEnvironment::UpdateBleV2MediumForScanning( if (enabled) { context.scanning = true; callback.start_scanning_result(absl::OkStatus()); - context.scan_callback_map.insert( - {{scanning_service_uuid, internal_session_id}, std::move(callback)}); + context.scan_callback_map[{scanning_service_uuid, internal_session_id}] = + std::move(callback); absl::flat_hash_set scanning_service_uuids; for (auto& element : context.scan_callback_map) { scanning_service_uuids.insert(element.first.first); @@ -724,7 +724,7 @@ MediumEnvironment::GetBleV2MediumStatus(const api::ble_v2::BleMedium& medium) { latch.CountDown(); return; } - BleV2MediumContext context = it->second; + BleV2MediumContext& context = it->second; result = BleV2MediumStatus{.is_advertising = context.advertising, .is_scanning = context.scanning}; diff --git a/internal/platform/medium_environment.h b/internal/platform/medium_environment.h index 2b366de8..668d869a 100644 --- a/internal/platform/medium_environment.h +++ b/internal/platform/medium_environment.h @@ -433,7 +433,7 @@ class MediumEnvironment { const NsdServiceInfo& service_info, bool enabled); - void RunOnMediumEnvironmentThread(std::function runnable); + void RunOnMediumEnvironmentThread(Runnable runnable); std::atomic_bool enabled_ = false; std::atomic_int job_count_ = 0; diff --git a/presence/BUILD b/presence/BUILD index efc7d138..25f23ce8 100644 --- a/presence/BUILD +++ b/presence/BUILD @@ -52,7 +52,6 @@ cc_library( "device_motion.h", "discovery_filter.h", "discovery_options.h", - "listeners.h", "power_mode.h", "presence_action.h", "presence_device.h", diff --git a/presence/data_types.h b/presence/data_types.h index e3f824fb..8333e7ff 100644 --- a/presence/data_types.h +++ b/presence/data_types.h @@ -33,17 +33,19 @@ using ScanSessionId = uint64_t; // empty functions. struct ScanCallback { // Updates client with the result of start scanning. - std::function start_scan_cb = [](absl::Status) {}; + absl::AnyInvocable start_scan_cb = [](absl::Status) {}; // Reports a {@link PresenceDevice} being discovered. - std::function on_discovered_cb = [](PresenceDevice) {}; + absl::AnyInvocable on_discovered_cb = + [](PresenceDevice) {}; // Reports a {@link PresenceDevice} information(distance, and etc) // changed. - std::function on_updated_cb = [](PresenceDevice) {}; + absl::AnyInvocable on_updated_cb = [](PresenceDevice) { + }; // Reports a {@link PresenceDevice} is no longer within range. - std::function on_lost_cb = [](PresenceDevice) {}; + absl::AnyInvocable on_lost_cb = [](PresenceDevice) {}; }; // Unique Broadcast Session Identifier. @@ -53,7 +55,8 @@ using BroadcastSessionId = uint64_t; // don't need these signal updates, they can skip with the provided default // empty functions. struct BroadcastCallback { - std::function start_broadcast_cb = [](absl::Status) {}; + absl::AnyInvocable start_broadcast_cb = [](absl::Status) { + }; }; } // namespace presence diff --git a/presence/implementation/broadcast_manager.cc b/presence/implementation/broadcast_manager.cc index 1beff863..1dc2a5e4 100644 --- a/presence/implementation/broadcast_manager.cc +++ b/presence/implementation/broadcast_manager.cc @@ -45,12 +45,12 @@ absl::StatusOr BroadcastManager::StartBroadcast( RunOnServiceControllerThread( "start-broadcast", [this, id, power_mode = broadcast_request.power_mode, request = *request, - broadcast_callback = std::move(callback)]() - ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) { - sessions_.insert( - {id, BroadcastSessionState(broadcast_callback, power_mode)}); - FetchCredentials(id, std::move(request)); - }); + broadcast_callback = std::move( + callback)]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) mutable { + sessions_.insert({id, BroadcastSessionState( + std::move(broadcast_callback), power_mode)}); + FetchCredentials(id, std::move(request)); + }); return id; } diff --git a/presence/implementation/broadcast_manager.h b/presence/implementation/broadcast_manager.h index 26b65b6d..7458a76d 100644 --- a/presence/implementation/broadcast_manager.h +++ b/presence/implementation/broadcast_manager.h @@ -61,7 +61,8 @@ class BroadcastManager { public: explicit BroadcastSessionState(BroadcastCallback broadcast_callback, PowerMode power_mode) - : broadcast_callback_(broadcast_callback), power_mode_(power_mode) {} + : broadcast_callback_(std::move(broadcast_callback)), + power_mode_(power_mode) {} void SetAdvertisingSession(std::unique_ptr session); void CallStartedCallback(absl::Status status); diff --git a/presence/implementation/mediums/ble.h b/presence/implementation/mediums/ble.h index 41f10fd8..7bd43c45 100644 --- a/presence/implementation/mediums/ble.h +++ b/presence/implementation/mediums/ble.h @@ -17,6 +17,7 @@ #include #include +#include #include "internal/platform/ble_v2.h" #include "internal/platform/bluetooth_adapter.h" @@ -70,7 +71,7 @@ class Ble { .is_connectable = true, }; return medium_.StartAdvertising(advertising_data, advertise_set_parameters, - callback); + std::move(callback)); } // Starts scanning for NP advertisements. The caller should use the returned @@ -79,7 +80,8 @@ class Ble { ScanningCallback callback) { return medium_.StartScanning( kPresenceServiceUuid, - ConvertPowerModeToPowerLevel(scan_request.power_mode), callback); + ConvertPowerModeToPowerLevel(scan_request.power_mode), + std::move(callback)); } // Provides access to platform implementation. It's used in tests. diff --git a/presence/implementation/scan_manager.cc b/presence/implementation/scan_manager.cc index 8e12550e..d335bee6 100644 --- a/presence/implementation/scan_manager.cc +++ b/presence/implementation/scan_manager.cc @@ -48,34 +48,37 @@ ScanSessionId ScanManager::StartScan(ScanRequest scan_request, ScanCallback cb) { ScanSessionId id = ::crypto::RandData(); RunOnServiceControllerThread( - "start-scan", [this, id, scan_request, - scan_callback = std::move( - cb)]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) { - ScanningCallback callback = ScanningCallback{ - .start_scanning_result = - [start_scan_client = std::move(scan_callback.start_scan_cb)]( - absl::Status ble_status) { start_scan_client(ble_status); }, - // TODO(b/256686710): Track known devices - .advertisement_found_cb = - [this, id](BlePeripheral& peripheral, - BleAdvertisementData data) { - RunOnServiceControllerThread( - "notify-found-ble", - [this, id, data = std::move(data), - address = peripheral.GetAddress()]() - ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) { - NotifyFoundBle(id, data, address); - }); - }}; - FetchCredentials(id, scan_request); - scan_sessions_.insert( - {id, ScanSessionState{ - .request = scan_request, - .callback = std::move(scan_callback), - .decoder = AdvertisementDecoder(scan_request), - .scanning_session = mediums_->GetBle().StartScanning( - scan_request, std::move(callback))}}); - }); + "start-scan", + [this, id, scan_request, scan_callback = std::move(cb)]() + ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) mutable { + ScanningCallback callback = ScanningCallback{ + .start_scanning_result = + [start_scan_client = + std::move(scan_callback.start_scan_cb)]( + absl::Status ble_status) mutable { + start_scan_client(ble_status); + }, + // TODO(b/256686710): Track known devices + .advertisement_found_cb = + [this, id](BlePeripheral& peripheral, + BleAdvertisementData data) { + RunOnServiceControllerThread( + "notify-found-ble", + [this, id, data = std::move(data), + address = peripheral.GetAddress()]() + ABSL_EXCLUSIVE_LOCKS_REQUIRED(*executor_) { + NotifyFoundBle(id, data, address); + }); + }}; + FetchCredentials(id, scan_request); + scan_sessions_.insert( + {id, ScanSessionState{ + .request = scan_request, + .callback = std::move(scan_callback), + .decoder = AdvertisementDecoder(scan_request), + .scanning_session = mediums_->GetBle().StartScanning( + scan_request, std::move(callback))}}); + }); return id; } diff --git a/presence/implementation/scan_manager_test.cc b/presence/implementation/scan_manager_test.cc index 67facd21..7eaa6e9f 100644 --- a/presence/implementation/scan_manager_test.cc +++ b/presence/implementation/scan_manager_test.cc @@ -206,7 +206,8 @@ TEST_F(ScanManagerTest, PresenceDeviceMetadataIsRetained) { // Start scanning ScanRequest scan_request_no_filter = MakeDefaultScanRequest(); scan_request_no_filter.scan_filters.clear(); - auto scan_session = manager.StartScan(scan_request_no_filter, callback); + auto scan_session = + manager.StartScan(scan_request_no_filter, std::move(callback)); ASSERT_EQ(manager.ScanningCallbacksLengthForTest(), 1); ASSERT_TRUE(mediums.GetBle().IsAvailable()); diff --git a/presence/implementation/service_controller_impl.cc b/presence/implementation/service_controller_impl.cc index a616bde4..c49e035f 100644 --- a/presence/implementation/service_controller_impl.cc +++ b/presence/implementation/service_controller_impl.cc @@ -14,6 +14,8 @@ #include "presence/implementation/service_controller_impl.h" +#include + #include "absl/status/statusor.h" #include "presence/data_types.h" @@ -22,7 +24,7 @@ namespace presence { absl::StatusOr ServiceControllerImpl::StartScan( ScanRequest scan_request, ScanCallback callback) { - return scan_manager_.StartScan(scan_request, callback); + return scan_manager_.StartScan(scan_request, std::move(callback)); } void ServiceControllerImpl::StopScan(ScanSessionId id) { scan_manager_.StopScan(id); @@ -30,7 +32,8 @@ void ServiceControllerImpl::StopScan(ScanSessionId id) { absl::StatusOr ServiceControllerImpl::StartBroadcast( BroadcastRequest broadcast_request, BroadcastCallback callback) { - return broadcast_manager_.StartBroadcast(broadcast_request, callback); + return broadcast_manager_.StartBroadcast(broadcast_request, + std::move(callback)); } void ServiceControllerImpl::StopBroadcast(BroadcastSessionId id) { diff --git a/presence/listeners.h b/presence/listeners.h deleted file mode 100644 index ab52a473..00000000 --- a/presence/listeners.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef THIRD_PARTY_NEARBY_PRESENCE_LISTENERS_H_ -#define THIRD_PARTY_NEARBY_PRESENCE_LISTENERS_H_ - -#include - -#include "absl/status/status.h" -#include "internal/platform/listeners.h" - -namespace nearby { -namespace presence { - -// Common callback for asynchronously invoked methods. -// Called after a job scheduled for execution is completed. -struct ResultCallback { - // Callback to access the status of the operation when available. - // status - result of job execution; - // Status::kSuccess, if successful; anything else indicates failure. - std::function result_cb = - nearby::DefaultCallback(); -}; - -} // namespace presence -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_PRESENCE_LISTENERS_H_ diff --git a/presence/presence_client.cc b/presence/presence_client.cc index 8cb8e86c..32418486 100644 --- a/presence/presence_client.cc +++ b/presence/presence_client.cc @@ -33,7 +33,7 @@ absl::StatusOr PresenceClient::StartScan( return absl::FailedPreconditionError( "Can't start scan, presence service is gone"); } - return (*borrowed)->StartScan(scan_request, callback); + return (*borrowed)->StartScan(scan_request, std::move(callback)); } void PresenceClient::StopScan(ScanSessionId id) { @@ -50,7 +50,7 @@ absl::StatusOr PresenceClient::StartBroadcast( return absl::FailedPreconditionError( "Can't start broadcast, presence service is gone"); } - return (*borrowed)->StartBroadcast(broadcast_request, callback); + return (*borrowed)->StartBroadcast(broadcast_request, std::move(callback)); } void PresenceClient::StopBroadcast(BroadcastSessionId session_id) { diff --git a/presence/presence_client_test.cc b/presence/presence_client_test.cc index 33f0c8e7..2403ad15 100644 --- a/presence/presence_client_test.cc +++ b/presence/presence_client_test.cc @@ -43,14 +43,14 @@ class PresenceClientTest : public testing::Test { TEST_F(PresenceClientTest, StartBroadcastWithDefaultConstructor) { env_.Start(); absl::Status broadcast_result; - BroadcastCallback broadcast_callback = { - .start_broadcast_cb = - [&](absl::Status status) { broadcast_result = status; }, - }; PresenceService presence_service; PresenceClient presence_client = presence_service.CreatePresenceClient(); - auto unused = presence_client.StartBroadcast({}, broadcast_callback); + auto unused = presence_client.StartBroadcast( + {}, { + .start_broadcast_cb = + [&](absl::Status status) { broadcast_result = status; }, + }); EXPECT_THAT(broadcast_result, StatusIs(absl::StatusCode::kInvalidArgument)); env_.Stop(); @@ -59,13 +59,13 @@ TEST_F(PresenceClientTest, StartBroadcastWithDefaultConstructor) { TEST_F(PresenceClientTest, StartBroadcastFailsWhenPresenceServiceIsGone) { env_.Start(); absl::Status broadcast_result = absl::UnknownError(""); - BroadcastCallback broadcast_callback = { - .start_broadcast_cb = - [&](absl::Status status) { broadcast_result = status; }, - }; absl::StatusOr session_id = - CreateDefunctPresenceClient().StartBroadcast({}, broadcast_callback); + CreateDefunctPresenceClient().StartBroadcast( + {}, { + .start_broadcast_cb = + [&](absl::Status status) { broadcast_result = status; }, + }); EXPECT_THAT(session_id, StatusIs(absl::StatusCode::kFailedPrecondition)); EXPECT_THAT(broadcast_result, StatusIs(absl::StatusCode::kUnknown)); @@ -81,7 +81,7 @@ TEST_F(PresenceClientTest, StartScanWithDefaultConstructor) { PresenceService presence_service; PresenceClient presence_client = presence_service.CreatePresenceClient(); - EXPECT_OK(presence_client.StartScan({}, scan_callback)); + EXPECT_OK(presence_client.StartScan({}, std::move(scan_callback))); EXPECT_TRUE(scan_result.Get().ok()); EXPECT_OK(scan_result.Get().GetResult()); @@ -91,12 +91,13 @@ TEST_F(PresenceClientTest, StartScanWithDefaultConstructor) { TEST_F(PresenceClientTest, StartScanFailsWhenPresenceServiceIsGone) { env_.Start(); absl::Status scan_result = absl::UnknownError(""); - ScanCallback scan_callback = { - .start_scan_cb = [&](absl::Status status) { scan_result = status; }, - }; absl::StatusOr session_id = - CreateDefunctPresenceClient().StartScan({}, scan_callback); + CreateDefunctPresenceClient().StartScan( + {}, { + .start_scan_cb = + [&](absl::Status status) { scan_result = status; }, + }); EXPECT_THAT(session_id, StatusIs(absl::StatusCode::kFailedPrecondition)); EXPECT_THAT(scan_result, StatusIs(absl::StatusCode::kUnknown)); diff --git a/presence/presence_service.cc b/presence/presence_service.cc index 7226bee0..e4d4c3b8 100644 --- a/presence/presence_service.cc +++ b/presence/presence_service.cc @@ -15,6 +15,7 @@ #include "presence/presence_service.h" #include +#include #include "internal/platform/borrowable.h" #include "presence/data_types.h" @@ -32,7 +33,7 @@ PresenceClient PresenceService::CreatePresenceClient() { absl::StatusOr PresenceService::StartScan( ScanRequest scan_request, ScanCallback callback) { - return service_controller_->StartScan(scan_request, callback); + return service_controller_->StartScan(scan_request, std::move(callback)); } void PresenceService::StopScan(ScanSessionId id) { service_controller_->StopScan(id); @@ -40,7 +41,8 @@ void PresenceService::StopScan(ScanSessionId id) { absl::StatusOr PresenceService::StartBroadcast( BroadcastRequest broadcast_request, BroadcastCallback callback) { - return service_controller_->StartBroadcast(broadcast_request, callback); + return service_controller_->StartBroadcast(broadcast_request, + std::move(callback)); } void PresenceService::StopBroadcast(BroadcastSessionId session) {