MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshXElement< meshx_model_send_param_header_t > Class Template Reference

Base class for MeshX elements. More...

#include <meshx_element_class.hpp>

Inheritance diagram for meshXElement< meshx_model_send_param_header_t >:
meshXElementIF

Public Member Functions

void set_element_type (meshxElementType_t type)
meshxElementType_t get_element_type (void) const final
 Get the element type.
void set_element_variant (meshx_element_type_t variant)
meshx_element_type_t get_element_variant (void) const final
 Get the element variant.
void set_no_of_sig_models (uint8_t cnt)
uint8_t get_no_of_sig_models (void) const final
 Get the number of SIG models supported by the element.
void set_no_of_ven_models (uint8_t cnt)
uint8_t get_no_of_ven_models (void) const final
 Get the number of Vendor models supported by the element.
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models (void) final
 Get the SIG models vector.
std::vector< std::unique_ptr< meshXModelIF > > & get_ven_models (void) final
 Get the Vendor models vector.
const char * get_element_name (void) const override
 Get the name of the element.
virtual uint8_t list_sig_models (void)
 Lists and creates all required SIG models for the element.
virtual uint8_t list_ven_models (void)
 Lists and creates all required Vendor models for the element.
virtual meshx_err_t element_state_change_notify (meshx_ptr_t param, size_t param_size)
 Notify element about state change.
void register_element_ctx (meshx_ptr_t ctx, size_t ctx_size)
 Register element context structure.
meshx_ptr_t get_element_ctx (void) const override
 Get the element context structure.
size_t get_element_ctx_size (void) const override
 Get the size of the element context structure.
meshx_err_t sig_plat_model_array_allocate (void)
 Allocate memory for SIG model platform array.
meshx_err_t ven_plat_model_array_allocate (void)
 Allocate memory for Vendor model platform array.
std::vector< uint8_t > & get_sig_model_array (void)
 Get the SIG model array.
std::vector< uint8_t > & get_ven_model_array (void)
 Get the Vendor model array.
template<typename meshXModelT, typename... ConstructorsArgs>
meshx_err_t add_sig_model (ConstructorsArgs &&... args)
 Add a SIG model to the element.
template<typename meshXModelT, typename... ConstructorsArgs>
meshx_err_t add_ven_model (ConstructorsArgs &&... args)
 Add a Vendor model to the element.
uint8_t get_sig_model_count (void) const
 Get the number of SIG models currently added to the element.
uint8_t get_ven_model_count (void) const
 Get the number of Vendor models currently added to the element.
meshx_err_t add_sig_models (void)
 Add multiple SIG models to the element.
meshx_err_t add_ven_models (void)
 Add multiple Vendor models to the element.
meshx_err_t add_models (void)
 Add both SIG and Vendor models to the element.
MESHX_MODEL * get_sig_plat_model_array (void)
 Get the platform model array for SIG models.
MESHX_MODEL * get_ven_plat_model_array (void)
 Get the platform model array for Vendor models.
 meshXElement (void)
 Default constructor for meshXElement.
 meshXElement (uint16_t element_idx)
 Constructor for meshXElement with element index.
 meshXElement (uint16_t element_idx, meshxElementType_t type, uint8_t no_of_sig_models, uint8_t no_of_ven_models)
 Constructor for meshXElement with element index, type, and model counts.
meshx_err_t initialize (void) override
 Initialize the element.
meshx_err_t reset (void) override
 Reset the element.
bool is_initialized (void) const override
 Check if the element is initialized.
meshx_err_t restore_nvs_context (void) override
 Restore the element's context from NVS.
bool has_model (uint16_t model_id) const override
 Check if the element contains a specific model by ID.
void on_baked (uint16_t index) override
 Called when the composition is baked to update the element's index.
 ~meshXElement () override
Public Member Functions inherited from meshXElementIF
void set_element_idx (uint16_t idx)
uint16_t get_element_idx (void) const
virtual void sync (control_task_msg_evt_t evt)=0
 Synchronize element state (Status broadcast or GET request).
virtual void handle_config (control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)=0
 Handle configuration server events (AppKey bind, Publication, etc.).
 meshXElementIF ()=delete
 meshXElementIF (uint16_t element_idx)
virtual ~meshXElementIF ()=default

Static Public Member Functions

static meshx_err_t static_prov_srv_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Server elements.
static meshx_err_t static_prov_cli_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Client elements.
static meshx_err_t static_config_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)
 Global static configuration callback.
static void register_global_callbacks (void)
 Register the global callbacks with the provisioning server.

Private Member Functions

meshx_err_t on_model_cb (meshx_ptr_t param, size_t param_size) final
 Handle model callback from child models.

Private Attributes

uint8_t no_of_sig_models
uint8_t no_of_ven_models
std::vector< uint8_t > sig_model_array
std::vector< uint8_t > ven_model_array
std::vector< std::unique_ptr< meshXModelIF > > sig_models
std::vector< std::unique_ptr< meshXModelIF > > ven_models
meshxElementType_t element_type
meshx_element_type_t element_variant
meshx_ptr_t element_ctx
size_t element_ctx_size

Detailed Description

template<typename meshx_model_send_param_header_t>
class meshXElement< meshx_model_send_param_header_t >

Base class for MeshX elements.

This is a base class for elements.

Constructor & Destructor Documentation

◆ meshXElement() [1/3]

template<typename meshx_model_send_param_header_t>
meshXElement< meshx_model_send_param_header_t >::meshXElement ( void )

Default constructor for meshXElement.

Creates an element with default parameters (index 0, no models)

◆ meshXElement() [2/3]

template<typename meshx_model_send_param_header_t>
meshXElement< meshx_model_send_param_header_t >::meshXElement ( uint16_t element_idx)
explicit

Constructor for meshXElement with element index.

Parameters
[in]element_idxIndex of the element in the mesh network
35{
36 // Register instance in global registry
38 // Register global callbacks
40}
meshXElementIF()=delete
uint16_t element_idx
Definition meshx_fwd_decl.hpp:84
void register_element(meshXElementIF *element)
Register an element instance.
Definition meshx_element_registry.hpp:43
static meshXElementRegistry & get_instance()
Definition meshx_element_registry.hpp:33
Base class for MeshX elements.
Definition meshx_element_class.hpp:34
size_t element_ctx_size
Definition meshx_element_class.hpp:48
static void register_global_callbacks(void)
Register the global callbacks with the provisioning server.
Definition meshx_element_class.cpp:502
meshx_ptr_t element_ctx
Definition meshx_element_class.hpp:47
uint8_t no_of_sig_models
Definition meshx_element_class.hpp:36
uint8_t no_of_ven_models
Definition meshx_element_class.hpp:37
meshx_element_type_t element_variant
Definition meshx_element_class.hpp:45
meshxElementType_t element_type
Definition meshx_element_class.hpp:44

◆ meshXElement() [3/3]

template<typename meshx_model_send_param_header_t>
meshXElement< meshx_model_send_param_header_t >::meshXElement ( uint16_t element_idx,
meshxElementType_t type,
uint8_t no_of_sig_models,
uint8_t no_of_ven_models )

Constructor for meshXElement with element index, type, and model counts.

Construct meshXElement with explicit element index, type, and model counts.

Parameters
[in]element_idxIndex of the element in the mesh network
[in]typeType of the element (server or client)
[in]no_of_sig_modelsNumber of SIG models supported by the element
[in]no_of_ven_modelsNumber of vendor models supported by the element

◆ ~meshXElement()

template<typename meshx_model_send_param_header_t>
meshXElement< meshx_model_send_param_header_t >::~meshXElement ( )
override
378{
380}
uint16_t get_element_idx(void) const
Definition meshx_fwd_decl.hpp:99
void unregister_element(uint16_t element_idx)
Unregister an element instance.
Definition meshx_element_registry.hpp:54

Member Function Documentation

◆ add_models()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::add_models ( void )

Add both SIG and Vendor models to the element.

This function combines the functionality of add_sig_models() and add_ven_models() to add all available models (both SIG and Vendor) to the element in a single call. It validates input parameters, checks capacity constraints for both model types, sets parent element for each model, and transfers ownership.

Returns
MESHX_SUCCESS on success, error code otherwise (MESHX_NOT_SUPPORTED, MESHX_INVALID_ARG, MESHX_NO_MEM)
235{
237
238 // Add SIG models
239
241 {
242 return sig_result;
243 }
244 // Add Vendor models
245
247 {
248 return ven_result;
249 }
250
251 // Check if at least one type of model is supported
252 if (no_of_sig_models == 0 && no_of_ven_models == 0)
253 {
254 return MESHX_NOT_SUPPORTED;
255 }
256
257 return result;
258}
meshx_err_t add_ven_models(void)
Add multiple Vendor models to the element.
Definition meshx_element_class.cpp:191
meshx_err_t add_sig_models(void)
Add multiple SIG models to the element.
Definition meshx_element_class.cpp:128

◆ add_sig_model()

template<typename meshx_model_send_param_header_t>
template<typename meshXModelT, typename... ConstructorsArgs>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::add_sig_model ( ConstructorsArgs &&... args)

Add a SIG model to the element.

Template Parameters
meshXModelTType of the model to add
ConstructorsArgsVariadic template parameter pack for constructor arguments

This function adds a SIG model to the element using perfect forwarding. It validates the model type, checks capacity constraints, and transfers ownership.

Parameters
[in]argsConstructor arguments for the model
Returns
MESHX_SUCCESS on success, error code otherwise
110{
112 "meshXModelT must be derived from meshXModelIF");
113
114 if(no_of_sig_models == 0)
115 {
116 return MESHX_NOT_SUPPORTED;
117 }
118 if (sig_models.size() >= no_of_sig_models)
119 {
120 return MESHX_NO_MEM;
121 }
123 return MESHX_SUCCESS;
124}
std::vector< std::unique_ptr< meshXModelIF > > sig_models
Definition meshx_element_class.hpp:42

◆ add_sig_models()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::add_sig_models ( void )

Add multiple SIG models to the element.

This function allows adding multiple SIG models at once to the element. It accepts a vector of unique_ptr to meshXModelIF objects. The function validates input parameters, checks capacity constraints, sets parent element for each model, and transfers ownership.

Returns
MESHX_SUCCESS on success, MESHX_NOT_SUPPORTED if no SIG models supported, MESHX_INVALID_ARG if input vector is empty or contains null pointers, MESHX_NO_MEM if adding models would exceed capacity
129{
131
132 if(no_of_sig_models == 0)
133 {
134 return MESHX_NOT_SUPPORTED;
135 }
136
137 if (models.empty())
138 {
139 return MESHX_INVALID_STATE;
140 }
141
142 if ((sig_models.size() + models.size()) > no_of_sig_models)
143 {
144 return MESHX_NO_MEM;
145 }
146
147 uint8_t index = 0;
148 for (auto& model : models)
149 {
150 if (model == nullptr)
151 {
152 return MESHX_INVALID_ARG;
153 }
154
155 // Set the platform model for the model
156 model->set_plat_model(reinterpret_cast<MESHX_MODEL*>(&this->sig_model_array[index * sizeof(MESHX_MODEL)]));
157 // Set the parent element for the model
158 model->set_parent_element(this);
159
160 // Add the model to the sig_models vector
161 // Since sig_models is a vector of unique_ptr, we need to transfer ownership
162 sig_models.emplace_back(std::move(model));
163 index++;
164 }
165
166 return MESHX_SUCCESS;
167}
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models(void) final
Get the SIG models vector.
Definition meshx_element_class.hpp:78
std::vector< uint8_t > sig_model_array
Definition meshx_element_class.hpp:39

◆ add_ven_model()

template<typename meshx_model_send_param_header_t>
template<typename meshXModelT, typename... ConstructorsArgs>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::add_ven_model ( ConstructorsArgs &&... args)

Add a Vendor model to the element.

Template Parameters
meshXModelTType of the model to add
ConstructorsArgsVariadic template parameter pack for constructor arguments

This function adds a Vendor model to the element using perfect forwarding. It validates the model type, checks capacity constraints, and transfers ownership.

Parameters
[in]argsConstructor arguments for the model
Returns
MESHX_SUCCESS on success, error code otherwise
173{
175 "meshXModelT must be derived from meshXModelIF");
176 if(no_of_ven_models == 0)
177 {
178 return MESHX_NOT_SUPPORTED;
179 }
180
181 if (ven_models.size() >= no_of_ven_models)
182 {
183 return MESHX_NO_MEM;
184 }
186 return MESHX_SUCCESS;
187}
std::vector< std::unique_ptr< meshXModelIF > > ven_models
Definition meshx_element_class.hpp:43

◆ add_ven_models()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::add_ven_models ( void )

Add multiple Vendor models to the element.

This function allows adding multiple Vendor models at once to the element. It accepts a vector of unique_ptr to meshXModelIF objects. The function validates input parameters, checks capacity constraints, sets parent element for each model, and transfers ownership.

Returns
MESHX_SUCCESS on success, MESHX_NOT_SUPPORTED if no Vendor models supported, MESHX_INVALID_ARG if input vector is empty or contains null pointers, MESHX_NO_MEM if adding models would exceed capacity
192{
194
195 if(no_of_ven_models == 0)
196 {
197 return MESHX_NOT_SUPPORTED;
198 }
199
200 if (models.empty())
201 {
202 return MESHX_INVALID_STATE;
203 }
204
205 if ((ven_models.size() + models.size()) > no_of_ven_models)
206 {
207 return MESHX_NO_MEM;
208 }
209
210 uint8_t index = 0;
211 for (auto& model : models)
212 {
213 if (model == nullptr)
214 {
215 return MESHX_INVALID_ARG;
216 }
217
218 // Set the platform model for the model
219 model->set_plat_model(reinterpret_cast<MESHX_MODEL*>(&this->ven_model_array[index * sizeof(MESHX_MODEL)]));
220 // Set the parent element for the model
221 model->set_parent_element(this);
222
223 // Add the model to the ven_models vector
224 // Since ven_models is a vector of unique_ptr, we need to transfer ownership
225 ven_models.emplace_back(std::move(model));
226 index++;
227 }
228
229 return MESHX_SUCCESS;
230}
std::vector< uint8_t > ven_model_array
Definition meshx_element_class.hpp:40
std::vector< std::unique_ptr< meshXModelIF > > & get_ven_models(void) final
Get the Vendor models vector.
Definition meshx_element_class.hpp:79

◆ element_state_change_notify()

template<typename meshx_model_send_param_header_t>
virtual meshx_err_t meshXElement< meshx_model_send_param_header_t >::element_state_change_notify ( meshx_ptr_t param,
size_t param_size )
inlinevirtual

Notify element about state change.

Note
This function shall be derived by the specific element class to handle state change notifications from child models (if required).
Parameters
[in]paramPointer to the state change parameter
[in]param_sizeSize of the parameter structure
Returns
MESHX_SUCCESS on success, error code otherwise

Reimplemented in meshXCWWWClientElement, meshXCWWWServerElement, meshXRelayClientElement, meshXRelayServerElement, meshXRGBServerElement, meshXRootElement, and meshXSensorElement.

119 {
120 /* If not derived, return success */
121 return MESHX_SUCCESS;
122 }

◆ get_element_ctx()

template<typename meshx_model_send_param_header_t>
meshx_ptr_t meshXElement< meshx_model_send_param_header_t >::get_element_ctx ( void ) const
inlineoverridevirtual

Get the element context structure.

Returns
Pointer to the element context structure

Implements meshXElementIF.

141{ return element_ctx; }

◆ get_element_ctx_size()

template<typename meshx_model_send_param_header_t>
size_t meshXElement< meshx_model_send_param_header_t >::get_element_ctx_size ( void ) const
inlineoverridevirtual

Get the size of the element context structure.

Returns
Size of the element context structure

Implements meshXElementIF.

146{ return element_ctx_size; }

◆ get_element_name()

template<typename meshx_model_send_param_header_t>
const char * meshXElement< meshx_model_send_param_header_t >::get_element_name ( void ) const
overridevirtual

Get the name of the element.

Returns
String literal representing the element name.

Implements meshXElementIF.

Reimplemented in meshXRelayClientElement, meshXRelayServerElement, meshXRGBServerElement, meshXRootElement, and meshXSensorElement.

99{
100 return "Unknown Element";
101}

◆ get_element_type()

template<typename meshx_model_send_param_header_t>
meshxElementType_t meshXElement< meshx_model_send_param_header_t >::get_element_type ( void ) const
inlinefinalvirtual

Get the element type.

Returns
Element type (server or client)

Implements meshXElementIF.

67{ return element_type; }

◆ get_element_variant()

template<typename meshx_model_send_param_header_t>
meshx_element_type_t meshXElement< meshx_model_send_param_header_t >::get_element_variant ( void ) const
inlinefinalvirtual

Get the element variant.

Returns
Element variant (meshx_element_type_t)

Implements meshXElementIF.

70{ return element_variant; }

◆ get_no_of_sig_models()

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::get_no_of_sig_models ( void ) const
inlinefinalvirtual

Get the number of SIG models supported by the element.

Returns
Number of SIG models

Implements meshXElementIF.

73{ return no_of_sig_models; }

◆ get_no_of_ven_models()

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::get_no_of_ven_models ( void ) const
inlinefinalvirtual

Get the number of Vendor models supported by the element.

Returns
Number of Vendor models

Implements meshXElementIF.

76{ return no_of_ven_models; }

◆ get_sig_model_array()

template<typename meshx_model_send_param_header_t>
std::vector< uint8_t > & meshXElement< meshx_model_send_param_header_t >::get_sig_model_array ( void )
inline

Get the SIG model array.

Returns
Reference to the SIG model array
172{ return sig_model_array; }

◆ get_sig_model_count()

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::get_sig_model_count ( void ) const
inline

