mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-07 01:30:05 +00:00
mesh: Model start callback
Replaces the Mesh model settings_commit callback with a start callback, indicating that the mesh model behavior is ready to start. Everything that was previously done in the settings_commit callback may be moved to this callback, which gets called just after mesh settings are committed, instead of in the middle of the process. This resolves an issue where models had no context in which to start their behavior, as the previous settings_commit call fired before the mesh was declared valid, making access APIs inaccessible. this is port of e86bc205a1039333a44cc84c72e7d4f7cfdc338a
This commit is contained in:
committed by
Łukasz Rymanowski
parent
77107719ca
commit
13c48e27d2
@@ -438,10 +438,10 @@ struct bt_mesh_model_cb {
|
||||
*/
|
||||
int (*const settings_set)(struct bt_mesh_model *model, char *val);
|
||||
|
||||
/** @brief Callback called when all settings have been loaded.
|
||||
/** @brief Callback called when the mesh is started.
|
||||
*
|
||||
* This handler gets called after the settings have been loaded in
|
||||
* full.
|
||||
* This handler gets called after the node has been provisioned, or
|
||||
* after all mesh data has been loaded from persistent storage.
|
||||
*
|
||||
* @sa settings_handler::h_commit
|
||||
*
|
||||
@@ -449,7 +449,7 @@ struct bt_mesh_model_cb {
|
||||
*
|
||||
* @return 0 on success, error otherwise.
|
||||
*/
|
||||
int (*const settings_commit)(struct bt_mesh_model *model);
|
||||
int (*const start)(struct bt_mesh_model *model);
|
||||
|
||||
/** @brief Model init callback.
|
||||
*
|
||||
|
||||
@@ -82,7 +82,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
|
||||
bt_mesh_store_iv(false);
|
||||
}
|
||||
|
||||
bt_mesh_net_start();
|
||||
bt_mesh_start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -359,3 +359,19 @@ int bt_mesh_init(uint8_t own_addr_type, const struct bt_mesh_prov *prov,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void model_start(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary, void *user_data)
|
||||
{
|
||||
if (mod->cb && mod->cb->start) {
|
||||
mod->cb->start(mod);
|
||||
}
|
||||
}
|
||||
|
||||
int bt_mesh_start(void)
|
||||
{
|
||||
bt_mesh_net_start();
|
||||
bt_mesh_model_foreach(model_start, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
|
||||
#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb)
|
||||
struct bt_mesh_net;
|
||||
int bt_mesh_start(void);
|
||||
|
||||
#define OP_GEN_ONOFF_GET BT_MESH_MODEL_OP_2(0x82, 0x01)
|
||||
#define OP_GEN_ONOFF_SET BT_MESH_MODEL_OP_2(0x82, 0x02)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "proxy.h"
|
||||
#include "settings.h"
|
||||
#include "nodes.h"
|
||||
#include "mesh_priv.h"
|
||||
|
||||
#include "config/config.h"
|
||||
|
||||
@@ -905,9 +906,6 @@ static void commit_mod(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
}
|
||||
}
|
||||
|
||||
if (mod->cb && mod->cb->settings_commit) {
|
||||
mod->cb->settings_commit(mod);
|
||||
}
|
||||
}
|
||||
|
||||
static int mesh_commit(void)
|
||||
@@ -967,7 +965,7 @@ static int mesh_commit(void)
|
||||
|
||||
atomic_set_bit(bt_mesh.flags, BT_MESH_VALID);
|
||||
|
||||
bt_mesh_net_start();
|
||||
bt_mesh_start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user