From 6e021b316fd0544f4bb62b5b6f2a8af56cdada53 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Mon, 30 Nov 2020 15:36:44 -0800 Subject: [PATCH] Simplify code in shim/l2c_api.cc Tag: #gd-refactor Bug: 141555841 Test: cert/run --host Test: Pair and connect with a headset Change-Id: Iae00fbea2dba97485047793d5355c3072258d28f --- main/shim/l2c_api.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main/shim/l2c_api.cc b/main/shim/l2c_api.cc index ee58a6e0d..9d6d28a35 100644 --- a/main/shim/l2c_api.cc +++ b/main/shim/l2c_api.cc @@ -43,15 +43,12 @@ using namespace bluetooth::l2cap; uint16_t classic_cid_token_counter_ = 0x41; -struct ClassicDynamicChannelInfo { - uint16_t psm; -}; -std::unordered_map +std::unordered_map classic_cid_token_to_channel_map_; uint16_t add_classic_cid_token_entry(uint16_t psm) { uint16_t new_token = classic_cid_token_counter_; - classic_cid_token_to_channel_map_[new_token] = {psm}; + classic_cid_token_to_channel_map_[new_token] = psm; classic_cid_token_counter_++; if (classic_cid_token_counter_ == 0) classic_cid_token_counter_ = 0x41; return new_token; @@ -593,7 +590,7 @@ uint16_t bluetooth::shim::L2CA_ConnectReq(uint16_t psm, } bool bluetooth::shim::L2CA_DisconnectReq(uint16_t cid) { - auto psm = classic_cid_token_to_channel_map_[cid].psm; + auto psm = classic_cid_token_to_channel_map_[cid]; if (classic_dynamic_channel_helper_map_.count(psm) == 0) { LOG(ERROR) << __func__ << "Not registered psm: " << psm; return false; @@ -607,7 +604,7 @@ uint8_t bluetooth::shim::L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) { LOG(ERROR) << __func__ << "Invalid cid: " << cid; return 0; } - auto psm = classic_cid_token_to_channel_map_[cid].psm; + auto psm = classic_cid_token_to_channel_map_[cid]; if (classic_dynamic_channel_helper_map_.count(psm) == 0) { LOG(ERROR) << __func__ << "Not registered psm: " << psm; return 0; @@ -856,7 +853,7 @@ bool bluetooth::shim::L2CA_RemoveFixedChnl(uint16_t cid, * Channel hygiene APIs */ bool bluetooth::shim::L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid) { - auto psm = classic_cid_token_to_channel_map_[lcid].psm; + auto psm = classic_cid_token_to_channel_map_[lcid]; if (classic_dynamic_channel_helper_map_.count(psm) == 0) { LOG(ERROR) << __func__ << "Not registered psm: " << psm; return false; -- 2.11.0