Commit de039933 authored by Vicky Min's avatar Vicky Min Committed by Commit Bot

[bluetooth] Serial interface for bluetooth devices

The class BluetoothSerialPortImpl is intended to support
Serial API features for Bluetooth SPP devices. The Close()
function is implemented todisallow any more calls to
BluetoothSerialPortImpl functions and tested.

Bug: 1043300
Change-Id: Ic42095eb587a5dd099f48f2babe75882c9dd385a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354682
Commit-Queue: Vicky Min <vickymin@google.com>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798998}
parent 81e3598e
......@@ -345,27 +345,38 @@ void BluetoothSerialPortImpl::Drain(DrainCallback callback) {
void BluetoothSerialPortImpl::GetControlSignals(
GetControlSignalsCallback callback) {
NOTIMPLEMENTED();
auto signals = mojom::SerialPortControlSignals::New();
std::move(callback).Run(std::move(signals));
}
void BluetoothSerialPortImpl::SetControlSignals(
mojom::SerialHostControlSignalsPtr signals,
SetControlSignalsCallback callback) {
NOTIMPLEMENTED();
std::move(callback).Run(true);
}
void BluetoothSerialPortImpl::ConfigurePort(
mojom::SerialConnectionOptionsPtr options,
ConfigurePortCallback callback) {
NOTIMPLEMENTED();
options_ = std::move(options);
std::move(callback).Run(true);
}
void BluetoothSerialPortImpl::GetPortInfo(GetPortInfoCallback callback) {
NOTIMPLEMENTED();
auto info = mojom::SerialConnectionInfo::New(
/*bitrate=*/options_->bitrate, /*data_bits=*/options_->data_bits,
/*parity_bit=*/options_->parity_bit, /*stop_bits=*/options_->stop_bits,
/*cts_flow_control=*/options_->cts_flow_control);
std::move(callback).Run(std::move(info));
}
void BluetoothSerialPortImpl::Close(CloseCallback callback) {
NOTIMPLEMENTED();
client_.reset();
if (bluetooth_socket_) {
bluetooth_socket_->Close();
bluetooth_socket_.reset();
}
std::move(callback).Run();
}
} // namespace device
......@@ -97,6 +97,8 @@ class BluetoothSerialPortImpl : public mojom::SerialPort {
bool read_pending_ = false;
bool write_pending_ = false;
mojom::SerialConnectionOptionsPtr options_;
base::WeakPtrFactory<BluetoothSerialPortImpl> weak_ptr_factory_{this};
};
......
......@@ -316,4 +316,38 @@ TEST_F(BluetoothSerialPortImplTest, Drain) {
disconnect_loop.Run();
}
TEST_F(BluetoothSerialPortImplTest, Close) {
mojo::Remote<mojom::SerialPort> serial_port;
mojo::SelfOwnedReceiverRef<mojom::SerialPortConnectionWatcher> watcher;
CreatePort(&serial_port, &watcher);
mojo::ScopedDataPipeProducerHandle producer;
mojo::ScopedDataPipeConsumerHandle consumer;
CreateDataPipe(&producer, &consumer);
auto options = mojom::SerialConnectionOptions::New();
mojo::PendingRemote<mojom::SerialPortClient> client;
FakeSerialPortClient serial_client;
serial_client.Bind(client.InitWithNewPipeAndPassReceiver());
base::RunLoop loop;
serial_port->Open(
std::move(options), std::move(client),
base::BindOnce([](base::RunLoop* loop, bool success) { loop->Quit(); },
&loop));
loop.Run();
EXPECT_CALL(mock_socket(), Close());
base::RunLoop close_loop;
serial_port->Close(close_loop.QuitClosure());
close_loop.Run();
base::RunLoop disconnect_loop;
watcher->set_connection_error_handler(
base::BindLambdaForTesting([&]() { disconnect_loop.Quit(); }));
serial_port.reset();
disconnect_loop.Run();
}
} // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment