Bluetooth: Mesh: Add model reset callback
Adds additional model callback that gets called on node_reset. Will also erase any user data when this happens. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
91ca7ca763
commit
b7d05fbf13
|
@ -422,6 +422,15 @@ struct bt_mesh_model_cb {
|
|||
* @return 0 on success, error otherwise.
|
||||
*/
|
||||
int (*const init)(struct bt_mesh_model *model);
|
||||
|
||||
/** @brief Model reset callback.
|
||||
*
|
||||
* Called when the mesh node is reset. All model data is deleted on
|
||||
* reset, and the model should clear its state.
|
||||
*
|
||||
* @param model Model this callback belongs to.
|
||||
*/
|
||||
void (*const reset)(struct bt_mesh_model *model);
|
||||
};
|
||||
|
||||
/** Abstraction that describes a Mesh Model instance */
|
||||
|
|
|
@ -11,6 +11,7 @@ enum {
|
|||
BT_MESH_MOD_BIND_PENDING = BIT(0),
|
||||
BT_MESH_MOD_SUB_PENDING = BIT(1),
|
||||
BT_MESH_MOD_PUB_PENDING = BIT(2),
|
||||
BT_MESH_MOD_DATA_PRESENT = BIT(3),
|
||||
};
|
||||
|
||||
void bt_mesh_elem_register(struct bt_mesh_elem *elem, u8_t count);
|
||||
|
|
|
@ -3289,14 +3289,22 @@ static void mod_reset(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
|||
|
||||
/* Clear model state that isn't otherwise cleared. E.g. AppKey
|
||||
* binding and model publication is cleared as a consequence
|
||||
* of removing all app keys, however model subscription clearing
|
||||
* must be taken care of here.
|
||||
* of removing all app keys, however model subscription and user data
|
||||
* clearing must be taken care of here.
|
||||
*/
|
||||
|
||||
clear_count = mod_sub_list_clear(mod);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_SETTINGS) && clear_count) {
|
||||
bt_mesh_store_mod_sub(mod);
|
||||
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
|
||||
if (clear_count) {
|
||||
bt_mesh_store_mod_sub(mod);
|
||||
}
|
||||
|
||||
bt_mesh_model_data_store(mod, vnd, NULL, 0);
|
||||
}
|
||||
|
||||
if (mod->cb && mod->cb->reset) {
|
||||
mod->cb->reset(mod);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -660,8 +660,12 @@ static int mod_set(bool vnd, const char *name, size_t len_rd,
|
|||
return mod_set_pub(mod, len_rd, read_cb, cb_arg);
|
||||
}
|
||||
|
||||
if (!strncmp(next, "data", len) && mod->cb && mod->cb->settings_set) {
|
||||
return mod->cb->settings_set(mod, len_rd, read_cb, cb_arg);
|
||||
if (!strncmp(next, "data", len)) {
|
||||
mod->flags |= BT_MESH_MOD_DATA_PRESENT;
|
||||
|
||||
if (mod->cb && mod->cb->settings_set) {
|
||||
return mod->cb->settings_set(mod, len_rd, read_cb, cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
BT_WARN("Unknown module key %s", next);
|
||||
|
@ -1591,9 +1595,14 @@ int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd,
|
|||
encode_mod_path(mod, vnd, "data", path, sizeof(path));
|
||||
|
||||
if (data_len) {
|
||||
mod->flags |= BT_MESH_MOD_DATA_PRESENT;
|
||||
err = settings_save_one(path, data, data_len);
|
||||
} else {
|
||||
} else if (mod->flags & BT_MESH_MOD_DATA_PRESENT) {
|
||||
mod->flags &= ~BT_MESH_MOD_DATA_PRESENT;
|
||||
err = settings_delete(path);
|
||||
} else {
|
||||
/* Nothing to delete */
|
||||
err = 0;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
|
Loading…
Reference in a new issue