Get the number of SIG models currently added to the element.

Returns
Number of SIG models in the element
212{ return sig_models.size(); }

◆ get_sig_models()

template<typename meshx_model_send_param_header_t>
std::vector< std::unique_ptr< meshXModelIF > > & meshXElement< meshx_model_send_param_header_t >::get_sig_models ( void )
inlinefinalvirtual

Get the SIG models vector.

Returns
Reference to the SIG models vector

Implements meshXElementIF.

78{ return sig_models; }

◆ get_sig_plat_model_array()

template<typename meshx_model_send_param_header_t>
MESHX_MODEL * meshXElement< meshx_model_send_param_header_t >::get_sig_plat_model_array ( void )

Get the platform model array for SIG models.

Returns
Pointer to the SIG model array
85{
86 return sig_model_array.empty() ? nullptr : reinterpret_cast<MESHX_MODEL*>(sig_model_array.data());
87}

◆ get_ven_model_array()

template<typename meshx_model_send_param_header_t>
std::vector< uint8_t > & meshXElement< meshx_model_send_param_header_t >::get_ven_model_array ( void )
inline

Get the Vendor model array.

Returns
Reference to the Vendor model array
178{ return ven_model_array; }

◆ get_ven_model_count()

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::get_ven_model_count ( void ) const
inline

Get the number of Vendor models currently added to the element.

Returns
Number of Vendor models in the element
218{ return ven_models.size(); }

◆ get_ven_models()

template<typename meshx_model_send_param_header_t>
std::vector< std::unique_ptr< meshXModelIF > > & meshXElement< meshx_model_send_param_header_t >::get_ven_models ( void )
inlinefinalvirtual

Get the Vendor models vector.

Returns
Reference to the Vendor models vector

Implements meshXElementIF.

79{ return ven_models; }

◆ get_ven_plat_model_array()

template<typename meshx_model_send_param_header_t>
MESHX_MODEL * meshXElement< meshx_model_send_param_header_t >::get_ven_plat_model_array ( void )

Get the platform model array for Vendor models.

Returns
Pointer to the Vendor model array
92{
93 return ven_model_array.empty() ? nullptr : reinterpret_cast<MESHX_MODEL*>(ven_model_array.data());
94}

◆ has_model()

template<typename meshx_model_send_param_header_t>
bool meshXElement< meshx_model_send_param_header_t >::has_model ( uint16_t model_id) const
overridevirtual

Check if the element contains a specific model by ID.

Parameters
model_idThe model ID to check for
Returns
true if the model exists in this element, false otherwise

Implements meshXElementIF.

385{
386 // Check SIG models
387 for (const auto& m : sig_models) {
388 if (m && m->get_model_id() == model_id) return true;
389 }
390
391 // Check Vendor models
392 for (const auto& m : ven_models) {
393 if (m && m->get_model_id() == model_id) return true;
394 }
395
396 return false;
397}

◆ initialize()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::initialize ( void )
overridevirtual

Initialize the element.

Returns
MESHX_SUCCESS on success, error code otherwise

Implements meshXElementIF.

315{
316 /* Restoration from NVS should happen before model initialization if needed */
317 this->restore_nvs_context();
318
319 /*
320 * If platform model pointers are already set (e.g. by meshx_composition_bake),
321 * we skip re-allocation and re-adding to maintain pointer stability.
322 */
323 bool already_initialized = false;
324 if (!this->get_sig_models().empty() && this->get_sig_models()[0]->get_plat_model() != nullptr) {
325 already_initialized = true;
326 }
327
328 if (!already_initialized) {
331
334
337
338 /* Add all models to the element (this populates the platform model pointers) */
339 this->add_models();
340 } else {
341 MESHX_LOGI(MODULE_ID_BLE_MESH_ELEMENT, "Element %d already has platform pointers set, skipping re-init", get_element_idx());
342 }
343
344 return MESHX_SUCCESS;
345}
meshx_err_t restore_nvs_context(void) override
Restore the element's context from NVS.
Definition meshx_element_class.cpp:365
virtual uint8_t list_sig_models(void)
Lists and creates all required SIG models for the element.
Definition meshx_element_class.hpp:94
void set_no_of_sig_models(uint8_t cnt)
Definition meshx_element_class.hpp:72
virtual uint8_t list_ven_models(void)
Lists and creates all required Vendor models for the element.
Definition meshx_element_class.hpp:106
meshx_err_t ven_plat_model_array_allocate(void)
Allocate memory for Vendor model platform array.
Definition meshx_element_class.cpp:72
void set_no_of_ven_models(uint8_t cnt)
Definition meshx_element_class.hpp:75
meshx_err_t add_models(void)
Add both SIG and Vendor models to the element.
Definition meshx_element_class.cpp:234
meshx_err_t sig_plat_model_array_allocate(void)
Allocate memory for SIG model platform array.
Definition meshx_element_class.cpp:60
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126

