mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Migrate to AnyInvocable in platform code
PiperOrigin-RevId: 504104740
This commit is contained in:
committed by
Copybara-Service
parent
7f34968b78
commit
f4d85f9b90
@@ -19,11 +19,11 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/shared/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/implementation/shared/count_down_latch.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -135,7 +135,7 @@ bool BleServerSocket::Connect(BleSocket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BleServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void BleServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
@@ -303,7 +303,8 @@ bool BleMedium::StartAcceptingConnections(const std::string& service_id,
|
||||
NEARBY_LOGS(INFO) << "G3 Ble StartAcceptingConnections: service_id="
|
||||
<< service_id;
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UpdateBleMediumForAcceptedConnection(*this, service_id, callback);
|
||||
env.UpdateBleMediumForAcceptedConnection(*this, service_id,
|
||||
std::move(callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/g3/multi_thread_executor.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -125,7 +125,7 @@ class BleServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// BleServerSocker to user, to track validity of a pointer to this
|
||||
// server socket,
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -138,7 +138,7 @@ class BleServerSocket {
|
||||
absl::Mutex mutex_;
|
||||
absl::CondVar cond_;
|
||||
absl::flat_hash_set<BleSocket*> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "internal/platform/implementation/g3/ble_v2.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -166,7 +165,7 @@ bool BleV2ServerSocket::Connect(BleV2Socket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BleV2ServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void BleV2ServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define PLATFORM_IMPL_G3_BLE_V2_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -133,7 +132,7 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// BleServerSocker to user, to track validity of a pointer to this
|
||||
// server socket.
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -147,7 +146,7 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
absl::CondVar cond_;
|
||||
BluetoothAdapter* adapter_ = nullptr; // Our Adapter. Read only.
|
||||
absl::flat_hash_set<BleV2Socket*> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -139,7 +139,8 @@ bool BluetoothServerSocket::Connect(BluetoothSocket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BluetoothServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void BluetoothServerSocket::SetCloseNotifier(
|
||||
absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/listeners.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -137,7 +137,7 @@ class BluetoothServerSocket : public api::BluetoothServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// BluetoothServerSocker to user, to track validity of a pointer to this
|
||||
// server socket,
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -152,7 +152,7 @@ class BluetoothServerSocket : public api::BluetoothServerSocket {
|
||||
BluetoothAdapter* adapter_ = nullptr; // Our Adapter. Read only.
|
||||
absl::flat_hash_set<BluetoothSocket*> pending_sockets_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#ifndef PLATFORM_IMPL_G3_TIMER_H_
|
||||
#define PLATFORM_IMPL_G3_TIMER_H_
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/implementation/timer.h"
|
||||
@@ -29,7 +28,7 @@ class Timer : public api::Timer {
|
||||
~Timer() override = default;
|
||||
|
||||
bool Create(int delay, int interval,
|
||||
std::function<void()> callback) override {
|
||||
absl::AnyInvocable<void()> callback) override {
|
||||
if (delay < 0 || interval < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -61,7 +60,7 @@ class Timer : public api::Timer {
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> callback_;
|
||||
absl::AnyInvocable<void()> callback_;
|
||||
bool is_stopped_ = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "internal/platform/implementation/g3/webrtc.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "webrtc/api/task_queue/default_task_queue_factory.h"
|
||||
@@ -39,8 +40,8 @@ bool WebRtcSignalingMessenger::StartReceivingMessages(
|
||||
OnSignalingMessageCallback on_message_callback,
|
||||
OnSignalingCompleteCallback on_complete_callback) {
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.RegisterWebRtcSignalingMessenger(self_id_, on_message_callback,
|
||||
on_complete_callback);
|
||||
env.RegisterWebRtcSignalingMessenger(self_id_, std::move(on_message_callback),
|
||||
std::move(on_complete_callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ void WebRtcMedium::CreatePeerConnection(
|
||||
|
||||
single_thread_executor_.Execute(
|
||||
[&env, callback = std::move(callback),
|
||||
peer_connection = peer_connection_or_error.MoveValue()]() {
|
||||
peer_connection = peer_connection_or_error.MoveValue()]() mutable {
|
||||
absl::SleepFor(env.GetPeerConnectionLatency());
|
||||
callback(peer_connection);
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "internal/platform/implementation/g3/wifi_direct.h"
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -30,7 +29,6 @@
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
|
||||
|
||||
// Code for WifiDirectSocket
|
||||
WifiDirectSocket::~WifiDirectSocket() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
@@ -94,7 +92,7 @@ OutputStream& WifiDirectSocket::GetLocalOutputStream() {
|
||||
|
||||
// Code for WifiDirectServerSocket
|
||||
std::string WifiDirectServerSocket::GetName(absl::string_view ip_address,
|
||||
int port) {
|
||||
int port) {
|
||||
return absl::StrCat(ip_address, ":", port);
|
||||
}
|
||||
|
||||
@@ -134,7 +132,8 @@ bool WifiDirectServerSocket::Connect(WifiDirectSocket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiDirectServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void WifiDirectServerSocket::SetCloseNotifier(
|
||||
absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
@@ -291,8 +290,8 @@ std::unique_ptr<api::WifiDirectSocket> WifiDirectMedium::ConnectToService(
|
||||
return socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WifiDirectServerSocket>
|
||||
WifiDirectMedium::ListenForService(int port) {
|
||||
std::unique_ptr<api::WifiDirectServerSocket> WifiDirectMedium::ListenForService(
|
||||
int port) {
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
auto server_socket = std::make_unique<WifiDirectServerSocket>();
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#ifndef PLATFORM_IMPL_G3_WIFI_DIRECT_H_
|
||||
#define PLATFORM_IMPL_G3_WIFI_DIRECT_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -144,7 +143,7 @@ class WifiDirectServerSocket : public api::WifiDirectServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// WifiDirectServerSocker to user, to track validity of a pointer to this
|
||||
// server socket.
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -164,7 +163,7 @@ class WifiDirectServerSocket : public api::WifiDirectServerSocket {
|
||||
absl::CondVar cond_;
|
||||
absl::flat_hash_set<WifiDirectSocket*> pending_sockets_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "internal/platform/implementation/g3/wifi_hotspot.h"
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -23,8 +22,8 @@
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
|
||||
@@ -99,7 +98,7 @@ OutputStream& WifiHotspotSocket::GetLocalOutputStream() {
|
||||
|
||||
// Code for WifiHotspotServerSocket
|
||||
std::string WifiHotspotServerSocket::GetName(absl::string_view ip_address,
|
||||
int port) {
|
||||
int port) {
|
||||
return absl::StrCat(ip_address, ":", port);
|
||||
}
|
||||
|
||||
@@ -139,7 +138,8 @@ bool WifiHotspotServerSocket::Connect(WifiHotspotSocket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiHotspotServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void WifiHotspotServerSocket::SetCloseNotifier(
|
||||
absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
@@ -186,8 +186,7 @@ bool WifiHotspotMedium::StartWifiHotspot(
|
||||
HotspotCredentials* hotspot_credentials) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
if (!IsInterfaceValid())
|
||||
return false;
|
||||
if (!IsInterfaceValid()) return false;
|
||||
|
||||
std::string ssid = absl::StrCat("DIRECT-", Prng().NextUint32());
|
||||
hotspot_credentials->SetSSID(ssid);
|
||||
@@ -199,7 +198,8 @@ bool WifiHotspotMedium::StartWifiHotspot(
|
||||
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
/*is_ap=*/true, /*enabled=*/true);
|
||||
/*is_ap=*/true,
|
||||
/*enabled=*/true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -208,13 +208,12 @@ bool WifiHotspotMedium::StopWifiHotspot() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
NEARBY_LOGS(INFO) << "G3 StopWifiHotspot";
|
||||
|
||||
if (!IsInterfaceValid())
|
||||
return false;
|
||||
if (!IsInterfaceValid()) return false;
|
||||
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, /*credentials*/nullptr,
|
||||
/*is_ap=*/true,
|
||||
/*enabled=*/false);
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, /*credentials*/ nullptr,
|
||||
/*is_ap=*/true,
|
||||
/*enabled=*/false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -230,13 +229,15 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
auto* remote_medium = static_cast<WifiHotspotMedium*>(
|
||||
env.GetWifiHotspotMedium(hotspot_credentials->GetSSID(), {}));
|
||||
if (!remote_medium) {
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
/*is_ap=*/false, /*enabled=*/false);
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
/*is_ap=*/false,
|
||||
/*enabled=*/false);
|
||||
return false;
|
||||
}
|
||||
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, hotspot_credentials,
|
||||
/*is_ap=*/false, /*enabled=*/true);
|
||||
/*is_ap=*/false,
|
||||
/*enabled=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -246,8 +247,9 @@ bool WifiHotspotMedium::DisconnectWifiHotspot() {
|
||||
NEARBY_LOGS(INFO) << "G3 DisconnectWifiHotspot";
|
||||
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, /*credentials*/nullptr,
|
||||
/*is_ap=*/false, /*enabled=*/false);
|
||||
env.UpdateWifiHotspotMediumForStartOrConnect(*this, /*credentials*/ nullptr,
|
||||
/*is_ap=*/false,
|
||||
/*enabled=*/false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -259,8 +261,8 @@ std::unique_ptr<api::WifiHotspotSocket> WifiHotspotMedium::ConnectToService(
|
||||
<< ", ip address + port=" << socket_name;
|
||||
// First, find an instance of remote medium, that exposed this service.
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
auto* remote_medium = static_cast<WifiHotspotMedium*>(
|
||||
env.GetWifiHotspotMedium({}, ip_address));
|
||||
auto* remote_medium =
|
||||
static_cast<WifiHotspotMedium*>(env.GetWifiHotspotMedium({}, ip_address));
|
||||
if (remote_medium == nullptr) {
|
||||
return {};
|
||||
}
|
||||
@@ -318,8 +320,7 @@ WifiHotspotMedium::ListenForService(int port) {
|
||||
|
||||
std::string dot_decimal_ip;
|
||||
std::string ip_address = env.GetFakeIPAddress();
|
||||
if (ip_address.empty())
|
||||
return nullptr;
|
||||
if (ip_address.empty()) return nullptr;
|
||||
|
||||
for (auto byte : ip_address) {
|
||||
absl::StrAppend(&dot_decimal_ip, absl::StrFormat("%d", byte), ".");
|
||||
|
||||
@@ -15,19 +15,18 @@
|
||||
#ifndef PLATFORM_IMPL_G3_WIFI_HOTSPOT_H_
|
||||
#define PLATFORM_IMPL_G3_WIFI_HOTSPOT_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/implementation/g3/multi_thread_executor.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -64,7 +63,7 @@ class WifiHotspotSocket : public api::WifiHotspotSocket {
|
||||
// Returns address of a remote WifiHotspotSocket or nullptr.
|
||||
WifiHotspotSocket* GetRemoteSocket() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns true if connection exists to the (possibly closed) remote socket.
|
||||
// Returns true if connection exists to the (possibly closed) remote socket.
|
||||
bool IsConnected() const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns true if socket is closed.
|
||||
@@ -148,7 +147,7 @@ class WifiHotspotServerSocket : public api::WifiHotspotServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// WifiHotspotServerSocker to user, to track validity of a pointer to this
|
||||
// server socket.
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -168,7 +167,7 @@ class WifiHotspotServerSocket : public api::WifiHotspotServerSocket {
|
||||
absl::CondVar cond_;
|
||||
absl::flat_hash_set<WifiHotspotSocket*> pending_sockets_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
@@ -184,7 +183,7 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
WifiHotspotMedium& operator=(WifiHotspotMedium&&) = delete;
|
||||
|
||||
// If the WiFi Adaptor supports to start a Hotspot interface.
|
||||
bool IsInterfaceValid() const override { return true;}
|
||||
bool IsInterfaceValid() const override { return true; }
|
||||
|
||||
// Discoverer connects to server socket
|
||||
std::unique_ptr<api::WifiHotspotSocket> ConnectToService(
|
||||
@@ -211,7 +210,7 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
|
||||
private:
|
||||
// Gets error message from exception pointer
|
||||
// std::string GetErrorMessage(std::exception_ptr eptr);
|
||||
// std::string GetErrorMessage(std::exception_ptr eptr);
|
||||
|
||||
// Protects to access some members
|
||||
absl::Mutex mutex_;
|
||||
@@ -220,7 +219,6 @@ class WifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
|
||||
} // namespace g3
|
||||
} // namespace nearby
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
@@ -146,7 +146,8 @@ bool WifiLanServerSocket::Connect(WifiLanSocket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiLanServerSocket::SetCloseNotifier(std::function<void()> notifier) {
|
||||
void WifiLanServerSocket::SetCloseNotifier(
|
||||
absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/g3/multi_thread_executor.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/implementation/g3/multi_thread_executor.h"
|
||||
#include "internal/platform/implementation/g3/pipe.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
@@ -144,7 +144,7 @@ class WifiLanServerSocket : public api::WifiLanServerSocket {
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// WifiLanServerSocker to user, to track validity of a pointer to this
|
||||
// server socket.
|
||||
void SetCloseNotifier(std::function<void()> notifier)
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -159,7 +159,7 @@ class WifiLanServerSocket : public api::WifiLanServerSocket {
|
||||
int port_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::CondVar cond_;
|
||||
absl::flat_hash_set<WifiLanSocket*> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
std::function<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user