mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Wi-Fi Direct Service Implementation(5)
PiperOrigin-RevId: 828017340
This commit is contained in:
@@ -161,7 +161,6 @@ cc_library(
|
||||
"webrtc.h",
|
||||
"wifi.h",
|
||||
"wifi_direct.h",
|
||||
"wifi_direct_service.h",
|
||||
"wifi_hotspot.h",
|
||||
"wifi_lan.h",
|
||||
],
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
// Copyright 2025 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 PLATFORM_IMPL_WIFI_DIRECT_SERVICE_H_
|
||||
#define PLATFORM_IMPL_WIFI_DIRECT_SERVICE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
class WifiDirectServiceSocket {
|
||||
public:
|
||||
virtual ~WifiDirectServiceSocket() = default;
|
||||
|
||||
// Returns the InputStream of the WifiDirectServiceSocket.
|
||||
// On error, returned stream will report Exception::kIo on any operation.
|
||||
//
|
||||
// The returned object is not owned by the caller, and can be invalidated once
|
||||
// the WifiDirectServiceSocket object is destroyed.
|
||||
virtual InputStream& GetInputStream() = 0;
|
||||
|
||||
// Returns the OutputStream of the WifiDirectServiceSocket.
|
||||
// On error, returned stream will report Exception::kIo on any operation.
|
||||
//
|
||||
// The returned object is not owned by the caller, and can be invalidated once
|
||||
// the WifiDirectServiceSocket object is destroyed.
|
||||
virtual OutputStream& GetOutputStream() = 0;
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
virtual Exception Close() = 0;
|
||||
};
|
||||
|
||||
class WifiDirectServiceServerSocket {
|
||||
public:
|
||||
virtual ~WifiDirectServiceServerSocket() = default;
|
||||
|
||||
virtual std::string GetIPAddress() const = 0;
|
||||
|
||||
virtual int GetPort() const = 0;
|
||||
|
||||
// Blocks until either:
|
||||
// - at least one incoming connection request is available, or
|
||||
// - ServerSocket is closed.
|
||||
// On success, returns connected socket, ready to exchange data.
|
||||
// Returns nullptr on error.
|
||||
// Once error is reported, it is permanent, and ServerSocket has to be closed.
|
||||
virtual std::unique_ptr<WifiDirectServiceSocket> Accept() = 0;
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
virtual Exception Close() = 0;
|
||||
};
|
||||
|
||||
// Container of operations that can be performed over the WifiDirectService
|
||||
// medium.
|
||||
class WifiDirectServiceMedium {
|
||||
public:
|
||||
virtual ~WifiDirectServiceMedium() = default;
|
||||
|
||||
// If the WiFi Adaptor supports to start a Hotspot interface.
|
||||
virtual bool IsInterfaceValid() const = 0;
|
||||
|
||||
// Connects to a WifiDirectService by ip address and port.
|
||||
// On success, returns a new WifiDirectServiceSocket.
|
||||
// On error, returns nullptr.
|
||||
virtual std::unique_ptr<WifiDirectServiceSocket> ConnectToService(
|
||||
absl::string_view ip_address, int port,
|
||||
CancellationFlag* cancellation_flag) = 0;
|
||||
|
||||
// Listens for incoming connection.
|
||||
//
|
||||
// port - A port number.
|
||||
// 0 : use a random port.
|
||||
// 1~65536 : open a server socket on that exact port.
|
||||
// On success, returns a new WifiDirectServiceServerSocket.
|
||||
// On error, returns nullptr.
|
||||
virtual std::unique_ptr<WifiDirectServiceServerSocket> ListenForService(
|
||||
int port) = 0;
|
||||
|
||||
// Start a softAP as Hotspot with platform dependent APIs and set the
|
||||
// SSID/password pair back to the credentials. BWU module will retrieve these
|
||||
// credentials and send to the client device through established channel and
|
||||
// then client may connect to this Hotspot with these credentials.
|
||||
virtual bool StartWifiDirectService() = 0;
|
||||
virtual bool StopWifiDirectService() = 0;
|
||||
|
||||
// Client device connect to a softAP with specified credential.
|
||||
virtual bool ConnectWifiDirectService() = 0;
|
||||
virtual bool DisconnectWifiDirectService() = 0;
|
||||
|
||||
// Returns the port range as a pair of min and max port.
|
||||
virtual absl::optional<std::pair<std::int32_t, std::int32_t>>
|
||||
GetDynamicPortRange() = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_WIFI_DIRECT_SERVICE_H_
|
||||
@@ -220,9 +220,9 @@ cc_library(
|
||||
"preferences_repository.cc",
|
||||
"system_clock.cc",
|
||||
"webrtc.cc",
|
||||
"wifi_direct_service_medium.cc",
|
||||
"wifi_direct_service_server_socket.cc",
|
||||
"wifi_direct_service_socket.cc",
|
||||
"wifi_direct_medium.cc",
|
||||
"wifi_direct_server_socket.cc",
|
||||
"wifi_direct_socket.cc",
|
||||
"wifi_hotspot_medium.cc",
|
||||
"wifi_hotspot_native.cc",
|
||||
"wifi_hotspot_server_socket.cc",
|
||||
@@ -255,7 +255,7 @@ cc_library(
|
||||
"preferences_repository.h",
|
||||
"webrtc.h",
|
||||
"wifi.h",
|
||||
"wifi_direct_service.h",
|
||||
"wifi_direct.h",
|
||||
"wifi_hotspot.h",
|
||||
"wifi_hotspot_native.h",
|
||||
"wifi_hotspot_server_socket.h",
|
||||
@@ -401,7 +401,7 @@ cc_test(
|
||||
"timer_test.cc",
|
||||
"utils_test.cc",
|
||||
"webrtc_test.cc",
|
||||
"wifi_direct_service_test.cc",
|
||||
"wifi_direct_test.cc",
|
||||
"wifi_hotspot_test.cc",
|
||||
"wifi_medium_test.cc",
|
||||
],
|
||||
|
||||
+63
-74
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_SERVICE_H_
|
||||
#define PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_SERVICE_H_
|
||||
#ifndef PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_H_
|
||||
#define PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_H_
|
||||
|
||||
// Windows headers
|
||||
#include <windows.h>
|
||||
@@ -27,20 +27,20 @@
|
||||
#include <utility>
|
||||
|
||||
// Nearby connections headers
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
#include "internal/platform/implementation/windows/nearby_client_socket.h"
|
||||
#include "internal/platform/implementation/windows/nearby_server_socket.h"
|
||||
#include "internal/platform/implementation/windows/submittable_executor.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
|
||||
// WinRT headers
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Enumeration.h"
|
||||
@@ -77,32 +77,32 @@ using ::winrt::Windows::Devices::WiFiDirect::Services::WiFiDirectServiceStatus;
|
||||
using ::winrt::Windows::Foundation::AsyncStatus;
|
||||
using ::winrt::Windows::Foundation::IInspectable;
|
||||
|
||||
// WifiDirectServiceSocket wraps the socket functions to read and write stream.
|
||||
// In WiFi HOTSPOT, A WifiDirectServiceSocket will be passed to
|
||||
// WifiDirectSocket wraps the socket functions to read and write stream.
|
||||
// In WiFi HOTSPOT, A WifiDirectSocket will be passed to
|
||||
// StartAcceptingConnections's callback when Winsock Server Socket receives a
|
||||
// new connection. When call API to connect to remote WiFi Hotspot service, also
|
||||
// will return a WifiDirectServiceSocket to caller.
|
||||
class WifiDirectServiceSocket : public api::WifiDirectServiceSocket {
|
||||
// will return a WifiDirectSocket to caller.
|
||||
class WifiDirectSocket : public api::WifiDirectSocket {
|
||||
public:
|
||||
WifiDirectServiceSocket();
|
||||
explicit WifiDirectServiceSocket(
|
||||
WifiDirectSocket();
|
||||
explicit WifiDirectSocket(
|
||||
absl_nonnull std::unique_ptr<NearbyClientSocket> socket);
|
||||
WifiDirectServiceSocket(WifiDirectServiceSocket&&) = default;
|
||||
~WifiDirectServiceSocket() override;
|
||||
WifiDirectServiceSocket& operator=(WifiDirectServiceSocket&&) = default;
|
||||
WifiDirectSocket(WifiDirectSocket&&) = default;
|
||||
~WifiDirectSocket() override;
|
||||
WifiDirectSocket& operator=(WifiDirectSocket&&) = default;
|
||||
|
||||
// Returns the InputStream of the WifiDirectServiceSocket.
|
||||
// Returns the InputStream of the WifiDirectSocket.
|
||||
// On error, returned stream will report Exception::kIo on any operation.
|
||||
//
|
||||
// The returned object is not owned by the caller, and can be invalidated once
|
||||
// the WifiDirectServiceSocket object is destroyed.
|
||||
// the WifiDirectSocket object is destroyed.
|
||||
InputStream& GetInputStream() override { return input_stream_; }
|
||||
|
||||
// Returns the OutputStream of the WifiDirectServiceSocket.
|
||||
// Returns the OutputStream of the WifiDirectSocket.
|
||||
// On error, returned stream will report Exception::kIo on any operation.
|
||||
//
|
||||
// The returned object is not owned by the caller, and can be invalidated once
|
||||
// the WifiDirectServiceSocket object is destroyed.
|
||||
// the WifiDirectSocket object is destroyed.
|
||||
OutputStream& GetOutputStream() override { return output_stream_; }
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -154,19 +154,16 @@ class WifiDirectServiceSocket : public api::WifiDirectServiceSocket {
|
||||
SocketOutputStream output_stream_;
|
||||
};
|
||||
|
||||
// WifiDirectServiceServerSocket provides the support to server socket, this
|
||||
// WifiDirectServerSocket provides the support to server socket, this
|
||||
// server socket accepts connection from clients.
|
||||
class WifiDirectServiceServerSocket
|
||||
: public api::WifiDirectServiceServerSocket {
|
||||
class WifiDirectServerSocket : public api::WifiDirectServerSocket {
|
||||
public:
|
||||
explicit WifiDirectServiceServerSocket(int port = 0);
|
||||
WifiDirectServiceServerSocket(const WifiDirectServiceServerSocket&) = default;
|
||||
WifiDirectServiceServerSocket(WifiDirectServiceServerSocket&&) = default;
|
||||
~WifiDirectServiceServerSocket() override;
|
||||
WifiDirectServiceServerSocket& operator=(
|
||||
const WifiDirectServiceServerSocket&) = default;
|
||||
WifiDirectServiceServerSocket& operator=(WifiDirectServiceServerSocket&&) =
|
||||
default;
|
||||
explicit WifiDirectServerSocket(int port = 0);
|
||||
WifiDirectServerSocket(const WifiDirectServerSocket&) = default;
|
||||
WifiDirectServerSocket(WifiDirectServerSocket&&) = default;
|
||||
~WifiDirectServerSocket() override;
|
||||
WifiDirectServerSocket& operator=(const WifiDirectServerSocket&) = default;
|
||||
WifiDirectServerSocket& operator=(WifiDirectServerSocket&&) = default;
|
||||
|
||||
std::string GetIPAddress() const override;
|
||||
int GetPort() const override;
|
||||
@@ -177,10 +174,10 @@ class WifiDirectServiceServerSocket
|
||||
// On success, returns connected socket, ready to exchange data.
|
||||
// Returns nullptr on error.
|
||||
// Once error is reported, it is permanent, and ServerSocket has to be closed.
|
||||
std::unique_ptr<api::WifiDirectServiceSocket> Accept() override;
|
||||
std::unique_ptr<api::WifiDirectSocket> Accept() override;
|
||||
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// WifiDirectServiceServerSocker to user, to track validity of a pointer to
|
||||
// WifiDirectServerSocker to user, to track validity of a pointer to
|
||||
// this server socket.
|
||||
void SetCloseNotifier(absl::AnyInvocable<void()> notifier);
|
||||
|
||||
@@ -194,7 +191,7 @@ class WifiDirectServiceServerSocket
|
||||
|
||||
private:
|
||||
// Retrieves hotspot IP address from local machine
|
||||
std::string GetWifiDirectServiceIpAddress() const;
|
||||
std::string GetWifiDirectIpAddress() const;
|
||||
|
||||
const int port_;
|
||||
mutable absl::Mutex mutex_;
|
||||
@@ -203,18 +200,17 @@ class WifiDirectServiceServerSocket
|
||||
absl::AnyInvocable<void()> close_notifier_ = nullptr;
|
||||
|
||||
// IP addresses of the server socket.
|
||||
std::string wifi_direct_service_ipaddr_ = {};
|
||||
std::string wifi_direct_ipaddr_ = {};
|
||||
bool closed_ = false;
|
||||
};
|
||||
|
||||
class WifiDirectServiceDiscovered {
|
||||
class WifiDirectDiscovered {
|
||||
public:
|
||||
explicit WifiDirectServiceDiscovered(const DeviceInformation& device_info);
|
||||
explicit WifiDirectDiscovered(const DeviceInformation& device_info);
|
||||
|
||||
~WifiDirectServiceDiscovered() = default;
|
||||
WifiDirectServiceDiscovered(WifiDirectServiceDiscovered&&) = default;
|
||||
WifiDirectServiceDiscovered& operator=(WifiDirectServiceDiscovered&&) =
|
||||
default;
|
||||
~WifiDirectDiscovered() = default;
|
||||
WifiDirectDiscovered(WifiDirectDiscovered&&) = default;
|
||||
WifiDirectDiscovered& operator=(WifiDirectDiscovered&&) = default;
|
||||
|
||||
std::string GetId() { return id_; }
|
||||
DeviceInformation GetDeviceInformation() {
|
||||
@@ -231,37 +227,35 @@ class WifiDirectServiceDiscovered {
|
||||
// std::string name_;
|
||||
};
|
||||
|
||||
class WifiDirectServiceMedium : public api::WifiDirectServiceMedium {
|
||||
class WifiDirectMedium {
|
||||
public:
|
||||
WifiDirectServiceMedium();
|
||||
~WifiDirectServiceMedium() override;
|
||||
// WifiDirectServiceMedium is neither copyable nor movable.
|
||||
WifiDirectServiceMedium(const WifiDirectServiceMedium&) = delete;
|
||||
WifiDirectServiceMedium& operator=(const WifiDirectServiceMedium&) = delete;
|
||||
WifiDirectMedium();
|
||||
~WifiDirectMedium();
|
||||
// WifiDirectMedium is neither copyable nor movable.
|
||||
WifiDirectMedium(const WifiDirectMedium&) = delete;
|
||||
WifiDirectMedium& operator=(const WifiDirectMedium&) = delete;
|
||||
|
||||
// If the WiFi Adaptor supports to start WifiDirect Service GO.
|
||||
bool IsInterfaceValid() const override;
|
||||
bool IsInterfaceValid() const;
|
||||
|
||||
// Discoverer connects to server socket
|
||||
std::unique_ptr<api::WifiDirectServiceSocket> ConnectToService(
|
||||
std::unique_ptr<api::WifiDirectSocket> ConnectToService(
|
||||
absl::string_view ip_address, int port,
|
||||
CancellationFlag* cancellation_flag) override;
|
||||
CancellationFlag* cancellation_flag);
|
||||
|
||||
// Advertiser starts to listen on server socket
|
||||
std::unique_ptr<api::WifiDirectServiceServerSocket> ListenForService(
|
||||
int port) override;
|
||||
std::unique_ptr<api::WifiDirectServerSocket> ListenForService(int port);
|
||||
|
||||
// Starts to advertising
|
||||
bool StartWifiDirectService() override;
|
||||
bool StartWifiDirect();
|
||||
// Stops to advertising
|
||||
bool StopWifiDirectService() override;
|
||||
// Connects to a WifiDirectService
|
||||
bool ConnectWifiDirectService() override;
|
||||
// Disconnects from a WifiDirectService
|
||||
bool DisconnectWifiDirectService() override;
|
||||
bool StopWifiDirect();
|
||||
// Connects to a WifiDirect
|
||||
bool ConnectWifiDirect();
|
||||
// Disconnects from a WifiDirect
|
||||
bool DisconnectWifiDirect();
|
||||
|
||||
absl::optional<std::pair<std::int32_t, std::int32_t>> GetDynamicPortRange()
|
||||
override {
|
||||
absl::optional<std::pair<std::int32_t, std::int32_t>> GetDynamicPortRange() {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
@@ -279,18 +273,16 @@ class WifiDirectServiceMedium : public api::WifiDirectServiceMedium {
|
||||
bool IsIdle() { return medium_status_ == kMediumStatusIdle; }
|
||||
// Advertiser is accepting connection on server socket
|
||||
bool IsAccepting() { return (medium_status_ & kMediumStatusAccepting) != 0; }
|
||||
// Advertiser started WifiDirectService
|
||||
// Advertiser started WifiDirect
|
||||
bool IsServiceStarted() {
|
||||
return (medium_status_ & kMediumStatusServiceStarted) != 0;
|
||||
}
|
||||
// Discoverer is connecting with the WifiDirectService
|
||||
// Discoverer is connecting with the WifiDirect
|
||||
bool IsConnecting() {
|
||||
return (medium_status_ & kMediumStatusConnecting) != 0;
|
||||
}
|
||||
// Discoverer is connected with the WifiDirectService
|
||||
bool IsConnected() {
|
||||
return (medium_status_ & kMediumStatusConnected) != 0;
|
||||
}
|
||||
// Discoverer is connected with the WifiDirect
|
||||
bool IsConnected() { return (medium_status_ & kMediumStatusConnected) != 0; }
|
||||
|
||||
// Converts WiFiDirectServiceConfigurationMethod enum to a string.
|
||||
static std::string ConfigMethodToString(
|
||||
@@ -340,19 +332,16 @@ class WifiDirectServiceMedium : public api::WifiDirectServiceMedium {
|
||||
absl::Mutex mutex_;
|
||||
absl::CondVar is_ip_address_ready_;
|
||||
// Keep the server socket listener pointer
|
||||
WifiDirectServiceServerSocket* server_socket_ptr_ ABSL_GUARDED_BY(mutex_) =
|
||||
nullptr;
|
||||
WifiDirectServerSocket* server_socket_ptr_ ABSL_GUARDED_BY(mutex_) = nullptr;
|
||||
SubmittableExecutor listener_executor_;
|
||||
|
||||
absl::flat_hash_map<winrt::hstring,
|
||||
std::unique_ptr<WifiDirectServiceDiscovered>>
|
||||
absl::flat_hash_map<winrt::hstring, std::unique_ptr<WifiDirectDiscovered>>
|
||||
discovered_devices_by_id_;
|
||||
|
||||
absl::flat_hash_map<winrt::hstring,
|
||||
std::unique_ptr<WifiDirectServiceDiscovered>>
|
||||
absl::flat_hash_map<winrt::hstring, std::unique_ptr<WifiDirectDiscovered>>
|
||||
connection_requested_devices_by_id_;
|
||||
};
|
||||
|
||||
} // namespace nearby::windows
|
||||
|
||||
#endif // PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_SERVICE_H_
|
||||
#endif // PLATFORM_IMPL_WINDOWS_WIFI_DIRECT_H_
|
||||
+53
-54
@@ -26,10 +26,10 @@
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
#include "internal/platform/implementation/windows/socket_address.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -40,8 +40,8 @@ constexpr std::wstring_view kPin = L"1234";
|
||||
constexpr int kWaitingForConnectionTimeoutSeconds = 90; // seconds
|
||||
} // namespace
|
||||
|
||||
WifiDirectServiceMedium::WifiDirectServiceMedium() {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::WifiDirectServiceMedium";
|
||||
WifiDirectMedium::WifiDirectMedium() {
|
||||
LOG(INFO) << "WifiDirectMedium::WifiDirectMedium";
|
||||
// Create a DispatcherQueue for this thread.
|
||||
controller_ = winrt::Windows::System::DispatcherQueueController::
|
||||
CreateOnDedicatedThread();
|
||||
@@ -52,10 +52,10 @@ WifiDirectServiceMedium::WifiDirectServiceMedium() {
|
||||
}
|
||||
}
|
||||
|
||||
WifiDirectServiceMedium::~WifiDirectServiceMedium() {
|
||||
WifiDirectMedium::~WifiDirectMedium() {
|
||||
listener_executor_.Shutdown();
|
||||
StopWifiDirectService();
|
||||
DisconnectWifiDirectService();
|
||||
StopWifiDirect();
|
||||
DisconnectWifiDirect();
|
||||
if (controller_) {
|
||||
// Asynchronously shut down the dispatcher queue.
|
||||
winrt::Windows::Foundation::IAsyncAction shutdown_async =
|
||||
@@ -68,7 +68,7 @@ WifiDirectServiceMedium::~WifiDirectServiceMedium() {
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiDirectServiceMedium::IsInterfaceValid() const {
|
||||
bool WifiDirectMedium::IsInterfaceValid() const {
|
||||
HANDLE wifi_direct_handle = nullptr;
|
||||
DWORD negotiated_version = 0;
|
||||
DWORD result = 0;
|
||||
@@ -86,11 +86,10 @@ bool WifiDirectServiceMedium::IsInterfaceValid() const {
|
||||
}
|
||||
|
||||
// Discoverer connects to server socket
|
||||
std::unique_ptr<api::WifiDirectServiceSocket>
|
||||
WifiDirectServiceMedium::ConnectToService(absl::string_view ip_address,
|
||||
int port,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::ConnectToService Server Socket";
|
||||
std::unique_ptr<api::WifiDirectSocket> WifiDirectMedium::ConnectToService(
|
||||
absl::string_view ip_address, int port,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
LOG(INFO) << "WifiDirectMedium::ConnectToService Server Socket";
|
||||
// check current status
|
||||
if (!IsConnecting()) {
|
||||
LOG(WARNING) << "GC is not connecting to GO, skip.";
|
||||
@@ -157,7 +156,7 @@ WifiDirectServiceMedium::ConnectToService(absl::string_view ip_address,
|
||||
|
||||
LOG(INFO) << "Connect to service ";
|
||||
for (int i = 0; i < wifi_direct_max_connection_retries; ++i) {
|
||||
auto wifi_direct_socket = std::make_unique<WifiDirectServiceSocket>();
|
||||
auto wifi_direct_socket = std::make_unique<WifiDirectSocket>();
|
||||
|
||||
// setup cancel listener
|
||||
std::unique_ptr<CancellationFlagListener> connection_cancellation_listener =
|
||||
@@ -192,9 +191,9 @@ WifiDirectServiceMedium::ConnectToService(absl::string_view ip_address,
|
||||
}
|
||||
|
||||
// Advertiser starts to listen on server socket
|
||||
std::unique_ptr<api::WifiDirectServiceServerSocket>
|
||||
WifiDirectServiceMedium::ListenForService(int port) {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::ListenForService";
|
||||
std::unique_ptr<api::WifiDirectServerSocket> WifiDirectMedium::ListenForService(
|
||||
int port) {
|
||||
LOG(INFO) << "WifiDirectMedium::ListenForService";
|
||||
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!IsServiceStarted()) {
|
||||
@@ -208,7 +207,7 @@ WifiDirectServiceMedium::ListenForService(int port) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto server_socket = std::make_unique<WifiDirectServiceServerSocket>(port);
|
||||
auto server_socket = std::make_unique<WifiDirectServerSocket>(port);
|
||||
server_socket_ptr_ = server_socket.get();
|
||||
|
||||
// Start to listen on server socket in a separate thread. Before GC
|
||||
@@ -268,8 +267,8 @@ WifiDirectServiceMedium::ListenForService(int port) {
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
bool WifiDirectServiceMedium::StartWifiDirectService() {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::StartWifiDirectService";
|
||||
bool WifiDirectMedium::StartWifiDirect() {
|
||||
LOG(INFO) << "WifiDirectMedium::StartWifiDirect";
|
||||
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (IsServiceStarted()) {
|
||||
@@ -280,11 +279,11 @@ bool WifiDirectServiceMedium::StartWifiDirectService() {
|
||||
// Create Advertiser object
|
||||
advertiser_ = WiFiDirectServiceAdvertiser(kServiceName);
|
||||
advertisement_status_changed_token_ = advertiser_.AdvertisementStatusChanged(
|
||||
{this, &WifiDirectServiceMedium::OnAdvertisementStatusChanged});
|
||||
{this, &WifiDirectMedium::OnAdvertisementStatusChanged});
|
||||
auto_accept_session_connected_token_ = advertiser_.AutoAcceptSessionConnected(
|
||||
{this, &WifiDirectServiceMedium::OnAutoAcceptSessionConnected});
|
||||
{this, &WifiDirectMedium::OnAutoAcceptSessionConnected});
|
||||
session_requested_token_ = advertiser_.SessionRequested(
|
||||
{this, &WifiDirectServiceMedium::OnSessionRequested});
|
||||
{this, &WifiDirectMedium::OnSessionRequested});
|
||||
|
||||
advertiser_.AutoAcceptSession(false);
|
||||
advertiser_.PreferGroupOwnerMode(true);
|
||||
@@ -329,8 +328,8 @@ bool WifiDirectServiceMedium::StartWifiDirectService() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WifiDirectServiceMedium::StopWifiDirectService() {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::StopWifiDirectService";
|
||||
bool WifiDirectMedium::StopWifiDirect() {
|
||||
LOG(INFO) << "WifiDirectMedium::StopWifiDirect";
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!IsServiceStarted()) {
|
||||
LOG(WARNING) << "Cannot stop Service because no Service is started.";
|
||||
@@ -366,7 +365,7 @@ bool WifiDirectServiceMedium::StopWifiDirectService() {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string WifiDirectServiceMedium::ConfigMethodToString(
|
||||
std::string WifiDirectMedium::ConfigMethodToString(
|
||||
WiFiDirectServiceConfigurationMethod config_method) {
|
||||
switch (config_method) {
|
||||
case WiFiDirectServiceConfigurationMethod::Default:
|
||||
@@ -380,26 +379,26 @@ std::string WifiDirectServiceMedium::ConfigMethodToString(
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::OnAdvertisementStatusChanged(
|
||||
fire_and_forget WifiDirectMedium::OnAdvertisementStatusChanged(
|
||||
WiFiDirectServiceAdvertiser sender, IInspectable const& event) {
|
||||
LOG(INFO) << "WiFiDirectServiceAdvertiser status changed: "
|
||||
<< (int)sender.AdvertisementStatus();
|
||||
auto status = sender.ServiceStatus();
|
||||
switch (status) {
|
||||
case WiFiDirectServiceStatus ::Available:
|
||||
LOG(INFO) << "WiFiDirectServiceAdvertiser service status changed: "
|
||||
LOG(INFO) << "WifiDirectAdvertiser service status changed: "
|
||||
"status: Available";
|
||||
break;
|
||||
case WiFiDirectServiceStatus ::Busy:
|
||||
LOG(INFO) << "WiFiDirectServiceAdvertiser service status changed: "
|
||||
LOG(INFO) << "WifiDirectAdvertiser service status changed: "
|
||||
"status: Busy";
|
||||
break;
|
||||
case WiFiDirectServiceStatus ::Custom:
|
||||
LOG(INFO) << "WiFiDirectServiceAdvertiser service status changed: "
|
||||
LOG(INFO) << "WifiDirectAdvertiser service status changed: "
|
||||
"status: Custom";
|
||||
break;
|
||||
default:
|
||||
LOG(INFO) << "WiFiDirectServiceAdvertiser service status changed: "
|
||||
LOG(INFO) << "WifiDirectAdvertiser service status changed: "
|
||||
"Code: "
|
||||
<< (int)status;
|
||||
break;
|
||||
@@ -407,10 +406,10 @@ fire_and_forget WifiDirectServiceMedium::OnAdvertisementStatusChanged(
|
||||
return winrt::fire_and_forget();
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::OnAutoAcceptSessionConnected(
|
||||
fire_and_forget WifiDirectMedium::OnAutoAcceptSessionConnected(
|
||||
WiFiDirectServiceAdvertiser sender,
|
||||
WiFiDirectServiceAutoAcceptSessionConnectedEventArgs const& args) {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::OnAutoAcceptSessionConnected";
|
||||
LOG(INFO) << "WifiDirectMedium::OnAutoAcceptSessionConnected";
|
||||
try {
|
||||
auto session = args.Session();
|
||||
if (!session) {
|
||||
@@ -442,7 +441,7 @@ fire_and_forget WifiDirectServiceMedium::OnAutoAcceptSessionConnected(
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::OnSessionRequested(
|
||||
fire_and_forget WifiDirectMedium::OnSessionRequested(
|
||||
WiFiDirectServiceAdvertiser const& sender,
|
||||
WiFiDirectServiceSessionRequestedEventArgs const& args) {
|
||||
try {
|
||||
@@ -520,8 +519,8 @@ fire_and_forget WifiDirectServiceMedium::OnSessionRequested(
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiDirectServiceMedium::ConnectWifiDirectService() {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::ConnectWifiDirectService";
|
||||
bool WifiDirectMedium::ConnectWifiDirect() {
|
||||
LOG(INFO) << "WifiDirectMedium::ConnectWifiDirect";
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (IsConnecting()) {
|
||||
LOG(WARNING) << "Service discovery already running";
|
||||
@@ -552,24 +551,24 @@ bool WifiDirectServiceMedium::ConnectWifiDirectService() {
|
||||
LOG(INFO) << "Create device watcher";
|
||||
device_watcher_ =
|
||||
DeviceInformation::CreateWatcher(device_selector, requested_properties);
|
||||
device_watcher_added_event_token_ = device_watcher_.Added(
|
||||
{this, &WifiDirectServiceMedium::Watcher_DeviceAdded});
|
||||
device_watcher_updated_event_token_ = device_watcher_.Updated(
|
||||
{this, &WifiDirectServiceMedium::Watcher_DeviceUpdated});
|
||||
device_watcher_removed_event_token_ = device_watcher_.Removed(
|
||||
{this, &WifiDirectServiceMedium::Watcher_DeviceRemoved});
|
||||
device_watcher_added_event_token_ =
|
||||
device_watcher_.Added({this, &WifiDirectMedium::Watcher_DeviceAdded});
|
||||
device_watcher_updated_event_token_ =
|
||||
device_watcher_.Updated({this, &WifiDirectMedium::Watcher_DeviceUpdated});
|
||||
device_watcher_removed_event_token_ =
|
||||
device_watcher_.Removed({this, &WifiDirectMedium::Watcher_DeviceRemoved});
|
||||
device_watcher_enumeration_completed_event_token_ =
|
||||
device_watcher_.EnumerationCompleted(
|
||||
{this, &WifiDirectServiceMedium::Watcher_DeviceEnumerationCompleted});
|
||||
device_watcher_stopped_event_token_ = device_watcher_.Stopped(
|
||||
{this, &WifiDirectServiceMedium::Watcher_DeviceStopped});
|
||||
{this, &WifiDirectMedium::Watcher_DeviceEnumerationCompleted});
|
||||
device_watcher_stopped_event_token_ =
|
||||
device_watcher_.Stopped({this, &WifiDirectMedium::Watcher_DeviceStopped});
|
||||
device_watcher_.Start();
|
||||
medium_status_ |= kMediumStatusConnecting;
|
||||
LOG(INFO) << "Started to discover WifiDirect service and connect.";
|
||||
return true;
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::Watcher_DeviceAdded(
|
||||
fire_and_forget WifiDirectMedium::Watcher_DeviceAdded(
|
||||
DeviceWatcher sender, DeviceInformation device_info) {
|
||||
LOG(INFO) << "Device Service founded for device ID "
|
||||
<< winrt::to_string(device_info.Id())
|
||||
@@ -659,31 +658,31 @@ fire_and_forget WifiDirectServiceMedium::Watcher_DeviceAdded(
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::Watcher_DeviceUpdated(
|
||||
fire_and_forget WifiDirectMedium::Watcher_DeviceUpdated(
|
||||
DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate) {
|
||||
VLOG(1) << "WifiDirectServiceMedium::Watcher_DeviceUpdated";
|
||||
VLOG(1) << "WifiDirectMedium::Watcher_DeviceUpdated";
|
||||
return fire_and_forget();
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::Watcher_DeviceRemoved(
|
||||
fire_and_forget WifiDirectMedium::Watcher_DeviceRemoved(
|
||||
DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate) {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::Watcher_DeviceRemoved";
|
||||
LOG(INFO) << "WifiDirectMedium::Watcher_DeviceRemoved";
|
||||
return fire_and_forget();
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::Watcher_DeviceEnumerationCompleted(
|
||||
fire_and_forget WifiDirectMedium::Watcher_DeviceEnumerationCompleted(
|
||||
DeviceWatcher sender, IInspectable inspectable) {
|
||||
LOG(INFO) << "WifiDirectServiceMedium::Watcher_DeviceEnumerationCompleted";
|
||||
LOG(INFO) << "WifiDirectMedium::Watcher_DeviceEnumerationCompleted";
|
||||
return fire_and_forget();
|
||||
}
|
||||
|
||||
fire_and_forget WifiDirectServiceMedium::Watcher_DeviceStopped(
|
||||
fire_and_forget WifiDirectMedium::Watcher_DeviceStopped(
|
||||
DeviceWatcher sender, IInspectable inspectable) {
|
||||
medium_status_ &= (~kMediumStatusConnecting);
|
||||
return fire_and_forget();
|
||||
}
|
||||
|
||||
bool WifiDirectServiceMedium::DisconnectWifiDirectService() {
|
||||
bool WifiDirectMedium::DisconnectWifiDirect() {
|
||||
LOG(WARNING) << "Stop connecting.";
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!IsConnecting()) {
|
||||
+18
-31
@@ -14,7 +14,6 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -24,52 +23,43 @@
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.Collections.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Connectivity.h"
|
||||
#include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h"
|
||||
#include "internal/platform/implementation/windows/socket_address.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby::windows {
|
||||
|
||||
namespace {
|
||||
using ::winrt::Windows::Networking::Connectivity::NetworkInformation;
|
||||
using ::winrt::Windows::Networking::Sockets::SocketQualityOfService;
|
||||
} // namespace
|
||||
WifiDirectServerSocket::WifiDirectServerSocket(int port) : port_(port) {}
|
||||
|
||||
WifiDirectServiceServerSocket::WifiDirectServiceServerSocket(int port)
|
||||
: port_(port) {}
|
||||
WifiDirectServerSocket::~WifiDirectServerSocket() { Close(); }
|
||||
|
||||
WifiDirectServiceServerSocket::~WifiDirectServiceServerSocket() { Close(); }
|
||||
|
||||
std::string WifiDirectServiceServerSocket::GetIPAddress() const {
|
||||
return wifi_direct_service_ipaddr_;
|
||||
std::string WifiDirectServerSocket::GetIPAddress() const {
|
||||
return wifi_direct_ipaddr_;
|
||||
}
|
||||
|
||||
int WifiDirectServiceServerSocket::GetPort() const {
|
||||
return server_socket_.GetPort();
|
||||
}
|
||||
int WifiDirectServerSocket::GetPort() const { return server_socket_.GetPort(); }
|
||||
|
||||
std::unique_ptr<api::WifiDirectServiceSocket>
|
||||
WifiDirectServiceServerSocket::Accept() {
|
||||
std::unique_ptr<api::WifiDirectSocket> WifiDirectServerSocket::Accept() {
|
||||
auto client_socket = server_socket_.Accept();
|
||||
if (client_socket == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LOG(INFO) << __func__ << ": Accepted a remote connection.";
|
||||
return std::make_unique<WifiDirectServiceSocket>(std::move(client_socket));
|
||||
return std::make_unique<WifiDirectSocket>(std::move(client_socket));
|
||||
}
|
||||
|
||||
void WifiDirectServiceServerSocket::SetCloseNotifier(
|
||||
void WifiDirectServerSocket::SetCloseNotifier(
|
||||
absl::AnyInvocable<void()> notifier) {
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
Exception WifiDirectServiceServerSocket::Close() {
|
||||
Exception WifiDirectServerSocket::Close() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (closed_) {
|
||||
return {Exception::kSuccess};
|
||||
@@ -86,19 +76,17 @@ Exception WifiDirectServiceServerSocket::Close() {
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
bool WifiDirectServiceServerSocket::Listen(bool dual_stack,
|
||||
std::string& ip_address) {
|
||||
bool WifiDirectServerSocket::Listen(bool dual_stack, std::string& ip_address) {
|
||||
// Get current IP addresses of the device.
|
||||
if (ip_address.empty()) {
|
||||
return false;
|
||||
}
|
||||
wifi_direct_service_ipaddr_ = ip_address;
|
||||
LOG(INFO) << "Listen wifi_direct_service on IP:port " << ip_address << ":"
|
||||
<< port_;
|
||||
wifi_direct_ipaddr_ = ip_address;
|
||||
LOG(INFO) << "Listen wifi_direct on IP:port " << ip_address << ":" << port_;
|
||||
SocketAddress address(dual_stack);
|
||||
if (!SocketAddress::FromString(address, ip_address, port_)) {
|
||||
LOG(ERROR) << "Failed to parse wifi_direct_service IP address: "
|
||||
<< ip_address << " and port: " << port_;
|
||||
LOG(ERROR) << "Failed to parse wifi_direct IP address: " << ip_address
|
||||
<< " and port: " << port_;
|
||||
return false;
|
||||
}
|
||||
if (!server_socket_.Listen(address)) {
|
||||
@@ -109,9 +97,8 @@ bool WifiDirectServiceServerSocket::Listen(bool dual_stack,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string WifiDirectServiceServerSocket::GetWifiDirectServiceIpAddress()
|
||||
const {
|
||||
return wifi_direct_service_ipaddr_;
|
||||
std::string WifiDirectServerSocket::GetWifiDirectIpAddress() const {
|
||||
return wifi_direct_ipaddr_;
|
||||
}
|
||||
|
||||
} // namespace nearby::windows
|
||||
+4
-4
@@ -17,23 +17,23 @@
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "internal/platform/implementation/windows/nearby_client_socket.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
WifiDirectServiceSocket::WifiDirectServiceSocket()
|
||||
WifiDirectSocket::WifiDirectSocket()
|
||||
: client_socket_(std::make_unique<NearbyClientSocket>()),
|
||||
input_stream_(client_socket_.get()),
|
||||
output_stream_(client_socket_.get()) {}
|
||||
|
||||
WifiDirectServiceSocket::WifiDirectServiceSocket(
|
||||
WifiDirectSocket::WifiDirectSocket(
|
||||
absl_nonnull std::unique_ptr<NearbyClientSocket> socket)
|
||||
: client_socket_(std::move(socket)),
|
||||
input_stream_(client_socket_.get()),
|
||||
output_stream_(client_socket_.get()) {}
|
||||
|
||||
WifiDirectServiceSocket::~WifiDirectServiceSocket() { Close(); }
|
||||
WifiDirectSocket::~WifiDirectSocket() { Close(); }
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
+28
-28
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/windows/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/windows/wifi_direct.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@@ -21,31 +21,31 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/implementation/wifi_direct_service.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
namespace {
|
||||
|
||||
TEST(WifiDirectServiceMedium, DISABLED_StartWifiDirectService) {
|
||||
TEST(WifiDirectMedium, DISABLED_StartWifiDirect) {
|
||||
int run_test;
|
||||
LOG(INFO) << "Run StartWifiDirectService test case? input 0 or 1:";
|
||||
LOG(INFO) << "Run StartWifiDirect test case? input 0 or 1:";
|
||||
std::cin >> run_test;
|
||||
|
||||
if (run_test) {
|
||||
winrt::init_apartment();
|
||||
WifiDirectServiceMedium wifi_direct_service_medium;
|
||||
WifiDirectMedium wifi_direct_medium;
|
||||
|
||||
EXPECT_TRUE(wifi_direct_service_medium.StartWifiDirectService());
|
||||
EXPECT_TRUE(wifi_direct_medium.StartWifiDirect());
|
||||
|
||||
while (true) {
|
||||
LOG(INFO) << "Enter \"s\" to stop test:";
|
||||
std::string stop;
|
||||
std::cin >> stop;
|
||||
if (stop == "s") {
|
||||
LOG(INFO) << "Exit WiFi WifiDirectService GO";
|
||||
EXPECT_TRUE(wifi_direct_service_medium.StopWifiDirectService());
|
||||
LOG(INFO) << "Exit WiFi WifiDirect GO";
|
||||
EXPECT_TRUE(wifi_direct_medium.StopWifiDirect());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -54,14 +54,14 @@ TEST(WifiDirectServiceMedium, DISABLED_StartWifiDirectService) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WifiDirectServiceMedium, DISABLED_ConnectWifiDirectService) {
|
||||
TEST(WifiDirectMedium, DISABLED_ConnectWifiDirect) {
|
||||
int run_test;
|
||||
LOG(INFO) << "Run ConnectWifiDirectService GO test case? input 0 or 1:";
|
||||
LOG(INFO) << "Run ConnectWifiDirect GO test case? input 0 or 1:";
|
||||
std::cin >> run_test;
|
||||
|
||||
if (run_test) {
|
||||
WifiDirectServiceMedium wifi_direct_service_medium;
|
||||
EXPECT_TRUE(wifi_direct_service_medium.ConnectWifiDirectService());
|
||||
WifiDirectMedium wifi_direct_medium;
|
||||
EXPECT_TRUE(wifi_direct_medium.ConnectWifiDirect());
|
||||
|
||||
absl::SleepFor(absl::Seconds(2));
|
||||
while (true) {
|
||||
@@ -69,8 +69,8 @@ TEST(WifiDirectServiceMedium, DISABLED_ConnectWifiDirectService) {
|
||||
std::string stop;
|
||||
std::cin >> stop;
|
||||
if (stop == "s") {
|
||||
LOG(INFO) << "Disconnect WiFiDirectService GO";
|
||||
EXPECT_TRUE(wifi_direct_service_medium.DisconnectWifiDirectService());
|
||||
LOG(INFO) << "Disconnect WifiDirect GO";
|
||||
EXPECT_TRUE(wifi_direct_medium.DisconnectWifiDirect());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -79,22 +79,22 @@ TEST(WifiDirectServiceMedium, DISABLED_ConnectWifiDirectService) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WifiDirectServiceMedium, DISABLED_WifiDirectServiceServerStartListen) {
|
||||
TEST(WifiDirectMedium, DISABLED_WifiDirectServerStartListen) {
|
||||
int run_test;
|
||||
LOG(INFO) << "Run WifiDirectServiceServerStartListen test? input 0 or 1:";
|
||||
LOG(INFO) << "Run WifiDirectServerStartListen test? input 0 or 1:";
|
||||
std::cin >> run_test;
|
||||
|
||||
if (run_test) {
|
||||
winrt::init_apartment();
|
||||
WifiDirectServiceMedium wifi_direct_service_medium;
|
||||
WifiDirectMedium wifi_direct_medium;
|
||||
|
||||
EXPECT_TRUE(wifi_direct_service_medium.StartWifiDirectService());
|
||||
EXPECT_TRUE(wifi_direct_medium.StartWifiDirect());
|
||||
absl::SleepFor(absl::Seconds(1));
|
||||
std::unique_ptr<api::WifiDirectServiceServerSocket> server_socket =
|
||||
wifi_direct_service_medium.ListenForService(/*port=*/1234);
|
||||
std::unique_ptr<api::WifiDirectServerSocket> server_socket =
|
||||
wifi_direct_medium.ListenForService(/*port=*/1234);
|
||||
|
||||
absl::SleepFor(absl::Seconds(60));
|
||||
std::unique_ptr<api::WifiDirectServiceSocket> client_socket =
|
||||
std::unique_ptr<api::WifiDirectSocket> client_socket =
|
||||
server_socket->Accept();
|
||||
EXPECT_NE(client_socket, nullptr);
|
||||
|
||||
@@ -105,7 +105,7 @@ TEST(WifiDirectServiceMedium, DISABLED_WifiDirectServiceServerStartListen) {
|
||||
if (stop == "s") {
|
||||
LOG(INFO) << "Close server socket and stop WiFi Direct Service";
|
||||
server_socket->Close();
|
||||
EXPECT_TRUE(wifi_direct_service_medium.StopWifiDirectService());
|
||||
EXPECT_TRUE(wifi_direct_medium.StopWifiDirect());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -114,19 +114,19 @@ TEST(WifiDirectServiceMedium, DISABLED_WifiDirectServiceServerStartListen) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WifiDirectServiceMedium, DISABLED_WifiDirectConnectToServiceServer) {
|
||||
TEST(WifiDirectMedium, DISABLED_WifiDirectConnectToServiceServer) {
|
||||
int run_test;
|
||||
LOG(INFO) << "Run WifiDirectConnectToServiceServer test? input 0 or 1:";
|
||||
std::cin >> run_test;
|
||||
|
||||
if (run_test) {
|
||||
winrt::init_apartment();
|
||||
WifiDirectServiceMedium wifi_direct_service_medium;
|
||||
WifiDirectMedium wifi_direct_medium;
|
||||
|
||||
EXPECT_TRUE(wifi_direct_service_medium.ConnectWifiDirectService());
|
||||
EXPECT_TRUE(wifi_direct_medium.ConnectWifiDirect());
|
||||
absl::SleepFor(absl::Seconds(1));
|
||||
std::unique_ptr<api::WifiDirectServiceSocket> client_socket =
|
||||
wifi_direct_service_medium.ConnectToService(
|
||||
std::unique_ptr<api::WifiDirectSocket> client_socket =
|
||||
wifi_direct_medium.ConnectToService(
|
||||
/*ip_address=*/"",
|
||||
/*port=*/1234,
|
||||
/*cancellation_flag=*/nullptr);
|
||||
@@ -139,7 +139,7 @@ TEST(WifiDirectServiceMedium, DISABLED_WifiDirectConnectToServiceServer) {
|
||||
if (stop == "s") {
|
||||
LOG(INFO) << "Close client socket and disconnect WiFi Direct Service";
|
||||
client_socket->Close();
|
||||
EXPECT_TRUE(wifi_direct_service_medium.DisconnectWifiDirectService());
|
||||
EXPECT_TRUE(wifi_direct_medium.DisconnectWifiDirect());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user