◆ is_initialized()

template<typename meshx_model_send_param_header_t>
bool meshXElement< meshx_model_send_param_header_t >::is_initialized ( void ) const
overridevirtual

Check if the element is initialized.

Returns
true if initialized, false otherwise

Implements meshXElementIF.

358{
359 /* Default: always report initialized */
360 return true;
361}

◆ list_sig_models()

template<typename meshx_model_send_param_header_t>
virtual uint8_t meshXElement< meshx_model_send_param_header_t >::list_sig_models ( void )
inlinevirtual

Lists and creates all required SIG models for the element.

This function is responsible for creating and populating the sig_models vector with all essential SIG models that the element must have.

The function can be extended to include additional models based on configuration flags or specific requirements.

Returns
uint8_t The total number of SIG models created and added to the root_sig_models vector

Implements meshXElementIF.

Reimplemented in meshXCWWWClientElement, meshXCWWWServerElement, meshXRelayClientElement, meshXRelayServerElement, meshXRGBServerElement, meshXRootElement, and meshXSensorElement.

94{ return 0; };

◆ list_ven_models()

template<typename meshx_model_send_param_header_t>
virtual uint8_t meshXElement< meshx_model_send_param_header_t >::list_ven_models ( void )
inlinevirtual

Lists and creates all required Vendor models for the element.

This function is responsible for creating and populating the ven_models vector with all essential Vendor models that the element must have.

The function can be extended to include additional models based on configuration flags or specific requirements.

Returns
uint8_t The total number of Vendor models created and added to the root_sig_models vector

Implements meshXElementIF.

Reimplemented in meshXCWWWClientElement, meshXCWWWServerElement, meshXRelayClientElement, meshXRelayServerElement, meshXRGBServerElement, meshXRootElement, and meshXSensorElement.

106{ return 0; };

◆ on_baked()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::on_baked ( uint16_t index)
inlineoverridevirtual

Called when the composition is baked to update the element's index.

Parameters
indexThe final platform index of this element.

Implements meshXElementIF.

318 {
319 this->set_element_idx(index);
320 for (auto& m : sig_models) m->on_baked();
321 for (auto& m : ven_models) m->on_baked();
322 }
void set_element_idx(uint16_t idx)
Definition meshx_fwd_decl.hpp:98
void on_baked(uint16_t index) override
Called when the composition is baked to update the element's index.
Definition meshx_element_class.hpp:318

◆ on_model_cb()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::on_model_cb ( meshx_ptr_t param,
size_t param_size )
finalprivatevirtual

Handle model callback from child models.

This function is called by child models when a state change occurs. It handles the state change by storing in element context, saving to NVS, and notifying the application.

Parameters
[in]paramPointer to the model callback parameter
[in]param_sizeSize of the parameter structure
Returns
  • MESHX_SUCCESS: State change handled successfully
  • MESHX_INVALID_ARG: Invalid parameter

Implements meshXElementIF.

266{
267 if (param == nullptr)
268 {
269 MESHX_LOGE(MODULE_ID_COMMON, "Invalid parameter in on_model_cb");
270 return MESHX_INVALID_ARG;
271 }
273
274 auto *msg_header = static_cast<meshx_model_send_param_header_t *>(param);
275
276 if(!msg_header)
277 {
278 MESHX_LOGE(MODULE_ID_COMMON, "Invalid message header in on_model_cb");
279 return MESHX_INVALID_ARG;
280 }
281
282 if(msg_header->element_state_change == MESHX_SUCCESS)
283 {
284 /* Notify the element of the state change to derived class (if defined) */
286 if(err != MESHX_SUCCESS)
287 {
288 MESHX_LOGE(MODULE_ID_COMMON, "Element state change notify failed in on_model_cb");
289 return err;
290 }
291
292 /* Save updated context to NVS if it exists */
293 if (element_ctx && element_ctx_size > 0)
294 {
296 if(err)
297 {
298 MESHX_LOGE(MODULE_ID_BLE_MESH_ELEMENT, "meshx_nvs_element_ctx_set failed: %d", err);
299 }
300 }
301 }
302
303 return err;
304}
virtual meshx_err_t element_state_change_notify(meshx_ptr_t param, size_t param_size)
Notify element about state change.
Definition meshx_element_class.hpp:118
meshx_element_type_t get_element_variant(void) const final
Get the element variant.
Definition meshx_element_class.hpp:70
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
meshx_err_t meshx_nvs_element_ctx_set(uint16_t element_id, meshx_element_type_t element_type, const void *blob, size_t blob_size)
Store the context of a specific element to NVS.
Definition meshx_nvs.c:466

