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

Commit 78b05005 authored by Chris Manton's avatar Chris Manton
Browse files

stack::rfcomm: Combine 2 APIs creating PORT_SetEventMaskAndCallback

Combine:

PORT_SetEventMask(...)
PORT_SetEventCallback(...)
The callback is called if an event in the corresponding bitmask is set indicating they should be logically aggregated.

Bug: 345258558
Test: m .
Flag: EXEMPT, Mechanical Refactor

Change-Id: Id5478343fd3f32ee88073b73dcacc9f775fcfff7
parent a3f62c80
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -228,13 +228,10 @@ void bta_ag_setup_port(tBTA_AG_SCB* p_scb, uint16_t handle) {
                                             sizeof(bta_ag_port_cback_tbl[0])),
      "callback index out of bound, handle={}, bd_addr={}", handle,
      ADDRESS_TO_LOGGABLE_STR(p_scb->peer_addr));
  if (PORT_SetEventMask(handle, BTA_AG_PORT_EV_MASK) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event mask peer:{} handle:{}",
              p_scb->peer_addr, handle);
  }
  if (PORT_SetEventCallback(
          handle, bta_ag_port_cback_tbl[port_callback_index]) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event callback peer:{} handle:{}",
  if (PORT_SetEventMaskAndCallback(
          handle, BTA_AG_PORT_EV_MASK,
          bta_ag_port_cback_tbl[port_callback_index]) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event and callback mask peer:{} handle:{}",
              p_scb->peer_addr, handle);
  }
}
+3 −5
Original line number Diff line number Diff line
@@ -170,11 +170,9 @@ static void bta_hf_client_mgmt_cback(const tPORT_RESULT code,
 *
 ******************************************************************************/
void bta_hf_client_setup_port(uint16_t handle) {
  if (PORT_SetEventMask(handle, PORT_EV_RXCHAR) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event mask handle:{}", handle);
  }
  if (PORT_SetEventCallback(handle, bta_hf_client_port_cback) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event callback handle:{}", handle);
  if (PORT_SetEventMaskAndCallback(handle, PORT_EV_RXCHAR,
                                   bta_hf_client_port_cback) != PORT_SUCCESS) {
    log::warn("Unable to set RFCOMM event mask and callbackhandle:{}", handle);
  }
}

+14 −21
Original line number Diff line number Diff line
@@ -1507,12 +1507,10 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
      p_pcb->rfcomm_slot_id = rfcomm_slot_id;
      bta_jv.rfc_cl_init.use_co = true;

      if (PORT_SetEventMask(handle, event_mask) != PORT_SUCCESS) {
        log::warn("Unable to set RFCOMM client event mask handle:{}", handle);
      }
      if (PORT_SetEventCallback(handle, bta_jv_port_event_cl_cback) !=
          PORT_SUCCESS) {
        log::warn("Unable to set RFCOMM client event callback handle:{}",
      if (PORT_SetEventMaskAndCallback(
              handle, event_mask, bta_jv_port_event_cl_cback) != PORT_SUCCESS) {
        log::warn(
            "Unable to set RFCOMM client event mask and callback handle:{}",
            handle);
      }
      if (PORT_SetDataCOCallback(handle, bta_jv_port_data_co_cback) !=
@@ -1772,13 +1770,11 @@ static tBTA_JV_PCB* bta_jv_add_rfc_port(tBTA_JV_RFC_CB* p_cb,
          log::warn("Unable to clear RFCOMM server keep handle flag handle:{}",
                    p_pcb->port_handle);
        }
        if (PORT_SetEventMask(p_pcb->port_handle, event_mask) != PORT_SUCCESS) {
          log::warn("Unable to set RFCOMM server event mask handle:{}",
                    p_pcb->port_handle);
        }
        if (PORT_SetEventCallback(p_pcb->port_handle,
                                  bta_jv_port_event_sr_cback) != PORT_SUCCESS) {
          log::warn("Unable to set RFCOMM server event callback handle:{}",
        if (PORT_SetEventMaskAndCallback(p_pcb->port_handle, event_mask,
                                         bta_jv_port_event_sr_cback) !=
            PORT_SUCCESS) {
          log::warn(
              "Unable to set RFCOMM server event mask and callback handle:{}",
              p_pcb->port_handle);
        }
        if (PORT_SetDataCOCallback(p_pcb->port_handle,
@@ -1854,12 +1850,9 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
      log::warn("Unable to clear RFCOMM server keep handle flag handle:{}",
                handle);
    }
    if (PORT_SetEventMask(handle, event_mask) != PORT_SUCCESS) {
      log::warn("Unable to set RFCOMM server event mask handle:{}", handle);
    }
    if (PORT_SetEventCallback(handle, bta_jv_port_event_sr_cback) !=
        PORT_SUCCESS) {
      log::warn("Unable to clear RFCOMM server event callback handle:{}",
    if (PORT_SetEventMaskAndCallback(
            handle, event_mask, bta_jv_port_event_sr_cback) != PORT_SUCCESS) {
      log::warn("Unable to set RFCOMM server event mask and callback handle:{}",
                handle);
    }
    if (PORT_GetState(handle, &port_state) != PORT_SUCCESS) {
+6 −16
Original line number Diff line number Diff line
@@ -279,30 +279,20 @@ typedef void(tPORT_MGMT_CALLBACK)(const tPORT_RESULT code,

/*******************************************************************************
 *
 * Function         PORT_SetEventMask
 * Function         PORT_SetEventMaskAndCallback
 *
 * Description      This function is called to close the specified connection.
 * Description      Set event callback the specified connection.
 *
 * Parameters:      handle       - Handle of the port returned in the Open
 *                  mask         - specifies events to be enabled.  A value
 *                                 of zero disables all events.
 *
 ******************************************************************************/
[[nodiscard]] int PORT_SetEventMask(uint16_t port_handle, uint32_t mask);

/*******************************************************************************
 *
 * Function         PORT_SetEventCallback
 *
 * Description      Set event callback the specified connection.
 *
 * Parameters:      handle       - Handle of the port returned in the Open
 *                  p_callback   - address of the callback function which should
 *                                 be called from the RFCOMM when an event
 *                                 specified in the mask occurs.
 *
 ******************************************************************************/
[[nodiscard]] int PORT_SetEventCallback(uint16_t port_handle,
[[nodiscard]] int PORT_SetEventMaskAndCallback(uint16_t port_handle,
                                               uint32_t mask,
                                               tPORT_CALLBACK* p_port_cb);

/*******************************************************************************
+3 −43
Original line number Diff line number Diff line
@@ -371,17 +371,8 @@ int RFCOMM_RemoveServer(uint16_t handle) {
  return (PORT_SUCCESS);
}

/*******************************************************************************
 *
 * Function         PORT_SetEventMask
 *
 * Description      This function is called to close the specified connection.
 *
 * Parameters:      handle     - Handle returned in the RFCOMM_CreateConnection
 *                  mask   - Bitmask of the events the host is interested in
 *
 ******************************************************************************/
int PORT_SetEventMask(uint16_t handle, uint32_t mask) {
int PORT_SetEventMaskAndCallback(uint16_t handle, uint32_t mask,
                                 tPORT_CALLBACK* p_port_cb) {
  log::verbose("PORT_SetEventMask() handle:{} mask:0x{:x}", handle, mask);
  tPORT* p_port = get_port_from_handle(handle);
  if (p_port == nullptr) {
@@ -394,42 +385,11 @@ int PORT_SetEventMask(uint16_t handle, uint32_t mask) {
  }

  p_port->ev_mask = mask;

  return (PORT_SUCCESS);
}

/*******************************************************************************
 *
 * Function         PORT_SetEventCallback
 *
 * Description      This function is called to provide an address of the
 *                  function which will be called when one of the events
 *                  specified in the mask occures.
 *
 * Parameters:      handle     - Handle returned in the RFCOMM_CreateConnection
 *                  p_callback - address of the callback function which should
 *                               be called from the RFCOMM when an event
 *                               specified in the mask occures.
 *
 *
 ******************************************************************************/
int PORT_SetEventCallback(uint16_t handle, tPORT_CALLBACK* p_port_cb) {
  tPORT* p_port = get_port_from_handle(handle);
  if (p_port == nullptr) {
    log::error("Unable to get RFCOMM port control block bad handle:{}", handle);
    return (PORT_BAD_HANDLE);
  }

  if (!p_port->in_use || (p_port->state == PORT_CONNECTION_STATE_CLOSED)) {
    return (PORT_NOT_OPENED);
  }

  log::verbose("PORT_SetEventCallback() handle:{}", handle);

  p_port->p_callback = p_port_cb;

  return (PORT_SUCCESS);
}

/*******************************************************************************
 *
 * Function         PORT_ClearKeepHandleFlag
Loading