OSDN Git Service

Simplify code in shim/l2c_api.cc
authorHansong Zhang <hsz@google.com>
Mon, 30 Nov 2020 23:36:44 +0000 (15:36 -0800)
committerHansong Zhang <hsz@google.com>
Wed, 2 Dec 2020 04:19:47 +0000 (20:19 -0800)
Tag: #gd-refactor
Bug: 141555841
Test: cert/run --host
Test: Pair and connect with a headset
Change-Id: Iae00fbea2dba97485047793d5355c3072258d28f

main/shim/l2c_api.cc

index ee58a6e..9d6d28a 100644 (file)
@@ -43,15 +43,12 @@ using namespace bluetooth::l2cap;
 
 uint16_t classic_cid_token_counter_ = 0x41;
 
-struct ClassicDynamicChannelInfo {
-  uint16_t psm;
-};
-std::unordered_map<uint16_t, ClassicDynamicChannelInfo>
+std::unordered_map<uint16_t /* token */, uint16_t /* cid */>
     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;