Remove BlePeripheral reference from BleSocket.

PiperOrigin-RevId: 757797557
This commit is contained in:
Francis Tsui
2025-05-12 09:38:22 -07:00
committed by Copybara-Service
parent 8f71b8e8b0
commit acc5f1b0d8
8 changed files with 19 additions and 26 deletions
+1 -6
View File
@@ -195,12 +195,7 @@ class BleV2ServerSocket final {
if (socket == nullptr) {
LOG(INFO) << "BleServerSocket Accept() failed on server socket: " << this;
} else {
api::ble_v2::BlePeripheral* platform_peripheral =
socket->GetRemotePeripheral();
if (platform_peripheral != nullptr) {
peripheral =
BleV2Peripheral(*medium_, platform_peripheral->GetUniqueId());
}
peripheral = BleV2Peripheral(*medium_, socket->GetRemotePeripheralId());
}
return BleV2Socket(peripheral, std::move(socket));
}
@@ -471,8 +471,8 @@ std::unique_ptr<api::ble_v2::BleSocket> BleMedium::Connect(
serviceID:@(service_id.c_str())
expectedIntroPacket:NO
callbackQueue:dispatch_get_main_queue()];
socket =
std::make_unique<BleSocket>(connection, peripheral);
socket = std::make_unique<BleSocket>(connection,
peripheral->GetUniqueId());
connection.connectionHandlers =
socket->GetInputStream().GetConnectionHandlers();
dispatch_semaphore_signal(semaphore);
@@ -94,7 +94,7 @@ class BleSocket : public api::ble_v2::BleSocket {
// The peripheral used to create the socket must outlive the socket or undefined behavior will
// occur.
BleSocket(id<GNCMConnection> connection, api::ble_v2::BlePeripheral *peripheral);
BleSocket(id<GNCMConnection> connection, api::ble_v2::BlePeripheral::UniqueId peripheral_id);
~BleSocket() override;
// Returns the InputStream of the BleSocket.
@@ -116,7 +116,7 @@ class BleSocket : public api::ble_v2::BleSocket {
// Returns valid BlePeripheral pointer if there is a connection, and
// nullptr otherwise.
api::ble_v2::BlePeripheral *GetRemotePeripheral() override { return peripheral_; }
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override { return peripheral_id_; }
bool IsClosed() const ABSL_LOCKS_EXCLUDED(mutex_);
@@ -127,7 +127,7 @@ class BleSocket : public api::ble_v2::BleSocket {
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
std::unique_ptr<BleInputStream> input_stream_;
std::unique_ptr<BleOutputStream> output_stream_;
api::ble_v2::BlePeripheral *peripheral_;
api::ble_v2::BlePeripheral::UniqueId peripheral_id_;
};
} // namespace apple
@@ -180,12 +180,13 @@ Exception BleOutputStream::Close() {
BleSocket::BleSocket(id<GNCMConnection> connection)
: input_stream_(new BleInputStream()),
output_stream_(new BleOutputStream(connection)),
peripheral_(&(BlePeripheral::DefaultBlePeripheral())) {}
peripheral_id_(BlePeripheral::DefaultBlePeripheral().GetUniqueId()) {}
BleSocket::BleSocket(id<GNCMConnection> connection, api::ble_v2::BlePeripheral *peripheral)
BleSocket::BleSocket(id<GNCMConnection> connection,
api::ble_v2::BlePeripheral::UniqueId peripheral_id)
: input_stream_(new BleInputStream()),
output_stream_(new BleOutputStream(connection)),
peripheral_(peripheral) {}
peripheral_id_(peripheral_id) {}
BleSocket::~BleSocket() {
absl::MutexLock lock(&mutex_);
+2 -3
View File
@@ -375,9 +375,8 @@ class BleSocket {
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
virtual Exception Close() = 0;
// Returns valid BlePeripheral pointer if there is a connection, and
// nullptr otherwise.
virtual BlePeripheral* GetRemotePeripheral() = 0;
// Returns BlePeripheral::UniqueId that is connected to this socket.
virtual BlePeripheral::UniqueId GetRemotePeripheralId() = 0;
};
// A BLE GATT server socket for listening incoming GATT socket.
@@ -68,14 +68,14 @@ std::string TxPowerLevelToName(TxPowerLevel power_mode) {
} // namespace
api::ble_v2::BlePeripheral* BleV2Socket::GetRemotePeripheral() {
api::ble_v2::BlePeripheral::UniqueId BleV2Socket::GetRemotePeripheralId() {
BleV2Socket* remote_socket = GetRemoteSocket();
if (remote_socket == nullptr || remote_socket->adapter_ == nullptr ||
remote_socket->adapter_->GetBleV2Medium() == nullptr) {
return nullptr;
return 0LL;
}
return &(dynamic_cast<BleV2Medium*>(remote_socket->adapter_->GetBleV2Medium())
->GetPeripheral());
return dynamic_cast<BleV2Medium*>(remote_socket->adapter_->GetBleV2Medium())
->GetPeripheral().GetUniqueId();
}
std::unique_ptr<api::ble_v2::BleSocket> BleV2ServerSocket::Accept() {
+1 -3
View File
@@ -69,9 +69,7 @@ class BleV2Socket : public api::ble_v2::BleSocket, public SocketBase {
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
Exception Close() override { return SocketBase::Close(); }
// Returns valid BlePeripheral pointer if there is a connection, and
// nullptr otherwise.
api::ble_v2::BlePeripheral* GetRemotePeripheral() override
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override
ABSL_LOCKS_EXCLUDED(mutex_);
private:
@@ -37,8 +37,8 @@ class BleV2Socket : public api::ble_v2::BleSocket {
Exception Close() override;
api::ble_v2::BlePeripheral* GetRemotePeripheral() override {
return nullptr;
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override {
return 0LL;
};
bool Connect();