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

Commit 2d6310e2 authored by Zach Johnson's avatar Zach Johnson
Browse files

Delete bta_sys state machine, freaking finally

the only event left is hardware errors, which is
only valid when in the STARTING or ON state.

change "state" to a boolean whether we care about
hw errors or not

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ie1f73bc1343276e86d2b3da70b07adab5f54bb0d
parent 571fe10a
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -173,19 +173,10 @@ enum {
};
typedef uint8_t tBTA_SYS_HW_EVT;

/* SYS HW state */
enum {
  BTA_SYS_HW_OFF,
  BTA_SYS_HW_STARTING,
  BTA_SYS_HW_ON,
  BTA_SYS_HW_STOPPING
};
typedef uint8_t tBTA_SYS_HW_STATE;

/*****************************************************************************
 *  Function declarations
 ****************************************************************************/
void bta_sys_set_state(tBTA_SYS_HW_STATE value);
void bta_set_forward_hw_failures(bool value);

extern void bta_sys_init(void);
extern void bta_sys_free(void);
+1 −2
Original line number Diff line number Diff line
@@ -44,8 +44,7 @@ typedef struct {
typedef struct {
  tBTA_SYS_REG* reg[BTA_ID_MAX]; /* registration structures */
  bool is_reg[BTA_ID_MAX];       /* registration structures */
  tBTA_SYS_HW_STATE state;
  bool bluetooth_active;
  bool forward_hw_failures;
  uint16_t sys_features;         /* Bitmask of sys features */

  tBTA_SYS_CONN_CBACK* prm_cb; /* role management callback registered by DM */
+7 −35
Original line number Diff line number Diff line
@@ -68,7 +68,9 @@ void bta_sys_init(void) {
void bta_sys_free(void) {
}

void bta_sys_set_state(tBTA_SYS_HW_STATE value) { bta_sys_cb.state = value; }
void bta_set_forward_hw_failures(bool value) {
  bta_sys_cb.forward_hw_failures = value;
}

/*******************************************************************************
 *
@@ -81,26 +83,6 @@ void bta_sys_set_state(tBTA_SYS_HW_STATE value) { bta_sys_cb.state = value; }
 *
 ******************************************************************************/
static void bta_sys_sm_execute(tBTA_SYS_HW_EVT event) {
  APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x", bta_sys_cb.state);

  switch (bta_sys_cb.state) {
    case BTA_SYS_HW_OFF:
      switch (event) {
        default:
          break;
      }
      break;
    case BTA_SYS_HW_STARTING:
      switch (event) {
        case BTA_SYS_ERROR_EVT:
          bta_sys_set_state(BTA_SYS_HW_ON);
          bta_sys_hw_error();
          break;
        default:
          break;
      }
      break;
    case BTA_SYS_HW_ON:
  switch (event) {
    case BTA_SYS_ERROR_EVT:
      bta_sys_hw_error();
@@ -108,16 +90,6 @@ static void bta_sys_sm_execute(tBTA_SYS_HW_EVT event) {
    default:
      break;
  }
      break;
    case BTA_SYS_HW_STOPPING:
      switch (event) {
        default:
          break;
      }
      break;
    default:
      break;
  }
}

void send_bta_sys_hw_event(tBTA_SYS_HW_EVT event) {
@@ -137,7 +109,7 @@ void send_bta_sys_hw_event(tBTA_SYS_HW_EVT event) {
 ******************************************************************************/
void bta_sys_hw_error() {
  APPL_TRACE_DEBUG("%s", __func__);
  if (bta_sys_cb.bluetooth_active) {
  if (bta_sys_cb.forward_hw_failures) {
    BTA_dm_on_hw_error();
  }
}
+2 −3
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ static void event_start_up_stack(UNUSED_ATTR void* context) {
  BTA_dm_init();
  bta_dm_enable(bte_dm_evt);

  bta_sys_set_state(BTA_SYS_HW_STARTING);
  bta_set_forward_hw_failures(true);
  btm_acl_device_down();
  BTM_db_reset();
  if (bluetooth::shim::is_gd_controller_enabled()) {
@@ -240,7 +240,6 @@ static void event_start_up_stack(UNUSED_ATTR void* context) {
  }
  BTM_reset_complete();

  bta_sys_set_state(BTA_SYS_HW_ON);
  BTA_dm_on_hw_on();

  if (future_await(local_hack_future) != FUTURE_SUCCESS) {
@@ -280,7 +279,7 @@ static void event_shut_down_stack(UNUSED_ATTR void* context) {
  hack_future = local_hack_future;

  bta_sys_disable();
  bta_sys_set_state(BTA_SYS_HW_OFF);
  bta_set_forward_hw_failures(false);
  BTA_dm_on_hw_off();

  module_shut_down(get_module(BTIF_CONFIG_MODULE));