Bluetooth: host: Use switch statement in bt_conn_set_state
Refactor old state handling in bt_conn_set_state to use switch statement instead of if statements. This will give us warning about enum values not covered. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
f19b7a6e69
commit
564ba1a07b
1 changed files with 18 additions and 7 deletions
|
@ -1678,8 +1678,9 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
* up and stop the tx thread for states where it was
|
* up and stop the tx thread for states where it was
|
||||||
* running.
|
* running.
|
||||||
*/
|
*/
|
||||||
if (old_state == BT_CONN_CONNECTED ||
|
switch (old_state) {
|
||||||
old_state == BT_CONN_DISCONNECT) {
|
case BT_CONN_CONNECTED:
|
||||||
|
case BT_CONN_DISCONNECT:
|
||||||
process_unack_tx(conn);
|
process_unack_tx(conn);
|
||||||
tx_notify(conn);
|
tx_notify(conn);
|
||||||
|
|
||||||
|
@ -1691,7 +1692,8 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
atomic_set_bit(conn->flags, BT_CONN_CLEANUP);
|
atomic_set_bit(conn->flags, BT_CONN_CLEANUP);
|
||||||
k_poll_signal_raise(&conn_change, 0);
|
k_poll_signal_raise(&conn_change, 0);
|
||||||
/* The last ref will be dropped during cleanup */
|
/* The last ref will be dropped during cleanup */
|
||||||
} else if (old_state == BT_CONN_CONNECT) {
|
break;
|
||||||
|
case BT_CONN_CONNECT:
|
||||||
/* LE Create Connection command failed. This might be
|
/* LE Create Connection command failed. This might be
|
||||||
* directly from the API, don't notify application in
|
* directly from the API, don't notify application in
|
||||||
* this case.
|
* this case.
|
||||||
|
@ -1699,8 +1701,10 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
if (conn->err) {
|
if (conn->err) {
|
||||||
notify_connected(conn);
|
notify_connected(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
} else if (old_state == BT_CONN_CONNECT_SCAN) {
|
break;
|
||||||
|
case BT_CONN_CONNECT_SCAN:
|
||||||
/* this indicate LE Create Connection with peer address
|
/* this indicate LE Create Connection with peer address
|
||||||
* has been stopped. This could either be triggered by
|
* has been stopped. This could either be triggered by
|
||||||
* the application through bt_conn_disconnect or by
|
* the application through bt_conn_disconnect or by
|
||||||
|
@ -1711,24 +1715,31 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
} else if (old_state == BT_CONN_CONNECT_DIR_ADV) {
|
break;
|
||||||
|
case BT_CONN_CONNECT_DIR_ADV:
|
||||||
/* this indicate Directed advertising stopped */
|
/* this indicate Directed advertising stopped */
|
||||||
if (conn->err) {
|
if (conn->err) {
|
||||||
notify_connected(conn);
|
notify_connected(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
} else if (old_state == BT_CONN_CONNECT_AUTO) {
|
break;
|
||||||
|
case BT_CONN_CONNECT_AUTO:
|
||||||
/* this indicates LE Create Connection with filter
|
/* this indicates LE Create Connection with filter
|
||||||
* policy has been stopped. This can only be triggered
|
* policy has been stopped. This can only be triggered
|
||||||
* by the application, so don't notify.
|
* by the application, so don't notify.
|
||||||
*/
|
*/
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
} else if (old_state == BT_CONN_CONNECT_ADV) {
|
break;
|
||||||
|
case BT_CONN_CONNECT_ADV:
|
||||||
/* This can only happen when application stops the
|
/* This can only happen when application stops the
|
||||||
* advertiser, conn->err is never set in this case.
|
* advertiser, conn->err is never set in this case.
|
||||||
*/
|
*/
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
break;
|
||||||
|
case BT_CONN_DISCONNECTED:
|
||||||
|
/* Cannot happen, no transition. */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BT_CONN_CONNECT_AUTO:
|
case BT_CONN_CONNECT_AUTO:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue