These are the fixes thus far. Most involve whether we're using a pointer or not.

PiperOrigin-RevId: 401241518
This commit is contained in:
jfcarroll
2021-10-06 07:42:58 -07:00
committed by Copybara-Service
parent dceb1e216b
commit eea2a91139
5 changed files with 39 additions and 27 deletions
@@ -19,8 +19,13 @@
namespace location {
namespace nearby {
namespace windows {
BluetoothSocket::BluetoothSocket() {
windows_socket_ = IStreamSocket();
BluetoothSocket::BluetoothSocket(StreamSocket streamSocket)
: windows_socket_(streamSocket) {
bluetooth_device_ = std::make_unique<BluetoothDevice>(
winrt::Windows::Devices::Bluetooth::BluetoothDevice::FromHostNameAsync(
windows_socket_.Information().RemoteHostName())
.get());
input_stream_ =
std::make_unique<BluetoothInputStream>(windows_socket_.InputStream());
output_stream_ =
@@ -59,8 +64,9 @@ Exception BluetoothSocket::Close() {
// https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html#getRemoteDevice()
// Returns valid BluetoothDevice pointer if there is a connection, and
// nullptr otherwise.
// TODO(b/184975123): replace with real implementation.
api::BluetoothDevice* BluetoothSocket::GetRemoteDevice() { return nullptr; }
api::BluetoothDevice* BluetoothSocket::GetRemoteDevice() {
return bluetooth_device_.get();
}
// Starts an asynchronous operation on a StreamSocket object to connect to a
// remote network destination specified by a remote hostname and a remote
@@ -81,7 +87,7 @@ ExceptionOr<ByteArray> BluetoothSocket::BluetoothInputStream::Read(
std::int64_t size) {
Buffer buffer = Buffer(size);
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::None);
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::None).get();
DataReader dataReader = DataReader::FromBuffer(buffer);
@@ -93,7 +99,7 @@ ExceptionOr<ByteArray> BluetoothSocket::BluetoothInputStream::Read(
IAsyncAction BluetoothSocket::CancelIOAsync() {
// Cancels pending reads and writes over a StreamSocket object.
// https://docs.microsoft.com/en-us/uwp/api/windows.networking.sockets.streamsocket.cancelioasync?view=winrt-20348
return windows_socket_.as<StreamSocket>().CancelIOAsync();
return windows_socket_.CancelIOAsync();
}
Exception BluetoothSocket::BluetoothInputStream::Close() {
@@ -117,7 +123,7 @@ Exception BluetoothSocket::BluetoothOutputStream::Write(const ByteArray& data) {
std::memcpy(buffer.data(), data.data(), data.size());
try {
winrt_stream_.WriteAsync(buffer);
winrt_stream_.WriteAsync(buffer).get();
} catch (std::exception exception) {
return {Exception::kFailed};
}