◆ register_element_ctx()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::register_element_ctx ( meshx_ptr_t ctx,
size_t ctx_size )
inline

Register element context structure.

This function registers the element context structure used to maintain state information for the element.

Parameters
[in]ctxPointer to the element context structure
[in]ctx_sizeSize of the context structure
133 {
136 }

◆ register_global_callbacks()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::register_global_callbacks ( void )
static

Register the global callbacks with the provisioning server.

503{
506#if CONFIG_ENABLE_CONFIG_SERVER
508#endif
509#if CONFIG_ENABLE_PROVISIONING
512#endif
513 });
514}
static meshx_err_t static_prov_srv_cb(const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
Global static provisioning callback for Server elements.
Definition meshx_element_class.cpp:406
static meshx_err_t static_config_cb(const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)
Global static configuration callback.
Definition meshx_element_class.cpp:442
static meshx_err_t static_prov_cli_cb(const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
Global static provisioning callback for Client elements.
Definition meshx_element_class.cpp:424
meshx_err_t meshx_config_server_cb_reg(config_srv_cb_t cb, uint32_t config_evt_bmap)
Definition meshx_model_config.cpp:296
meshx_err_t meshx_prov_srv_reg_el_client_cb(prov_srv_cb_t cb)
Register a callback function for provisioning events.
Definition meshx_prov_srv.cpp:283
meshx_err_t meshx_prov_srv_reg_el_server_cb(prov_srv_cb_t cb)
Register a callback function for provisioning events.
Definition meshx_prov_srv.cpp:292

◆ reset()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::reset ( void )
overridevirtual

Reset the element.

Returns
MESHX_SUCCESS on success, error code otherwise

Implements meshXElementIF.

350{
351 /* Default: reset is a no-op */
352 return MESHX_SUCCESS;
353}

◆ restore_nvs_context()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::restore_nvs_context ( void )
overridevirtual

Restore the element's context from NVS.

Returns
MESHX_SUCCESS on success, error code otherwise.

Implements meshXElementIF.

366{
367 if (element_ctx && element_ctx_size > 0)
368 {
370 }
371 return MESHX_SUCCESS;
372}
meshx_err_t meshx_nvs_element_ctx_get(uint16_t element_id, meshx_element_type_t element_type, void *blob, size_t blob_size)
Retrieve the context of a specific element from NVS.
Definition meshx_nvs.c:447

◆ set_element_type()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::set_element_type ( meshxElementType_t type)
inline
66{ element_type = type; }

◆ set_element_variant()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::set_element_variant ( meshx_element_type_t variant)
inline

◆ set_no_of_sig_models()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::set_no_of_sig_models ( uint8_t cnt)
inline

◆ set_no_of_ven_models()

template<typename meshx_model_send_param_header_t>
void meshXElement< meshx_model_send_param_header_t >::set_no_of_ven_models ( uint8_t cnt)
inline

◆ sig_plat_model_array_allocate()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::sig_plat_model_array_allocate ( void )

Allocate memory for SIG model platform array.

This function allocates memory for the SIG model platform array based on the number of SIG models supported by the element. It reserves capacity for the specified number of models.

Returns
MESHX_SUCCESS on success, MESHX_NOT_SUPPORTED if no SIG models supported
61{
62 if (no_of_sig_models > 0)
63 {
65 return MESHX_SUCCESS;
66 }
68}

◆ static_config_cb()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::static_config_cb ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const meshx_config_srv_cb_param_t * params )
static

Global static configuration callback.

443{
445 if (!params) return MESHX_INVALID_ARG;
446
448
450 {
451 element_addr = params->state_change.mod_app_bind.element_addr;
452 }
454 {
455 element_addr = params->state_change.mod_pub_set.element_addr;
456 }
457 else
458 {
459 return MESHX_SUCCESS; // Not an event we handle context for directly
460 }
461
462 // Find element by address (abs_id)
464 if (el)
465 {
466 // Update common context first (pattern matching)
467 auto *ctx = static_cast<meshx_element_common_ctx_t *>(el->get_element_ctx());
468 if (ctx)
469 {
470 bool save = false;
472 {
473 ctx->app_id = params->state_change.mod_app_bind.app_idx;
474 save = true;
475 }
477 {
479 ctx->pub_addr = params->state_change.mod_pub_set.pub_addr;
480 ctx->app_id = params->state_change.mod_pub_set.app_idx;
481 } else {
482 ctx->pub_addr = MESHX_ADDR_UNASSIGNED;
483 }
484 save = true;
485 }
486
487 if (save)
488 {
491 }
492 }
493
494 // Notify element for any specialized handling
496 }
497 return MESHX_SUCCESS;
498}
virtual void handle_config(control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)=0
Handle configuration server events (AppKey bind, Publication, etc.).
meshXElementIF * find_element(uint16_t element_idx)
Find an element instance by its index.
Definition meshx_element_registry.hpp:65
size_t get_element_ctx_size(void) const override
Get the size of the element context structure.
Definition meshx_element_class.hpp:146
meshx_ptr_t get_element_ctx(void) const override
Get the element context structure.
Definition meshx_element_class.hpp:141
#define MESHX_UNUSED(x)
Definition meshx_err.h:19

