From 913a639a5db129bc76b4b1f9bacc0bcaef624282 Mon Sep 17 00:00:00 2001 From: jfcarroll Date: Fri, 13 Aug 2021 14:15:19 -0700 Subject: [PATCH] BluetoothClassicMedium::GetRemoteDevice and BluetoothClassicSocket::Close implmentations PiperOrigin-RevId: 390691122 --- cpp/platform/impl/windows/bluetooth_classic_device.h | 3 ++- .../impl/windows/bluetooth_classic_medium.cc | 10 ++-------- .../impl/windows/bluetooth_classic_socket.cc | 12 ++++++++++-- cpp/platform/impl/windows/bluetooth_classic_socket.h | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cpp/platform/impl/windows/bluetooth_classic_device.h b/cpp/platform/impl/windows/bluetooth_classic_device.h index 78161533..e24019a9 100644 --- a/cpp/platform/impl/windows/bluetooth_classic_device.h +++ b/cpp/platform/impl/windows/bluetooth_classic_device.h @@ -21,7 +21,6 @@ #include "platform/base/exception.h" #include "platform/base/input_stream.h" #include "platform/base/output_stream.h" - #include "platform/impl/windows/generated/winrt/Windows.Devices.Bluetooth.h" #include "platform/impl/windows/generated/winrt/Windows.Devices.Enumeration.h" #include "platform/impl/windows/generated/winrt/base.h" @@ -51,6 +50,8 @@ using winrt::Windows::Devices::Bluetooth::BluetoothCacheMode; // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html. class BluetoothDevice : public api::BluetoothDevice { public: + BluetoothDevice(std::string mac_address) + : windows_bluetooth_device_(nullptr), mac_address_(mac_address) {} BluetoothDevice(const winrt::Windows::Devices::Bluetooth::BluetoothDevice& bluetoothDevice); diff --git a/cpp/platform/impl/windows/bluetooth_classic_medium.cc b/cpp/platform/impl/windows/bluetooth_classic_medium.cc index 7beca335..c58e2a0c 100644 --- a/cpp/platform/impl/windows/bluetooth_classic_medium.cc +++ b/cpp/platform/impl/windows/bluetooth_classic_medium.cc @@ -44,11 +44,6 @@ BluetoothClassicMedium::BluetoothClassicMedium() { BluetoothClassicMedium::~BluetoothClassicMedium() {} -// TODO(b/184975123): replace with real implementation. -api::BluetoothDevice* GetRemoteDevice(const std::string& mac_address) { - return nullptr; -} - bool BluetoothClassicMedium::StartDiscovery( BluetoothClassicMedium::DiscoveryCallback discovery_callback) { EnterCriticalSection(&critical_section_); @@ -148,7 +143,7 @@ std::unique_ptr BluetoothClassicMedium::ConnectToService( EnterCriticalSection(&critical_section_); std::unique_ptr rfcommSocket = - std::make_unique(); + std::make_unique(nullptr); location::nearby::CancellationFlagListener cancellationFlagListener( cancellation_flag, @@ -263,10 +258,9 @@ BluetoothClassicMedium::ListenForService(const std::string& service_name, return std::move(bluetooth_server_socket); } -// TODO(b/184975123): replace with real implementation. api::BluetoothDevice* BluetoothClassicMedium::GetRemoteDevice( const std::string& mac_address) { - return nullptr; + return new BluetoothDevice(mac_address); } bool BluetoothClassicMedium::StartScanning() { diff --git a/cpp/platform/impl/windows/bluetooth_classic_socket.cc b/cpp/platform/impl/windows/bluetooth_classic_socket.cc index 2c26d223..d80dded4 100644 --- a/cpp/platform/impl/windows/bluetooth_classic_socket.cc +++ b/cpp/platform/impl/windows/bluetooth_classic_socket.cc @@ -45,8 +45,16 @@ OutputStream& BluetoothSocket::GetOutputStream() { // Closes both input and output streams, marks Socket as closed. // After this call object should be treated as not connected. // Returns Exception::kIo on error, Exception::kSuccess otherwise. -// TODO(b/184975123): replace with real implementation. -Exception BluetoothSocket::Close() { return Exception(); } +Exception BluetoothSocket::Close() { + // The Close method aborts any pending operations and releases all unmanaged + // resources associated with the StreamSocket object, including the Input and + // Output streams + windows_socket_.Close(); + windows_socket_ = nullptr; + input_stream_ = nullptr; + output_stream_ = nullptr; + return {Exception::kSuccess}; +} // https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html#getRemoteDevice() // Returns valid BluetoothDevice pointer if there is a connection, and diff --git a/cpp/platform/impl/windows/bluetooth_classic_socket.h b/cpp/platform/impl/windows/bluetooth_classic_socket.h index 639ba356..d15aea01 100644 --- a/cpp/platform/impl/windows/bluetooth_classic_socket.h +++ b/cpp/platform/impl/windows/bluetooth_classic_socket.h @@ -16,7 +16,7 @@ #define PLATFORM_IMPL_WINDOWS_BLUETOOTH_CLASSIC_SOCKET_H_ #include "platform/api/bluetooth_classic.h" - +#include "platform/impl/windows/bluetooth_classic_device.h" #include "platform/impl/windows/generated/winrt/Windows.Foundation.h" #include "platform/impl/windows/generated/winrt/Windows.Networking.Sockets.h" #include "platform/impl/windows/generated/winrt/Windows.Storage.Streams.h"