Loading system/gd/neighbor/name_db.cc +11 −7 Original line number Original line Diff line number Diff line Loading @@ -49,7 +49,7 @@ struct NameDbModule::impl { void Stop(); void Stop(); private: private: std::unordered_map<hci::Address, PendingRemoteNameRead> address_to_pending_read_map_; std::unordered_map<hci::Address, std::list<PendingRemoteNameRead>> address_to_pending_read_map_; std::unordered_map<hci::Address, RemoteName> address_to_name_map_; std::unordered_map<hci::Address, RemoteName> address_to_name_map_; void OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name); void OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name); Loading @@ -67,11 +67,14 @@ neighbor::NameDbModule::impl::impl(const neighbor::NameDbModule& module) : modul void neighbor::NameDbModule::impl::ReadRemoteNameRequest( void neighbor::NameDbModule::impl::ReadRemoteNameRequest( hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler) { hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler) { if (address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()) { if (address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()) { LOG_WARN("Already have remote read db in progress and currently can only have one outstanding"); LOG_WARN("Already have remote read db in progress; adding callback to callback list"); address_to_pending_read_map_[address].push_back({std::move(callback), handler}); return; return; } } address_to_pending_read_map_[address] = {std::move(callback), std::move(handler)}; std::list<PendingRemoteNameRead> tmp; address_to_pending_read_map_[address] = std::move(tmp); address_to_pending_read_map_[address].push_back({std::move(callback), handler}); // TODO(cmanton) Use remote name request defaults for now // TODO(cmanton) Use remote name request defaults for now hci::PageScanRepetitionMode page_scan_repetition_mode = hci::PageScanRepetitionMode::R1; hci::PageScanRepetitionMode page_scan_repetition_mode = hci::PageScanRepetitionMode::R1; Loading @@ -88,13 +91,14 @@ void neighbor::NameDbModule::impl::ReadRemoteNameRequest( void neighbor::NameDbModule::impl::OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name) { void neighbor::NameDbModule::impl::OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name) { ASSERT(address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()); ASSERT(address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()); PendingRemoteNameRead callback_handler = std::move(address_to_pending_read_map_.at(address)); if (status == hci::ErrorCode::SUCCESS) { if (status == hci::ErrorCode::SUCCESS) { address_to_name_map_[address] = name; address_to_name_map_[address] = name; } } callback_handler.handler_->Post( auto& callback_list = address_to_pending_read_map_.at(address); common::BindOnce(std::move(callback_handler.callback_), address, status == hci::ErrorCode::SUCCESS)); for (auto& it : callback_list) { it.handler_->Call(std::move(it.callback_), address, status == hci::ErrorCode::SUCCESS); } address_to_pending_read_map_.erase(address); } } bool neighbor::NameDbModule::impl::IsNameCached(hci::Address address) const { bool neighbor::NameDbModule::impl::IsNameCached(hci::Address address) const { Loading system/gd/neighbor/name_db.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,7 @@ using ReadRemoteNameDbCallback = common::OnceCallback<void(hci::Address address, class NameDbModule : public bluetooth::Module { class NameDbModule : public bluetooth::Module { public: public: void ReadRemoteNameRequest(hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler); virtual void ReadRemoteNameRequest(hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler); bool IsNameCached(hci::Address address) const; bool IsNameCached(hci::Address address) const; RemoteName ReadCachedRemoteName(hci::Address address) const; RemoteName ReadCachedRemoteName(hci::Address address) const; Loading system/gd/security/test/fake_name_db.h +14 −0 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,20 @@ class FakeNameDbModule : public neighbor::NameDbModule { void ListDependencies(ModuleList* list) override {} void ListDependencies(ModuleList* list) override {} void Start() override {} void Start() override {} void Stop() override {} void Stop() override {} void ReadRemoteNameRequest( hci::Address address, neighbor::ReadRemoteNameDbCallback callback, os::Handler* handler) override { handler->Call(std::move(callback), address, true); } bool IsNameCached(hci::Address address) const { return true; } neighbor::RemoteName ReadCachedRemoteName(hci::Address address) const { neighbor::RemoteName name = {'t', 'e', 's', 't'}; return name; } }; }; } // namespace security } // namespace security Loading Loading
system/gd/neighbor/name_db.cc +11 −7 Original line number Original line Diff line number Diff line Loading @@ -49,7 +49,7 @@ struct NameDbModule::impl { void Stop(); void Stop(); private: private: std::unordered_map<hci::Address, PendingRemoteNameRead> address_to_pending_read_map_; std::unordered_map<hci::Address, std::list<PendingRemoteNameRead>> address_to_pending_read_map_; std::unordered_map<hci::Address, RemoteName> address_to_name_map_; std::unordered_map<hci::Address, RemoteName> address_to_name_map_; void OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name); void OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name); Loading @@ -67,11 +67,14 @@ neighbor::NameDbModule::impl::impl(const neighbor::NameDbModule& module) : modul void neighbor::NameDbModule::impl::ReadRemoteNameRequest( void neighbor::NameDbModule::impl::ReadRemoteNameRequest( hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler) { hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler) { if (address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()) { if (address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()) { LOG_WARN("Already have remote read db in progress and currently can only have one outstanding"); LOG_WARN("Already have remote read db in progress; adding callback to callback list"); address_to_pending_read_map_[address].push_back({std::move(callback), handler}); return; return; } } address_to_pending_read_map_[address] = {std::move(callback), std::move(handler)}; std::list<PendingRemoteNameRead> tmp; address_to_pending_read_map_[address] = std::move(tmp); address_to_pending_read_map_[address].push_back({std::move(callback), handler}); // TODO(cmanton) Use remote name request defaults for now // TODO(cmanton) Use remote name request defaults for now hci::PageScanRepetitionMode page_scan_repetition_mode = hci::PageScanRepetitionMode::R1; hci::PageScanRepetitionMode page_scan_repetition_mode = hci::PageScanRepetitionMode::R1; Loading @@ -88,13 +91,14 @@ void neighbor::NameDbModule::impl::ReadRemoteNameRequest( void neighbor::NameDbModule::impl::OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name) { void neighbor::NameDbModule::impl::OnRemoteNameResponse(hci::ErrorCode status, hci::Address address, RemoteName name) { ASSERT(address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()); ASSERT(address_to_pending_read_map_.find(address) != address_to_pending_read_map_.end()); PendingRemoteNameRead callback_handler = std::move(address_to_pending_read_map_.at(address)); if (status == hci::ErrorCode::SUCCESS) { if (status == hci::ErrorCode::SUCCESS) { address_to_name_map_[address] = name; address_to_name_map_[address] = name; } } callback_handler.handler_->Post( auto& callback_list = address_to_pending_read_map_.at(address); common::BindOnce(std::move(callback_handler.callback_), address, status == hci::ErrorCode::SUCCESS)); for (auto& it : callback_list) { it.handler_->Call(std::move(it.callback_), address, status == hci::ErrorCode::SUCCESS); } address_to_pending_read_map_.erase(address); } } bool neighbor::NameDbModule::impl::IsNameCached(hci::Address address) const { bool neighbor::NameDbModule::impl::IsNameCached(hci::Address address) const { Loading
system/gd/neighbor/name_db.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,7 @@ using ReadRemoteNameDbCallback = common::OnceCallback<void(hci::Address address, class NameDbModule : public bluetooth::Module { class NameDbModule : public bluetooth::Module { public: public: void ReadRemoteNameRequest(hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler); virtual void ReadRemoteNameRequest(hci::Address address, ReadRemoteNameDbCallback callback, os::Handler* handler); bool IsNameCached(hci::Address address) const; bool IsNameCached(hci::Address address) const; RemoteName ReadCachedRemoteName(hci::Address address) const; RemoteName ReadCachedRemoteName(hci::Address address) const; Loading
system/gd/security/test/fake_name_db.h +14 −0 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,20 @@ class FakeNameDbModule : public neighbor::NameDbModule { void ListDependencies(ModuleList* list) override {} void ListDependencies(ModuleList* list) override {} void Start() override {} void Start() override {} void Stop() override {} void Stop() override {} void ReadRemoteNameRequest( hci::Address address, neighbor::ReadRemoteNameDbCallback callback, os::Handler* handler) override { handler->Call(std::move(callback), address, true); } bool IsNameCached(hci::Address address) const { return true; } neighbor::RemoteName ReadCachedRemoteName(hci::Address address) const { neighbor::RemoteName name = {'t', 'e', 's', 't'}; return name; } }; }; } // namespace security } // namespace security Loading