◆ static_prov_cli_cb()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::static_prov_cli_cb ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const void * params )
static

Global static provisioning callback for Client elements.

425{
427
428 // Iterate through all elements and call sync only for client elements
430 for (auto const& [abs_id, base_el] : elements)
431 {
433 {
434 base_el->sync(evt);
435 }
436 }
437 return MESHX_SUCCESS;
438}
virtual void sync(control_task_msg_evt_t evt)=0
Synchronize element state (Status broadcast or GET request).
std::map< uint16_t, meshXElementIF * > get_all_elements()
Get all registered elements.
Definition meshx_element_registry.hpp:98
meshxElementType_t get_element_type(void) const final
Get the element type.
Definition meshx_element_class.hpp:67

◆ static_prov_srv_cb()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::static_prov_srv_cb ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const void * params )
static

Global static provisioning callback for Server elements.

407{
409
410 // Iterate through all elements and call sync only for server elements
412 for (auto const& [abs_id, base_el] : elements)
413 {
415 {
416 base_el->sync(evt);
417 }
418 }
419 return MESHX_SUCCESS;
420}

◆ ven_plat_model_array_allocate()

template<typename meshx_model_send_param_header_t>
meshx_err_t meshXElement< meshx_model_send_param_header_t >::ven_plat_model_array_allocate ( void )

Allocate memory for Vendor model platform array.

This function allocates memory for the Vendor model platform array based on the number of Vendor models supported by the element. It reserves capacity for the specified number of models.

Returns
MESHX_SUCCESS on success, MESHX_NOT_SUPPORTED if no Vendor models supported
73{
74 if (no_of_ven_models > 0)
75 {
77 return MESHX_SUCCESS;
78 }
80}

Field Documentation

◆ element_ctx

template<typename meshx_model_send_param_header_t>
meshx_ptr_t meshXElement< meshx_model_send_param_header_t >::element_ctx
private

Pointer to element context structure

◆ element_ctx_size

template<typename meshx_model_send_param_header_t>
size_t meshXElement< meshx_model_send_param_header_t >::element_ctx_size
private

Size of the element context structure

◆ element_type

template<typename meshx_model_send_param_header_t>
meshxElementType_t meshXElement< meshx_model_send_param_header_t >::element_type
private

◆ element_variant

template<typename meshx_model_send_param_header_t>
meshx_element_type_t meshXElement< meshx_model_send_param_header_t >::element_variant
private

◆ no_of_sig_models

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::no_of_sig_models
private

◆ no_of_ven_models

template<typename meshx_model_send_param_header_t>
uint8_t meshXElement< meshx_model_send_param_header_t >::no_of_ven_models
private

◆ sig_model_array

template<typename meshx_model_send_param_header_t>
std::vector<uint8_t> meshXElement< meshx_model_send_param_header_t >::sig_model_array
private

◆ sig_models

template<typename meshx_model_send_param_header_t>
std::vector<std::unique_ptr<meshXModelIF> > meshXElement< meshx_model_send_param_header_t >::sig_models
private

◆ ven_model_array

template<typename meshx_model_send_param_header_t>
std::vector<uint8_t> meshXElement< meshx_model_send_param_header_t >::ven_model_array
private

◆ ven_models

template<typename meshx_model_send_param_header_t>
std::vector<std::unique_ptr<meshXModelIF> > meshXElement< meshx_model_send_param_header_t >::ven_models
private

The documentation for this class was generated from the following files: