Loading system/service/adapter.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ class AdapterImpl : public Adapter, name_(kDefaultName) { memset(&local_le_features_, 0, sizeof(local_le_features_)); hal::BluetoothInterface::Get()->AddObserver(this); ble_client_factory_.reset(new LowEnergyClientFactory()); ble_client_factory_.reset(new LowEnergyClientFactory(*this)); gatt_client_factory_.reset(new GattClientFactory()); gatt_server_factory_.reset(new GattServerFactory()); hal::BluetoothInterface::Get()->GetHALInterface()->get_adapter_properties(); Loading system/service/low_energy_client.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <base/logging.h> #include "service/adapter.h" #include "stack/include/bt_types.h" #include "stack/include/hcidefs.h" Loading Loading @@ -270,8 +271,10 @@ void GetAdvertiseParams(const AdvertiseSettings& settings, bool has_scan_rsp, // LowEnergyClient implementation // ======================================================== LowEnergyClient::LowEnergyClient(const UUID& uuid, int client_id) : app_identifier_(uuid), LowEnergyClient::LowEnergyClient( Adapter& adapter, const UUID& uuid, int client_id) : adapter_(adapter), app_identifier_(uuid), client_id_(client_id), adv_data_needs_update_(false), scan_rsp_needs_update_(false), Loading Loading @@ -588,7 +591,8 @@ void LowEnergyClient::InvokeAndClearStopCallback(BLEStatus status) { // LowEnergyClientFactory implementation // ======================================================== LowEnergyClientFactory::LowEnergyClientFactory() { LowEnergyClientFactory::LowEnergyClientFactory(Adapter& adapter) : adapter_(adapter) { hal::BluetoothGattInterface::Get()->AddClientObserver(this); } Loading Loading @@ -639,7 +643,7 @@ void LowEnergyClientFactory::RegisterClientCallback( std::unique_ptr<LowEnergyClient> client; BLEStatus result = BLE_STATUS_FAILURE; if (status == BT_STATUS_SUCCESS) { client.reset(new LowEnergyClient(uuid, client_id)); client.reset(new LowEnergyClient(adapter_, uuid, client_id)); // Use the unsafe variant to register this as an observer, since // LowEnergyClient instances only get created by LowEnergyClientCallback Loading system/service/low_energy_client.h +12 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ namespace bluetooth { class Adapter; // A LowEnergyClient represents an application's handle to perform various // Bluetooth Low Energy GAP operations. Instances cannot be created directly and // should be obtained through the factory. Loading Loading @@ -78,7 +80,7 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, // Constructor shouldn't be called directly as instances are meant to be // obtained from the factory. LowEnergyClient(const UUID& uuid, int client_id); LowEnergyClient(Adapter& adapter, const UUID& uuid, int client_id); // BluetoothGattInterface::ClientObserver overrides: void MultiAdvEnableCallback( Loading Loading @@ -106,6 +108,9 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, void InvokeAndClearStartCallback(BLEStatus status); void InvokeAndClearStopCallback(BLEStatus status); // Raw pointer to the Bluetooth Adapter. Adapter& adapter_; // See getters above for documentation. UUID app_identifier_; int client_id_; Loading Loading @@ -144,7 +149,7 @@ class LowEnergyClientFactory public: // Don't construct/destruct directly except in tests. Instead, obtain a handle // from an Adapter instance. LowEnergyClientFactory(); LowEnergyClientFactory(Adapter& adapter); ~LowEnergyClientFactory() override; // BluetoothInstanceFactory override: Loading @@ -152,6 +157,8 @@ class LowEnergyClientFactory const RegisterCallback& callback) override; private: friend class LowEnergyClient; // BluetoothGattInterface::ClientObserver overrides: void RegisterClientCallback( hal::BluetoothGattInterface* gatt_iface, Loading @@ -162,6 +169,9 @@ class LowEnergyClientFactory std::mutex pending_calls_lock_; std::map<UUID, RegisterCallback> pending_calls_; // Raw pointer to the Adapter that owns this factory. Adapter& adapter_; DISALLOW_COPY_AND_ASSIGN(LowEnergyClientFactory); }; Loading system/service/test/low_energy_client_unittest.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> #include "service/adapter.h" #include "service/hal/fake_bluetooth_gatt_interface.h" #include "service/low_energy_client.h" #include "stack/include/bt_types.h" #include "stack/include/hcidefs.h" #include "test/mock_adapter.h" using ::testing::_; using ::testing::Return; Loading Loading @@ -119,7 +121,7 @@ class LowEnergyClientTest : public ::testing::Test { hal::FakeBluetoothGattInterface::TestClientHandler>(mock_handler_), nullptr); hal::BluetoothGattInterface::InitializeForTesting(fake_hal_gatt_iface_); ble_factory_.reset(new LowEnergyClientFactory()); ble_factory_.reset(new LowEnergyClientFactory(mock_adapter_)); } void TearDown() override { Loading @@ -129,6 +131,7 @@ class LowEnergyClientTest : public ::testing::Test { protected: hal::FakeBluetoothGattInterface* fake_hal_gatt_iface_; testing::MockAdapter mock_adapter_; std::shared_ptr<MockGattHandler> mock_handler_; std::unique_ptr<LowEnergyClientFactory> ble_factory_; Loading Loading @@ -163,7 +166,7 @@ class LowEnergyClientPostRegisterTest : public LowEnergyClientTest { bt_uuid_t hal_uuid = uuid.GetBlueDroid(); fake_hal_gatt_iface_->NotifyRegisterClientCallback(0, 0, hal_uuid); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); } void TearDown() override { Loading Loading @@ -262,7 +265,7 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { // the stack. EXPECT_FALSE(ble_factory_->RegisterInstance(uuid0, callback)); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); // Call with a different UUID while one is pending. UUID uuid1 = UUID::GetRandom(); Loading Loading @@ -298,7 +301,7 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); client.reset(); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); // |uuid1| fails. int client_if1 = 3; Loading Loading
system/service/adapter.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ class AdapterImpl : public Adapter, name_(kDefaultName) { memset(&local_le_features_, 0, sizeof(local_le_features_)); hal::BluetoothInterface::Get()->AddObserver(this); ble_client_factory_.reset(new LowEnergyClientFactory()); ble_client_factory_.reset(new LowEnergyClientFactory(*this)); gatt_client_factory_.reset(new GattClientFactory()); gatt_server_factory_.reset(new GattServerFactory()); hal::BluetoothInterface::Get()->GetHALInterface()->get_adapter_properties(); Loading
system/service/low_energy_client.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <base/logging.h> #include "service/adapter.h" #include "stack/include/bt_types.h" #include "stack/include/hcidefs.h" Loading Loading @@ -270,8 +271,10 @@ void GetAdvertiseParams(const AdvertiseSettings& settings, bool has_scan_rsp, // LowEnergyClient implementation // ======================================================== LowEnergyClient::LowEnergyClient(const UUID& uuid, int client_id) : app_identifier_(uuid), LowEnergyClient::LowEnergyClient( Adapter& adapter, const UUID& uuid, int client_id) : adapter_(adapter), app_identifier_(uuid), client_id_(client_id), adv_data_needs_update_(false), scan_rsp_needs_update_(false), Loading Loading @@ -588,7 +591,8 @@ void LowEnergyClient::InvokeAndClearStopCallback(BLEStatus status) { // LowEnergyClientFactory implementation // ======================================================== LowEnergyClientFactory::LowEnergyClientFactory() { LowEnergyClientFactory::LowEnergyClientFactory(Adapter& adapter) : adapter_(adapter) { hal::BluetoothGattInterface::Get()->AddClientObserver(this); } Loading Loading @@ -639,7 +643,7 @@ void LowEnergyClientFactory::RegisterClientCallback( std::unique_ptr<LowEnergyClient> client; BLEStatus result = BLE_STATUS_FAILURE; if (status == BT_STATUS_SUCCESS) { client.reset(new LowEnergyClient(uuid, client_id)); client.reset(new LowEnergyClient(adapter_, uuid, client_id)); // Use the unsafe variant to register this as an observer, since // LowEnergyClient instances only get created by LowEnergyClientCallback Loading
system/service/low_energy_client.h +12 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ namespace bluetooth { class Adapter; // A LowEnergyClient represents an application's handle to perform various // Bluetooth Low Energy GAP operations. Instances cannot be created directly and // should be obtained through the factory. Loading Loading @@ -78,7 +80,7 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, // Constructor shouldn't be called directly as instances are meant to be // obtained from the factory. LowEnergyClient(const UUID& uuid, int client_id); LowEnergyClient(Adapter& adapter, const UUID& uuid, int client_id); // BluetoothGattInterface::ClientObserver overrides: void MultiAdvEnableCallback( Loading Loading @@ -106,6 +108,9 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, void InvokeAndClearStartCallback(BLEStatus status); void InvokeAndClearStopCallback(BLEStatus status); // Raw pointer to the Bluetooth Adapter. Adapter& adapter_; // See getters above for documentation. UUID app_identifier_; int client_id_; Loading Loading @@ -144,7 +149,7 @@ class LowEnergyClientFactory public: // Don't construct/destruct directly except in tests. Instead, obtain a handle // from an Adapter instance. LowEnergyClientFactory(); LowEnergyClientFactory(Adapter& adapter); ~LowEnergyClientFactory() override; // BluetoothInstanceFactory override: Loading @@ -152,6 +157,8 @@ class LowEnergyClientFactory const RegisterCallback& callback) override; private: friend class LowEnergyClient; // BluetoothGattInterface::ClientObserver overrides: void RegisterClientCallback( hal::BluetoothGattInterface* gatt_iface, Loading @@ -162,6 +169,9 @@ class LowEnergyClientFactory std::mutex pending_calls_lock_; std::map<UUID, RegisterCallback> pending_calls_; // Raw pointer to the Adapter that owns this factory. Adapter& adapter_; DISALLOW_COPY_AND_ASSIGN(LowEnergyClientFactory); }; Loading
system/service/test/low_energy_client_unittest.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> #include "service/adapter.h" #include "service/hal/fake_bluetooth_gatt_interface.h" #include "service/low_energy_client.h" #include "stack/include/bt_types.h" #include "stack/include/hcidefs.h" #include "test/mock_adapter.h" using ::testing::_; using ::testing::Return; Loading Loading @@ -119,7 +121,7 @@ class LowEnergyClientTest : public ::testing::Test { hal::FakeBluetoothGattInterface::TestClientHandler>(mock_handler_), nullptr); hal::BluetoothGattInterface::InitializeForTesting(fake_hal_gatt_iface_); ble_factory_.reset(new LowEnergyClientFactory()); ble_factory_.reset(new LowEnergyClientFactory(mock_adapter_)); } void TearDown() override { Loading @@ -129,6 +131,7 @@ class LowEnergyClientTest : public ::testing::Test { protected: hal::FakeBluetoothGattInterface* fake_hal_gatt_iface_; testing::MockAdapter mock_adapter_; std::shared_ptr<MockGattHandler> mock_handler_; std::unique_ptr<LowEnergyClientFactory> ble_factory_; Loading Loading @@ -163,7 +166,7 @@ class LowEnergyClientPostRegisterTest : public LowEnergyClientTest { bt_uuid_t hal_uuid = uuid.GetBlueDroid(); fake_hal_gatt_iface_->NotifyRegisterClientCallback(0, 0, hal_uuid); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); } void TearDown() override { Loading Loading @@ -262,7 +265,7 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { // the stack. EXPECT_FALSE(ble_factory_->RegisterInstance(uuid0, callback)); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); // Call with a different UUID while one is pending. UUID uuid1 = UUID::GetRandom(); Loading Loading @@ -298,7 +301,7 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); client.reset(); testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); // |uuid1| fails. int client_if1 = 3; Loading