Skip to content

Commit

Permalink
bluetooth: mesh: brg_cfg: use IS_ENABLED macro optimally
Browse files Browse the repository at this point in the history
If use `IS_ENABLED` macro inside if statements but not as preprocessor
directives, we can always compile the code for settings even if settings
are not used. This allows to reduce amount of firmwares we need to build
in CI to ensure that code compiles.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
  • Loading branch information
PavelVPV authored and nashif committed Sep 17, 2024
1 parent 945e320 commit dd7b675
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions subsys/bluetooth/mesh/brg_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ enum {
TABLE_UPDATED,
BRG_CFG_FLAGS_COUNT,
};
#if defined(CONFIG_BT_SETTINGS)
static ATOMIC_DEFINE(brg_cfg_flags, BRG_CFG_FLAGS_COUNT);
#endif

static void brg_tbl_compact(void)
{
Expand All @@ -48,7 +46,6 @@ static void brg_tbl_compact(void)
bt_mesh_brg_cfg_row_cnt--;
}

#if IS_ENABLED(CONFIG_BT_SETTINGS)
/* Set function for initializing bridging enable state from value stored in settings. */
static int brg_en_set(const char *name, size_t len_rd, settings_read_cb read_cb, void *cb_arg)
{
Expand Down Expand Up @@ -110,7 +107,6 @@ static int brg_tbl_set(const char *name, size_t len_rd, settings_read_cb read_cb

/* Define a setting for storing briging table rows */
BT_MESH_SETTINGS_DEFINE(brg_tbl, "brg_tbl", brg_tbl_set);
#endif

bool bt_mesh_brg_cfg_enable_get(void)
{
Expand All @@ -124,16 +120,17 @@ int bt_mesh_brg_cfg_enable_set(bool enable)
}

brg_enabled = enable;
#if IS_ENABLED(CONFIG_BT_SETTINGS)
atomic_set_bit(brg_cfg_flags, STATE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
#endif

if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(brg_cfg_flags, STATE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
}

return 0;
}

void bt_mesh_brg_cfg_pending_store(void)
{
#if CONFIG_BT_SETTINGS
char *path_en = "bt/mesh/brg_en";
char *path_tbl = "bt/mesh/brg_tbl";
int err;
Expand Down Expand Up @@ -162,7 +159,6 @@ void bt_mesh_brg_cfg_pending_store(void)
LOG_ERR("Failed to store %s value", path_tbl);
}
}
#endif
}

/* Remove the entry from the bridging table that corresponds with the NetKey Index of the removed
Expand All @@ -183,10 +179,10 @@ static void brg_tbl_netkey_removed_evt(struct bt_mesh_subnet *sub, enum bt_mesh_
}
}

#if IS_ENABLED(CONFIG_BT_SETTINGS)
atomic_set_bit(brg_cfg_flags, TABLE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
#endif
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(brg_cfg_flags, TABLE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
}
}

/* Add event hook for key deletion event */
Expand All @@ -203,15 +199,17 @@ int bt_mesh_brg_cfg_tbl_reset(void)
memset(brg_tbl, 0, sizeof(brg_tbl));
atomic_clear(brg_cfg_flags);

#if CONFIG_BT_SETTINGS
if (!IS_ENABLED(CONFIG_BT_SETTINGS)) {
return 0;
}

err = settings_delete("bt/mesh/brg_en");

if (err) {
return err;
}

err = settings_delete("bt/mesh/brg_tbl");
#endif
return err;
}

Expand Down Expand Up @@ -270,10 +268,10 @@ int bt_mesh_brg_cfg_tbl_add(enum bt_mesh_brg_cfg_dir direction, uint16_t net_idx
bt_mesh_brg_cfg_row_cnt++;

store:
#if IS_ENABLED(CONFIG_BT_SETTINGS)
atomic_set_bit(brg_cfg_flags, TABLE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
#endif
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
atomic_set_bit(brg_cfg_flags, TABLE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
}

return 0;
}
Expand All @@ -298,9 +296,8 @@ void bt_mesh_brg_cfg_tbl_foreach_subnet(uint16_t src, uint16_t dst, uint16_t net
int bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t addr1,
uint16_t addr2)
{
#if IS_ENABLED(CONFIG_BT_SETTINGS)
bool store = false;
#endif

/* Sanity checks */
if ((!BT_MESH_ADDR_IS_UNICAST(addr1) && addr1 != BT_MESH_ADDR_UNASSIGNED) ||
addr2 == BT_MESH_ADDR_ALL_NODES) {
Expand Down Expand Up @@ -331,22 +328,18 @@ int bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t ad
(addr2 == BT_MESH_ADDR_UNASSIGNED && brg_tbl[i].addr1 == addr1) ||
(addr1 == BT_MESH_ADDR_UNASSIGNED && brg_tbl[i].addr2 == addr2)) {
memset(&brg_tbl[i], 0, sizeof(brg_tbl[i]));
#if IS_ENABLED(CONFIG_BT_SETTINGS)
store = true;
#endif
}
}
}

/* Compact when all rows have been deleted. */
brg_tbl_compact();

#if IS_ENABLED(CONFIG_BT_SETTINGS)
if (store) {
if (IS_ENABLED(CONFIG_BT_SETTINGS) && store) {
atomic_set_bit(brg_cfg_flags, TABLE_UPDATED);
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
}
#endif

return 0;
}

0 comments on commit dd7b675

Please sign in to comment.