Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38e5415b authored by William Escande's avatar William Escande
Browse files

SDP code cleanup duplication

Bug: 246022810
Test: atest net_test_stack_sdp
Tag: #refactor
Merged-In: I2deeb024f9b6e28f95ed81738f1cdf587ae84e68
Change-Id: I2deeb024f9b6e28f95ed81738f1cdf587ae84e68
(cherry picked from commit 220fc132)
parent f53d7b4e
Loading
Loading
Loading
Loading
+7 −35
Original line number Diff line number Diff line
@@ -257,17 +257,9 @@ static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
    return;
  }

  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(((p_ccb->con_state == SDP_STATE_CONNECTED)
  sdpu_callback(p_ccb, (p_ccb->con_state == SDP_STATE_CONNECTED)
                           ? SDP_SUCCESS
                        : SDP_CONN_FAILED));
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(
        ((p_ccb->con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS
                                                   : SDP_CONN_FAILED),
        p_ccb->user_data);

                           : SDP_CONN_FAILED);
  if (ack_needed) {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, process pend sdp ccb: 0x%x",
                      l2cap_cid);
@@ -394,12 +386,7 @@ void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason) {
    p_ccb->disconnect_reason = reason;
    if (SDP_SUCCESS == reason &&
        (true == sdpu_process_pend_ccb(p_ccb->connection_id, true))) {
      /* Tell the user if he has a callback */
      if (p_ccb->p_cb)
        (*p_ccb->p_cb)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason));
      else if (p_ccb->p_cb2)
        (*p_ccb->p_cb2)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason),
                        p_ccb->user_data);
      sdpu_callback(p_ccb, reason);
      sdpu_release_ccb(p_ccb);
      return;
    } else {
@@ -410,12 +397,7 @@ void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason) {
  /* If at setup state, we may not get callback ind from L2CAP */
  /* Call user callback immediately */
  if (p_ccb->con_state == SDP_STATE_CONN_SETUP) {
    /* Tell the user if there is a callback */
    if (p_ccb->p_cb)
      (*p_ccb->p_cb)(reason);
    else if (p_ccb->p_cb2)
      (*p_ccb->p_cb2)(reason, p_ccb->user_data);

    sdpu_callback(p_ccb, reason);
    sdpu_release_ccb(p_ccb);
  }
}
@@ -443,13 +425,7 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid,

  SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);

  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason));
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(static_cast<tSDP_STATUS>(p_ccb->disconnect_reason),
                    p_ccb->user_data);

  sdpu_callback(p_ccb, static_cast<tSDP_STATUS>(p_ccb->disconnect_reason));
  sdpu_process_pend_ccb(p_ccb->connection_id, false);
  sdpu_release_ccb(p_ccb);
}
@@ -472,11 +448,7 @@ void sdp_conn_timer_timeout(void* data) {

  L2CA_DisconnectReq(p_ccb->connection_id);

  /* Tell the user if there is a callback */
  if (p_ccb->p_cb)
    (*p_ccb->p_cb)(SDP_CONN_FAILED);
  else if (p_ccb->p_cb2)
    (*p_ccb->p_cb2)(SDP_CONN_FAILED, p_ccb->user_data);
  sdpu_callback(p_ccb, SDP_CONN_FAILED);
  sdpu_clear_pend_ccb(p_ccb->connection_id);
  sdpu_release_ccb(p_ccb);
}
+19 −10
Original line number Diff line number Diff line
@@ -384,6 +384,23 @@ tCONN_CB* sdpu_allocate_ccb(void) {
  return (NULL);
}

/*******************************************************************************
 *
 * Function         sdpu_callback
 *
 * Description      Tell the user if they have a callback
 *
 * Returns          void
 *
 ******************************************************************************/
void sdpu_callback(tCONN_CB* p_ccb, tSDP_REASON reason) {
  if (p_ccb->p_cb) {
    (*p_ccb->p_cb)(reason);
  } else if (p_ccb->p_cb2) {
    (*p_ccb->p_cb2)(reason, p_ccb->user_data);
  }
}

/*******************************************************************************
 *
 * Function         sdpu_release_ccb
@@ -486,11 +503,7 @@ bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
      if (new_cid != 0) {
        p_ccb->connection_id = new_cid;
      } else {
        // Tell the user if he has a callback
        if (p_ccb->p_cb)
          (*p_ccb->p_cb)(SDP_CONN_FAILED);
        else if (p_ccb->p_cb2)
          (*p_ccb->p_cb2)(SDP_CONN_FAILED, p_ccb->user_data);
        sdpu_callback(p_ccb, SDP_CONN_FAILED);
        sdpu_release_ccb(p_ccb);
      }
    }
@@ -518,11 +531,7 @@ void sdpu_clear_pend_ccb(uint16_t cid) {
    if ((p_ccb->con_state == SDP_STATE_CONN_PEND) &&
        (p_ccb->connection_id == cid) &&
        (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)) {
      // Tell the user if he has a callback
      if (p_ccb->p_cb)
        (*p_ccb->p_cb)(SDP_CONN_FAILED);
      else if (p_ccb->p_cb2)
        (*p_ccb->p_cb2)(SDP_CONN_FAILED, p_ccb->user_data);
      sdpu_callback(p_ccb, SDP_CONN_FAILED);
      sdpu_release_ccb(p_ccb);
    }
  }
+1 −0
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ extern void sdpu_set_avrc_target_version(const tSDP_ATTRIBUTE* p_attr,
extern uint16_t sdpu_get_active_ccb_cid(const RawAddress& remote_bd_addr);
extern bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl);
extern void sdpu_clear_pend_ccb(uint16_t cid);
extern void sdpu_callback(tCONN_CB* p_ccb, tSDP_REASON reason);

/* Functions provided by sdp_db.cc
 */