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
meshXGenericUserPropertyServerModel Class Reference

A template class for creating Generic User Property Server models. More...

#include <meshx_model_property.hpp>

Inheritance diagram for meshXGenericUserPropertyServerModel:
meshXServerModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t > meshXModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t > meshXModelIF

Public Member Functions

meshx_err_t model_send (meshx_gen_property_send_params_t *params) override
 Send a packet to the MeshX stack based on the given parameters.
meshx_err_t model_from_ble_cb (dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
 Callback function for handling BLE mesh events for Generic User Property Server Model.
meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override
 Prepare message for element notification.
meshx_err_t element_state_change_handle (void) override
 Handle state change request from element.
 meshXGenericUserPropertyServerModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Constructor for Generic User Property Server Model.
 ~meshXGenericUserPropertyServerModel ()=default
Public Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >
 meshXServerModel (MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Construct a new Server Model.
Public Member Functions inherited from meshXModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >
void set_plat_model (MESHX_MODEL *p_model) override
 Set the platform-specific model instance.
meshx_err_t model_handle_from_ble_cb (dev_struct_t *p_dev, evt_model_id_t evt_model_id, meshx_ptr_t params)
 Handle upstream BLE Mesh events.
void on_baked (void) override
 Called when the model's parent element is baked.
virtual ~meshXModel ()
 Destructor for meshXModel.
meshx_err_t send_to_parent_element (meshx_ptr_t msg_ptr, size_t msg_size)
 Send message to parent element.
uint16_t get_model_func_id (void) const
 Get the model function identifier.
void set_model_func_id (uint16_t func_id)
 Set the model function identifier.
uint16_t get_model_id (void) const override
 Get the model identifier.
bool is_initialized (void) const override
 Check if the model is successfully initialized.
void set_model_id (uint16_t id)
 Set the model identifier.
meshx_err_t get_init_status (void) const
 Get the model initialization status.
meshXBaseGenericServerModelget_base_model (void) const
 Get the base model instance.
 meshXModel (MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, uint16_t model_func_id=0)
 Constructs a new meshXModel instance.
Public Member Functions inherited from meshXModelIF
 meshXModelIF ()
 meshXModelIF (MESHX_MODEL *p_plat_model)
virtual ~meshXModelIF ()=default
MESHX_MODEL * get_plat_model (void) const
 Get the platform-specific model instance.
meshx_ptr_t get_pub_struct (void) const
 Get the publication structures.
meshx_ptr_t get_gen_struct (void) const
 Get the generic structures.
void set_pub_struct (meshx_ptr_t pub)
 Set the publication structures.
void set_gen_struct (meshx_ptr_t gen)
 Set the generic structures.
void set_parent_element (meshXElementIF *parent)
 Set the parent element for this model.
meshXElementIFget_parent_element (void) const
 Get the parent element of this model.
void set_parent_element_state (meshx_ptr_t state)
 Set the parent element state pointer.
meshx_ptr_t get_parent_element_state (void) const
 Get the parent element state pointer.

Private Member Functions

meshx_err_t plat_model_create (MESHX_MODEL *p_plat_model_ptr=nullptr) override
 Creates and initializes a server model instance for Generic User Property Server.
meshx_err_t plat_model_delete (void) override
 Deletes the Generic User Property Server model and its associated resources.

Private Attributes

meshx_gen_property_model_state_t model_state
meshx_property_srv_el_msg_t element_msg
bool element_msg_prepared = false

Additional Inherited Members

Protected Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >
void update_element_state_change_header (meshx_err_t element_state_change, meshx_ptr_t msg_ptr) override
 Update element_state_change field in server message header.

Detailed Description

A template class for creating Generic User Property Server models.

This class is derived from meshXServerModel and provides a convenient interface for creating Generic User Property Server models. It handles the Generic User Property state change notifications from the MeshX stack and publishes the state change event to the element layer.

Constructor & Destructor Documentation

◆ meshXGenericUserPropertyServerModel()

meshXGenericUserPropertyServerModel::meshXGenericUserPropertyServerModel ( meshXElementIF * parent_element = nullptr,
meshx_ptr_t parent_element_state = nullptr,
uint16_t model_func_id = 0 )

Constructor for Generic User Property Server Model.

Parameters
[in]parent_elementPointer to the parent element (meshXElementIF)
[in]parent_element_statePointer to the parent element's state structure.
[in]model_func_idFunctional ID for the model instance.
915{}
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
meshXServerModel(MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Definition meshx_model_class.cpp:200
#define MESHX_MODEL_ID_GEN_USER_PROP_SRV
Definition meshx_ble_mesh_cmn_def.h:89

◆ ~meshXGenericUserPropertyServerModel()

meshXGenericUserPropertyServerModel::~meshXGenericUserPropertyServerModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

meshx_err_t meshXGenericUserPropertyServerModel::element_state_change_handle ( void )
overridevirtual

Handle state change request from element.

This function is called by the parent element when a state change request is received. It validates the request and returns a result to the element. Note: The actual state is maintained in the element layer, not the model layer.

Returns
  • MESHX_SUCCESS: State change handled successfully
  • MESHX_INVALID_ARG: Invalid parameter
  • MESHX_INVALID_STATE: No state change detected

Implements meshXModelIF.

878{
879 auto *el_state =
881
882 if (!el_state) {
883 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
884 return MESHX_INVALID_ARG;
885 }
886
887 if(el_state->property_id != model_state.property_id)
888 {
889 el_state->property_id = model_state.property_id;
890 }
891 if(el_state->access != model_state.access)
892 {
893 el_state->access = model_state.access;
894 }
895 // Note: property_value is a pointer and should be handled carefully
896 // The actual value management is typically done at the element level
897 return MESHX_SUCCESS;
898}
meshx_gen_property_model_state_t model_state
Definition meshx_model_property.hpp:229
meshx_ptr_t get_parent_element_state(void) const
Get the parent element state pointer.
Definition meshx_model_class.hpp:154
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
struct meshx_gen_property_model_state meshx_gen_property_model_state_t
Definition meshx_model_property.hpp:50
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34

◆ model_from_ble_cb()

meshx_err_t meshXGenericUserPropertyServerModel::model_from_ble_cb ( dev_struct_t * p_dev,
control_task_msg_evt_t model_id,
meshx_ptr_t params )
overridevirtual

Callback function for handling BLE mesh events for Generic User Property Server Model.

Parameters
[in]p_devPointer to the device structure
[in]model_idModel ID associated with the event
[in]paramsPointer to the event parameters
Returns
MESHX_SUCCESS if successful, error code otherwise

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >.

804{
805 if(!params || !p_dev)
806 {
807 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameters");
808 return MESHX_INVALID_ARG;
809 }
811 {
812 /* Callback triggered not for this model */
813 return MESHX_SUCCESS;
814 }
815
816 auto *param = static_cast<meshx_gen_srv_cb_param_t *>(params);
817
818 // Store the message in member variable for later use by prepare_element_msg
819 element_msg = {
820 .header = {
821 .model = param->model,
822 .element_state_change = MESHX_SUCCESS,
823 },
824 .state = {
825 .property_id = param->state_change.user_property_set.id,
826 .property_value = param->state_change.user_property_set.value,
827 .access = 0
828 }
829 };
830
832 return MESHX_SUCCESS;
833}
bool element_msg_prepared
Definition meshx_model_property.hpp:235
meshx_property_srv_el_msg_t element_msg
Definition meshx_model_property.hpp:232
struct meshx_gen_srv_cb_param meshx_gen_srv_cb_param_t

◆ model_send()

meshx_err_t meshXGenericUserPropertyServerModel::model_send ( meshx_gen_property_send_params_t * params)
overridevirtual

Send a packet to the MeshX stack based on the given parameters.

This function takes a pointer to a meshx_gen_property_send_params_t structure as input and sends the corresponding packet to the MeshX stack for processing.

Parameters
[in]paramsPointer to the meshx_gen_property_send_params_t structure containing the parameters
Returns
MESHX_SUCCESS on success, or an error code on failure

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >.

768{
769if (!params|| !params->model || !params->ctx)
770 {
771 return MESHX_INVALID_ARG;
772 }
774 meshx_gen_srv_state_change_t state_change = {
775 .user_property_set = {
776 .id = params->property_id,
777 .value = params->property_value
778 }
779 };
780 meshx_gen_server_send_params_t send_params = {
781 .p_model = params->model,
782 .p_ctx = params->ctx,
783 .state_change = state_change,
784 .data_len = sizeof(meshx_state_change_gen_user_property_set_t)
785 };
786 return this->get_base_model()->plat_send_msg(&send_params);
787}
meshx_err_t plat_send_msg(meshx_gen_server_send_params_t *params) override
Sends a status message for the Generic Server model.
Definition meshx_base_model_generic.cpp:401
meshXBaseGenericServerModel * get_base_model(void) const
Definition meshx_model_class.hpp:315
struct meshx_gen_server_send_params { meshx_model_t *p_model; meshx_ctx_t *p_ctx; meshx_gen_srv_state_change_t state_change; size_t data_len; } meshx_gen_server_send_params_t
Definition meshx_base_model_generic.hpp:135
#define MESHX_MODEL_OP_GEN_USER_PROPERTY_STATUS
Definition meshx_ble_mesh_cmn_def.h:326
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
meshx_ctx_t * ctx
Definition meshx_model_property.hpp:58
meshx_model_t * model
Definition meshx_model_property.hpp:57

◆ plat_model_create()

meshx_err_t meshXGenericUserPropertyServerModel::plat_model_create ( MESHX_MODEL * p_plat_model_ptr = nullptr)
overrideprivatevirtual

Creates and initializes a server model instance for Generic User Property Server.

This function handles the platform-specific model creation process for Generic User Property Server models. It initializes server-specific features and cannot be overridden by derived classes.

Returns
meshx_err_t Returns an error code indicating the result of the operation.
  • MESHX_SUCCESS on successful model creation and initialization
  • MESHX_ERR_NO_MEM if memory allocation fails
  • Other error codes for platform-specific failures
Note
This is a final function and cannot be overridden by derived classes.

Implements meshXModelIF.

933{
934 this->set_plat_model(p_plat_model_ptr);
935 meshx_ptr_t p_pub = this->get_pub_struct();
936 meshx_ptr_t p_gen = this->get_gen_struct();
938
939 err = meshx_plat_user_property_gen_srv_create(this->get_plat_model(), &p_pub, &p_gen);
940 if(err)
941 {
942 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to create Generic User Property Server Model");
943 }
944 else
945 {
946 this->set_pub_struct(p_pub);
947 this->set_gen_struct(p_gen);
948 }
949 return err;
950}
meshx_ptr_t get_pub_struct(void) const
Get the publication structures.
Definition meshx_model_class.hpp:113
MESHX_MODEL * get_plat_model(void) const
Get the platform-specific model instance.
Definition meshx_model_class.hpp:107
void set_gen_struct(meshx_ptr_t gen)
Set the generic structures.
Definition meshx_model_class.hpp:131
meshx_ptr_t get_gen_struct(void) const
Get the generic structures.
Definition meshx_model_class.hpp:119
void set_pub_struct(meshx_ptr_t pub)
Set the publication structures.
Definition meshx_model_class.hpp:125
void set_plat_model(MESHX_MODEL *p_model) override
Definition meshx_model_class.cpp:92
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_model_delete()

meshx_err_t meshXGenericUserPropertyServerModel::plat_model_delete ( void )
overrideprivatevirtual

Deletes the Generic User Property Server model and its associated resources.

This function frees the memory allocated for the Generic User Property Server and sets the pointer to NULL. It also deletes the model publication resources associated with the server.

Returns
  • MESHX_SUCCESS: Model and publication deleted successfully.
  • MESHX_FAIL: Failed to delete the model or publication.

Implements meshXModelIF.

966{
967 meshx_ptr_t p_pub = this->get_pub_struct();
968 meshx_ptr_t p_gen = this->get_gen_struct();
969
970 meshx_err_t err = meshx_plat_gen_srv_delete(&p_pub, &p_gen);
971 if (err)
972 {
973 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to delete Generic User Property Server Model");
974 }
975 else
976 {
977 this->set_pub_struct(nullptr);
978 this->set_gen_struct(nullptr);
979 }
980 return err;
981}
meshx_err_t meshx_plat_gen_srv_delete(void **p_pub, void **p_srv)
Deletes the Generic OnOff Server model and its associated resources.

◆ prepare_element_msg()

meshx_err_t meshXGenericUserPropertyServerModel::prepare_element_msg ( meshx_ptr_t * msg_ptr,
size_t * msg_size )
overridevirtual

Prepare message for element notification.

Returns pointer to the stored element message if it has been prepared

Parameters
[out]msg_ptrPointer to message structure (output parameter)
[out]msg_sizeSize of the message structure (output parameter)
Returns
MESHX_SUCCESS if message prepared successfully, error code otherwise

Implements meshXModelIF.

846{
847 if (!msg_ptr || !msg_size)
848 {
849 return MESHX_INVALID_ARG;
850 }
851
853 {
854 return MESHX_NOT_SUPPORTED;
855 }
856
857 *msg_ptr = &element_msg;
858 *msg_size = sizeof(element_msg);
859
860 return MESHX_SUCCESS;
861}
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51

Field Documentation

◆ element_msg

meshx_property_srv_el_msg_t meshXGenericUserPropertyServerModel::element_msg
private

◆ element_msg_prepared

bool meshXGenericUserPropertyServerModel::element_msg_prepared = false
private

◆ model_state

meshx_gen_property_model_state_t meshXGenericUserPropertyServerModel::model_state
private

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