nearby: snapshot of cl/317978613

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I4bf367877a986910bb03e1c54aa972b4bcd59942
This commit is contained in:
Alexey Polyudov
2020-06-23 19:52:26 -07:00
parent 32828732ff
commit 6b27a508ed
164 changed files with 8663 additions and 1212 deletions
+22 -16
View File
@@ -13,9 +13,15 @@ namespace location {
namespace nearby {
namespace g3 {
BluetoothSocket::~BluetoothSocket() {
absl::MutexLock lock(&mutex_);
DoClose();
}
void BluetoothSocket::Connect(BluetoothSocket& other) {
absl::MutexLock lock(&mutex_);
remote_socket_ = &other;
input_ = other.output_;
}
bool BluetoothSocket::IsConnected() const {
@@ -29,7 +35,7 @@ bool BluetoothSocket::IsClosed() const {
}
bool BluetoothSocket::IsConnectedLocked() const {
return remote_socket_ != nullptr;
return input_ != nullptr;
}
InputStream& BluetoothSocket::GetInputStream() {
@@ -44,31 +50,31 @@ OutputStream& BluetoothSocket::GetOutputStream() {
InputStream& BluetoothSocket::GetLocalInputStream() {
absl::MutexLock lock(&mutex_);
return output_.GetInputStream();
return output_->GetInputStream();
}
OutputStream& BluetoothSocket::GetLocalOutputStream() {
absl::MutexLock lock(&mutex_);
return output_.GetOutputStream();
return output_->GetOutputStream();
}
Exception BluetoothSocket::Close() {
BluetoothSocket* remote_socket = nullptr;
{
absl::MutexLock lock(&mutex_);
if (!closed_) {
remote_socket = remote_socket_;
output_.GetOutputStream().Close();
output_.GetInputStream().Close();
closed_ = true;
}
}
if (remote_socket != nullptr) {
remote_socket->Close();
}
absl::MutexLock lock(&mutex_);
DoClose();
return {Exception::kSuccess};
}
void BluetoothSocket::DoClose() {
if (!closed_) {
remote_socket_ = nullptr;
output_->GetOutputStream().Close();
output_->GetInputStream().Close();
input_->GetOutputStream().Close();
input_->GetInputStream().Close();
closed_ = true;
}
}
BluetoothSocket* BluetoothSocket::GetRemoteSocket() {
absl::MutexLock lock(&mutex_);
return remote_socket_;