From b22d23d374b5382b1c58cd573e4c5e74ef34e2dc Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Sat, 18 Jan 2020 17:29:38 -0800 Subject: [PATCH] Fix legacy shim namespace Align namespaces to adhere to convention Bug: 140421732 Test: Builds Change-Id: I23e716f7250b79d147ba0db974b91578ebf63d56 --- main/shim/l2c_api.cc | 2 +- main/shim/l2cap.cc | 66 ++++++++++++++++++++++++------------------------- main/shim/l2cap.h | 4 +-- main/shim/l2cap_test.cc | 6 ++--- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/main/shim/l2c_api.cc b/main/shim/l2c_api.cc index 357cd0387..ef0fc1018 100644 --- a/main/shim/l2c_api.cc +++ b/main/shim/l2c_api.cc @@ -21,7 +21,7 @@ #include "main/shim/shim.h" #include "osi/include/log.h" -static bluetooth::legacy::shim::L2cap shim_l2cap; +static bluetooth::shim::legacy::L2cap shim_l2cap; /** * Classic Service Registration APIs diff --git a/main/shim/l2cap.cc b/main/shim/l2cap.cc index f9f565d35..575e317c8 100644 --- a/main/shim/l2cap.cc +++ b/main/shim/l2cap.cc @@ -35,36 +35,36 @@ constexpr uint8_t kUnusedId = 0; constexpr uint16_t kUnusedResult = 0; } // namespace -bool bluetooth::legacy::shim::PsmManager::IsPsmRegistered(uint16_t psm) const { +bool bluetooth::shim::legacy::PsmManager::IsPsmRegistered(uint16_t psm) const { return psm_to_callback_map_.find(psm) != psm_to_callback_map_.end(); } -bool bluetooth::legacy::shim::PsmManager::HasClient(uint16_t psm) const { +bool bluetooth::shim::legacy::PsmManager::HasClient(uint16_t psm) const { return IsPsmRegistered(psm) && psm_to_callback_map_.at(psm) != nullptr; } -void bluetooth::legacy::shim::PsmManager::RegisterPsm( +void bluetooth::shim::legacy::PsmManager::RegisterPsm( uint16_t psm, const tL2CAP_APPL_INFO* callbacks) { CHECK(!HasClient(psm)); psm_to_callback_map_[psm] = callbacks; } -void bluetooth::legacy::shim::PsmManager::RegisterPsm(uint16_t psm) { +void bluetooth::shim::legacy::PsmManager::RegisterPsm(uint16_t psm) { RegisterPsm(psm, nullptr); } -void bluetooth::legacy::shim::PsmManager::UnregisterPsm(uint16_t psm) { +void bluetooth::shim::legacy::PsmManager::UnregisterPsm(uint16_t psm) { CHECK(IsPsmRegistered(psm)); psm_to_callback_map_.erase(psm); } -const tL2CAP_APPL_INFO* bluetooth::legacy::shim::PsmManager::Callbacks( +const tL2CAP_APPL_INFO* bluetooth::shim::legacy::PsmManager::Callbacks( uint16_t psm) { CHECK(HasClient(psm)); return psm_to_callback_map_[psm]; } -bluetooth::legacy::shim::L2cap::L2cap() +bluetooth::shim::legacy::L2cap::L2cap() : classic_dynamic_psm_(kInitialClassicDynamicPsm), le_dynamic_psm_(kInitialLeDynamicPsm), classic_virtual_psm_(kInitialClassicVirtualPsm) { @@ -72,28 +72,28 @@ bluetooth::legacy::shim::L2cap::L2cap() [this](int fd) { Dump(fd); }); } -bluetooth::legacy::shim::L2cap::~L2cap() { +bluetooth::shim::legacy::L2cap::~L2cap() { bluetooth::shim::UnregisterDumpsysFunction(static_cast(this)); } -bluetooth::legacy::shim::PsmManager& bluetooth::legacy::shim::L2cap::Le() { +bluetooth::shim::legacy::PsmManager& bluetooth::shim::legacy::L2cap::Le() { return le_; } -bluetooth::legacy::shim::PsmManager& bluetooth::legacy::shim::L2cap::Classic() { +bluetooth::shim::legacy::PsmManager& bluetooth::shim::legacy::L2cap::Classic() { return classic_; } -bool bluetooth::legacy::shim::L2cap::ConnectionExists(uint16_t cid) const { +bool bluetooth::shim::legacy::L2cap::ConnectionExists(uint16_t cid) const { return cid_to_psm_map_.find(cid) != cid_to_psm_map_.end(); } -uint16_t bluetooth::legacy::shim::L2cap::CidToPsm(uint16_t cid) const { +uint16_t bluetooth::shim::legacy::L2cap::CidToPsm(uint16_t cid) const { CHECK(ConnectionExists(cid)); return cid_to_psm_map_.at(cid); } -uint16_t bluetooth::legacy::shim::L2cap::ConvertClientToRealPsm( +uint16_t bluetooth::shim::legacy::L2cap::ConvertClientToRealPsm( uint16_t client_psm, bool is_outgoing_only_connection) { if (!is_outgoing_only_connection) { return client_psm; @@ -101,7 +101,7 @@ uint16_t bluetooth::legacy::shim::L2cap::ConvertClientToRealPsm( return GetNextVirtualPsm(client_psm); } -uint16_t bluetooth::legacy::shim::L2cap::ConvertClientToRealPsm( +uint16_t bluetooth::shim::legacy::L2cap::ConvertClientToRealPsm( uint16_t client_psm) { if (client_psm_to_real_psm_map_.find(client_psm) == client_psm_to_real_psm_map_.end()) { @@ -110,14 +110,14 @@ uint16_t bluetooth::legacy::shim::L2cap::ConvertClientToRealPsm( return client_psm_to_real_psm_map_.at(client_psm); } -void bluetooth::legacy::shim::L2cap::RemoveClientPsm(uint16_t client_psm) { +void bluetooth::shim::legacy::L2cap::RemoveClientPsm(uint16_t client_psm) { if (client_psm_to_real_psm_map_.find(client_psm) != client_psm_to_real_psm_map_.end()) { client_psm_to_real_psm_map_.erase(client_psm); } } -uint16_t bluetooth::legacy::shim::L2cap::GetNextVirtualPsm(uint16_t real_psm) { +uint16_t bluetooth::shim::legacy::L2cap::GetNextVirtualPsm(uint16_t real_psm) { if (real_psm < kInitialClassicDynamicPsm) { return real_psm; } @@ -131,7 +131,7 @@ uint16_t bluetooth::legacy::shim::L2cap::GetNextVirtualPsm(uint16_t real_psm) { return classic_virtual_psm_; } -uint16_t bluetooth::legacy::shim::L2cap::GetNextDynamicLePsm() { +uint16_t bluetooth::shim::legacy::L2cap::GetNextDynamicLePsm() { while (Le().IsPsmRegistered(le_dynamic_psm_)) { le_dynamic_psm_++; if (le_dynamic_psm_ > kFinalLeDynamicPsm) { @@ -141,7 +141,7 @@ uint16_t bluetooth::legacy::shim::L2cap::GetNextDynamicLePsm() { return le_dynamic_psm_; } -uint16_t bluetooth::legacy::shim::L2cap::GetNextDynamicClassicPsm() { +uint16_t bluetooth::shim::legacy::L2cap::GetNextDynamicClassicPsm() { while (Classic().IsPsmRegistered(classic_dynamic_psm_)) { classic_dynamic_psm_ += 2; if (classic_dynamic_psm_ > kFinalClassicDynamicPsm) { @@ -160,7 +160,7 @@ uint16_t bluetooth::legacy::shim::L2cap::GetNextDynamicClassicPsm() { return classic_dynamic_psm_; } -void bluetooth::legacy::shim::L2cap::RegisterService( +void bluetooth::shim::legacy::L2cap::RegisterService( uint16_t psm, const tL2CAP_APPL_INFO* callbacks, bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info) { LOG_DEBUG(LOG_TAG, "Registering service on psm:%hd", psm); @@ -181,7 +181,7 @@ void bluetooth::legacy::shim::L2cap::RegisterService( bluetooth::shim::GetL2cap()->RegisterService( psm, use_ertm, mtu, std::bind( - &bluetooth::legacy::shim::L2cap::OnRemoteInitiatedConnectionCreated, + &bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), std::move(register_completed)); @@ -189,7 +189,7 @@ void bluetooth::legacy::shim::L2cap::RegisterService( LOG_DEBUG(LOG_TAG, "Successfully registered service on psm:%hd", psm); } -void bluetooth::legacy::shim::L2cap::OnRemoteInitiatedConnectionCreated( +void bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated( std::string string_address, uint16_t psm, uint16_t cid) { RawAddress raw_address; RawAddress::FromString(string_address, raw_address); @@ -206,7 +206,7 @@ void bluetooth::legacy::shim::L2cap::OnRemoteInitiatedConnectionCreated( kUnusedId); } -void bluetooth::legacy::shim::L2cap::UnregisterService(uint16_t psm) { +void bluetooth::shim::legacy::L2cap::UnregisterService(uint16_t psm) { if (!Classic().IsPsmRegistered(psm)) { LOG_WARN(LOG_TAG, "Service must be registered in order to unregister psm:%hd", psm); @@ -225,7 +225,7 @@ void bluetooth::legacy::shim::L2cap::UnregisterService(uint16_t psm) { Classic().UnregisterPsm(psm); } -uint16_t bluetooth::legacy::shim::L2cap::CreateConnection( +uint16_t bluetooth::shim::legacy::L2cap::CreateConnection( uint16_t psm, const RawAddress& raw_address) { if (!Classic().IsPsmRegistered(psm)) { LOG_WARN(LOG_TAG, "Service must be registered in order to connect psm:%hd", @@ -242,7 +242,7 @@ uint16_t bluetooth::legacy::shim::L2cap::CreateConnection( bluetooth::shim::GetL2cap()->CreateConnection( psm, raw_address.ToString(), std::bind( - &bluetooth::legacy::shim::L2cap::OnLocalInitiatedConnectionCreated, + &bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), std::move(connect_completed)); @@ -263,7 +263,7 @@ uint16_t bluetooth::legacy::shim::L2cap::CreateConnection( return cid; } -void bluetooth::legacy::shim::L2cap::OnLocalInitiatedConnectionCreated( +void bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated( std::string string_address, uint16_t psm, uint16_t cid) { LOG_DEBUG(LOG_TAG, "Sending connection confirm to the upper stack but really " @@ -277,7 +277,7 @@ void bluetooth::legacy::shim::L2cap::OnLocalInitiatedConnectionCreated( Classic().Callbacks(psm)->pL2CA_ConnectCfm_Cb(cid, status); } -bool bluetooth::legacy::shim::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) { +bool bluetooth::shim::legacy::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) { CHECK(bt_hdr != nullptr); const uint8_t* data = bt_hdr->data + bt_hdr->offset; size_t len = bt_hdr->len; @@ -289,7 +289,7 @@ bool bluetooth::legacy::shim::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) { return true; } -void bluetooth::legacy::shim::L2cap::SetDownstreamCallbacks(uint16_t cid) { +void bluetooth::shim::legacy::L2cap::SetDownstreamCallbacks(uint16_t cid) { bluetooth::shim::GetL2cap()->SetReadDataReadyCallback( cid, [this](uint16_t cid, std::vector data) { LOG_DEBUG(LOG_TAG, "OnDataReady cid:%hd len:%zd", cid, data.size()); @@ -320,7 +320,7 @@ void bluetooth::legacy::shim::L2cap::SetDownstreamCallbacks(uint16_t cid) { }); } -bool bluetooth::legacy::shim::L2cap::ConnectResponse( +bool bluetooth::shim::legacy::L2cap::ConnectResponse( const RawAddress& raw_address, uint8_t signal_id, uint16_t cid, uint16_t result, uint16_t status, tL2CAP_ERTM_INFO* ertm_info) { CHECK(ConnectionExists(cid)); @@ -331,7 +331,7 @@ bool bluetooth::legacy::shim::L2cap::ConnectResponse( return true; } -bool bluetooth::legacy::shim::L2cap::ConfigRequest( +bool bluetooth::shim::legacy::L2cap::ConfigRequest( uint16_t cid, const tL2CAP_CFG_INFO* config_info) { LOG_INFO(LOG_TAG, "Received config request from upper layer cid:%hd", cid); CHECK(ConnectionExists(cid)); @@ -354,7 +354,7 @@ bool bluetooth::legacy::shim::L2cap::ConfigRequest( return true; } -bool bluetooth::legacy::shim::L2cap::ConfigResponse( +bool bluetooth::shim::legacy::L2cap::ConfigResponse( uint16_t cid, const tL2CAP_CFG_INFO* config_info) { CHECK(ConnectionExists(cid)); LOG_DEBUG( @@ -364,7 +364,7 @@ bool bluetooth::legacy::shim::L2cap::ConfigResponse( return true; } -bool bluetooth::legacy::shim::L2cap::DisconnectRequest(uint16_t cid) { +bool bluetooth::shim::legacy::L2cap::DisconnectRequest(uint16_t cid) { CHECK(ConnectionExists(cid)); if (cid_closing_set_.find(cid) != cid_closing_set_.end()) { LOG_WARN(LOG_TAG, "%s Channel already in closing state cid:%hu", __func__, @@ -377,7 +377,7 @@ bool bluetooth::legacy::shim::L2cap::DisconnectRequest(uint16_t cid) { return true; } -bool bluetooth::legacy::shim::L2cap::DisconnectResponse(uint16_t cid) { +bool bluetooth::shim::legacy::L2cap::DisconnectResponse(uint16_t cid) { LOG_DEBUG(LOG_TAG, "%s Silently dropping client disconnect response as channel is " "already disconnected", @@ -385,7 +385,7 @@ bool bluetooth::legacy::shim::L2cap::DisconnectResponse(uint16_t cid) { return true; } -void bluetooth::legacy::shim::L2cap::Dump(int fd) { +void bluetooth::shim::legacy::L2cap::Dump(int fd) { if (cid_to_psm_map_.empty()) { dprintf(fd, "%s No active l2cap channels\n", kModuleName); } else { diff --git a/main/shim/l2cap.h b/main/shim/l2cap.h index 8c0d0da28..65b2759f8 100644 --- a/main/shim/l2cap.h +++ b/main/shim/l2cap.h @@ -24,8 +24,8 @@ #include "stack/include/l2c_api.h" namespace bluetooth { -namespace legacy { namespace shim { +namespace legacy { static constexpr uint16_t kInitialClassicDynamicPsm = 0x1001; static constexpr uint16_t kFinalClassicDynamicPsm = 0xfeff; @@ -120,6 +120,6 @@ class L2cap { std::unordered_map client_psm_to_real_psm_map_; }; -} // namespace shim } // namespace legacy +} // namespace shim } // namespace bluetooth diff --git a/main/shim/l2cap_test.cc b/main/shim/l2cap_test.cc index 6a5b76cae..7708ae2ae 100644 --- a/main/shim/l2cap_test.cc +++ b/main/shim/l2cap_test.cc @@ -47,7 +47,7 @@ L2capTest* l2cap_test_ = nullptr; class L2capTest : public ::testing::Test { public: - static shim::L2cap* l2cap_; + static shim::legacy::L2cap* l2cap_; struct { int L2caConnectCfmCb; @@ -77,7 +77,7 @@ class L2capTest : public ::testing::Test { protected: void SetUp() override { - l2cap_ = new shim::L2cap(); + l2cap_ = new shim::legacy::L2cap(); l2cap_test_ = this; } @@ -89,7 +89,7 @@ class L2capTest : public ::testing::Test { uint8_t data_buffer_[kDataBufferSize]; }; -shim::L2cap* L2capTest::l2cap_ = nullptr; +shim::legacy::L2cap* L2capTest::l2cap_ = nullptr; // Indication of remotely initiated connection response sent void L2caConnectIndCb(const RawAddress& raw_address, uint16_t a, uint16_t b, uint8_t c) { -- 2.11.0