mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
internal fix
PiperOrigin-RevId: 755993569
This commit is contained in:
committed by
Copybara-Service
parent
ee9266b175
commit
94ddb09a7f
@@ -71,7 +71,6 @@ class GattServer : public api::ble_v2::GattServer {
|
||||
|
||||
private:
|
||||
GNCBLEGATTServer *gatt_server_;
|
||||
EmptyBlePeripheral peripheral_;
|
||||
};
|
||||
|
||||
} // namespace apple
|
||||
|
||||
@@ -97,7 +97,7 @@ void GattServer::Stop() {
|
||||
|
||||
// TODO(b/290385712): Implement.
|
||||
api::ble_v2::BlePeripheral &GattServer::GetBlePeripheral() {
|
||||
return peripheral_;
|
||||
return BlePeripheral::DefaultBlePeripheral();
|
||||
}
|
||||
|
||||
} // namespace apple
|
||||
|
||||
@@ -168,7 +168,7 @@ Exception BleL2capOutputStream::Close() {
|
||||
#pragma mark - BleL2capSocket
|
||||
|
||||
BleL2capSocket::BleL2capSocket(GNCBLEL2CAPConnection *connection)
|
||||
: BleL2capSocket(connection, new EmptyBlePeripheral()) {}
|
||||
: BleL2capSocket(connection, &BlePeripheral::DefaultBlePeripheral()) {}
|
||||
|
||||
BleL2capSocket::BleL2capSocket(GNCBLEL2CAPConnection *connection,
|
||||
api::ble_v2::BlePeripheral *peripheral)
|
||||
|
||||
@@ -183,11 +183,10 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
GNCBLEMedium *medium_;
|
||||
|
||||
absl::Mutex peripherals_mutex_;
|
||||
absl::flat_hash_map<api::ble_v2::BlePeripheral::UniqueId, std::unique_ptr<BlePeripheral>>
|
||||
absl::flat_hash_map<api::ble_v2::BlePeripheral::UniqueId,
|
||||
std::unique_ptr<BlePeripheral>>
|
||||
peripherals_ ABSL_GUARDED_BY(peripherals_mutex_);
|
||||
|
||||
std::unique_ptr<EmptyBlePeripheral> local_peripheral_;
|
||||
|
||||
GNSPeripheralServiceManager *socketPeripheralServiceManager_;
|
||||
GNSPeripheralManager *socketPeripheralManager_;
|
||||
GNSCentralManager *socketCentralManager_;
|
||||
|
||||
@@ -547,8 +547,8 @@ bool BleMedium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId unique_
|
||||
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) {
|
||||
// If the unique_id is 0, that means it's the local/empty peripheral. We must return "true"
|
||||
// otherwise the connection will be considered invalid and the application will crash.
|
||||
if (unique_id == 0) {
|
||||
callback(*local_peripheral_);
|
||||
if (unique_id == BlePeripheral::DefaultBlePeripheral().GetUniqueId()) {
|
||||
callback(BlePeripheral::DefaultBlePeripheral());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,29 +31,6 @@
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
// An empty peripheral.
|
||||
//
|
||||
// Apple APIs do not expose a peripheral's MAC address and does not provide a
|
||||
// way to directly connect to a given MAC address. Instead a connection can only
|
||||
// be made using a CoreBluetooth peripheral object. Many times a CoreBluetooth
|
||||
// peripheral is not available, namely, when the remote device is a central. For
|
||||
// these cases, an EmptyBlePeripheral should be used.
|
||||
class EmptyBlePeripheral : public api::ble_v2::BlePeripheral {
|
||||
public:
|
||||
EmptyBlePeripheral();
|
||||
~EmptyBlePeripheral() override = default;
|
||||
|
||||
// Returns an empty string.
|
||||
std::string GetAddress() const override;
|
||||
|
||||
// Returns an immutable unique identifier. The identifier does not change when
|
||||
// the peripheral's address is rotated.
|
||||
api::ble_v2::BlePeripheral::UniqueId GetUniqueId() const override;
|
||||
|
||||
private:
|
||||
api::ble_v2::BlePeripheral::UniqueId unique_id_;
|
||||
};
|
||||
|
||||
// A wrapper of a CoreBluetooth peripheral object. This can be used to uniquely
|
||||
// identify a peripheral and connect to its GATT server.
|
||||
//
|
||||
@@ -62,6 +39,9 @@ class EmptyBlePeripheral : public api::ble_v2::BlePeripheral {
|
||||
// used instead.
|
||||
class BlePeripheral : public api::ble_v2::BlePeripheral {
|
||||
public:
|
||||
// Returns a reference to a default BlePeripheral.
|
||||
static api::ble_v2::BlePeripheral& DefaultBlePeripheral();
|
||||
|
||||
explicit BlePeripheral(id<GNCPeripheral> peripheral);
|
||||
~BlePeripheral() override = default;
|
||||
|
||||
|
||||
@@ -26,19 +26,17 @@
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
#pragma mark - EmptyBlePeripheral
|
||||
|
||||
EmptyBlePeripheral::EmptyBlePeripheral() : unique_id_(0) {}
|
||||
|
||||
std::string EmptyBlePeripheral::GetAddress() const { return ""; }
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId EmptyBlePeripheral::GetUniqueId() const { return unique_id_; }
|
||||
|
||||
#pragma mark - BlePeripheral
|
||||
|
||||
BlePeripheral::BlePeripheral(id<GNCPeripheral> peripheral)
|
||||
: peripheral_(peripheral), unique_id_(peripheral.identifier.hash) {}
|
||||
|
||||
api::ble_v2::BlePeripheral& BlePeripheral::DefaultBlePeripheral() {
|
||||
static api::ble_v2::BlePeripheral* default_peripheral =
|
||||
new api::ble_v2::BlePeripheral(0xffffffffffffffff);
|
||||
return *default_peripheral;
|
||||
}
|
||||
|
||||
std::string BlePeripheral::GetAddress() const { return ""; }
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId BlePeripheral::GetUniqueId() const { return unique_id_; }
|
||||
|
||||
@@ -180,7 +180,7 @@ Exception BleOutputStream::Close() {
|
||||
BleSocket::BleSocket(id<GNCMConnection> connection)
|
||||
: input_stream_(new BleInputStream()),
|
||||
output_stream_(new BleOutputStream(connection)),
|
||||
peripheral_(new EmptyBlePeripheral()) {}
|
||||
peripheral_(&(BlePeripheral::DefaultBlePeripheral())) {}
|
||||
|
||||
BleSocket::BleSocket(id<GNCMConnection> connection, api::ble_v2::BlePeripheral *peripheral)
|
||||
: input_stream_(new BleInputStream()),
|
||||
|
||||
Reference in New Issue
Block a user