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
meshXBaseModel< ble_mesh_send_msg_params_t > Class Template Referenceabstract

Base class for all mesh models. More...

#include <meshx_base_model_class.hpp>

Inheritance diagram for meshXBaseModel< ble_mesh_send_msg_params_t >:
meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t > meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >

Data Structures

struct  reg_info

Public Member Functions

meshx_err_t from_ble_reg_cb (void) const
 Register BLE message callback for this model.
virtual meshx_err_t plat_model_init (void)=0
 Initialize platform model.
virtual meshx_err_t plat_send_msg (ble_mesh_send_msg_params_t *params)=0
 Send message through the model.
meshx_err_t get_status (void) const
 Get the current status of the model.
uint32_t get_model_id (void) const
 Get the model identifier.
control_task_msg_handle_t get_from_ble_cb (void) const
 Get the BLE message callback function.
meshXBaseModelType_t get_model_type (void) const
 Get the model type (server/client).
void set_status (meshx_err_t err)
 Set the model status.
void set_model_id (uint32_t id)
 Set the model identifier.
void set_from_ble_cb (control_task_msg_handle_t cb)
 Set the BLE message callback function.
void set_model_type (meshXBaseModelType_t type)
 Set the model type.
 meshXBaseModel (uint32_t model_id, control_task_msg_handle_t from_ble_cb, meshXBaseModelType_t model_type)
 Construct a new meshXBaseModel object.
 meshXBaseModel ()=delete
virtual ~meshXBaseModel ()
 Virtual destructor for meshXBaseModel.

Protected Member Functions

virtual meshx_err_t from_ble_dereg_cb (void) const
 Deregister BLE message callback for this model.

Protected Attributes

uint32_t model_id
meshXBaseModelType_t model_type
control_task_msg_handle_t from_ble_cb
meshx_err_t status = MESHX_SUCCESS

Static Private Attributes

static std::forward_list< reg_inforegistrations

Detailed Description

template<typename ble_mesh_send_msg_params_t>
class meshXBaseModel< ble_mesh_send_msg_params_t >

Base class for all mesh models.

This class serves as the foundation for all MeshX models, providing common functionality and interfaces for both client and server models.

Template Parameters
meshXBaseTTemplate parameter for base model customization. This should be a derived class that implements platform-specific behavior.
ble_mesh_send_msg_params_tBLE mesh message parameters type. This type defines the structure used for sending BLE mesh messages.
Note
This is an abstract base class that cannot be instantiated directly. Use meshXBaseServerModel or meshXBaseClientModel instead.

Constructor & Destructor Documentation

◆ meshXBaseModel() [1/2]

template<typename ble_mesh_send_msg_params_t>
meshXBaseModel< ble_mesh_send_msg_params_t >::meshXBaseModel ( uint32_t model_id,
control_task_msg_handle_t from_ble_cb,
meshXBaseModelType_t model_type )

Construct a new meshXBaseModel object.

Parameters
[in]model_idModel identifier
[in]from_ble_cbCallback for handling BLE messages
[in]model_typeType of the model (server/client)
46{
47 if(from_ble_cb == nullptr)
48 {
49 MESHX_LOGE(MODULE_ID_COMMON, "from_ble_cb is NULL");
51 return;
52 }
53 // Callback registration is deferred to meshx_composition to avoid early-boot race conditions
55}
Base class for all mesh models.
Definition meshx_base_model_class.hpp:50
meshx_err_t status
Definition meshx_base_model_class.hpp:55
uint32_t model_id
Definition meshx_base_model_class.hpp:52
meshXBaseModelType_t model_type
Definition meshx_base_model_class.hpp:53
control_task_msg_handle_t from_ble_cb
Definition meshx_base_model_class.hpp:54
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114

◆ meshXBaseModel() [2/2]

template<typename ble_mesh_send_msg_params_t>
meshXBaseModel< ble_mesh_send_msg_params_t >::meshXBaseModel ( )
delete

◆ ~meshXBaseModel()

template<typename ble_mesh_send_msg_params_t>
meshXBaseModel< ble_mesh_send_msg_params_t >::~meshXBaseModel ( )
virtual

Virtual destructor for meshXBaseModel.

Destructor for the meshXBaseModel class.

This destructor deregisters the callback function associated with the model ID and calls the platform specific model de-initialization function.

64{
66}
virtual meshx_err_t from_ble_dereg_cb(void) const
Deregister BLE message callback for this model.
Definition meshx_base_model_class.cpp:115

Member Function Documentation

◆ from_ble_dereg_cb()

template<typename ble_mesh_send_msg_params_t>
meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::from_ble_dereg_cb ( void ) const
protectedvirtual

Deregister BLE message callback for this model.

Deregisters a callback function associated with a model ID.

Automatically called during model destruction to remove the callback function that handles BLE messages for this model's ID.

Returns
MESHX_SUCCESS if deregistration successful, error code otherwise

This function deregisters the callback function associated with the given model ID, allowing the server to stop handling events or messages related to that model.

Returns
meshx_err_t Returns an error code indicating the result of the deregistration. Possible values include success or specific error codes.

Reimplemented in meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >, meshXBaseClientModel< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_cli_cb_param_t >, meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >, meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >, meshXBaseServerModel< meshXBaseConfigServerModel, meshx_config_server_send_params_t, meshx_config_server_restore_params_t, meshx_config_srv_cb_param_t >, meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >, meshXBaseServerModel< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t >, and meshXBaseServerModel< meshXBaseSensorServerModel, meshx_sensor_server_send_params_t, meshx_sensor_server_restore_params_t, meshx_sensor_server_cb_param_t >.

116{
117 for (auto it = registrations.begin(); it != registrations.end(); ++it)
118 {
119 if (it->id == model_id)
120 {
121 if (--it->count == 0)
122 {
123 MESHX_LOGD(MODULE_ID_COMMON, "meshXBaseModel[%08" PRIx32 "] Last instance, unsubscribing callback %p", model_id, from_ble_cb);
125 registrations.remove_if([this](const reg_info& reg) { return reg.id == model_id; });
126 return err;
127 }
128 MESHX_LOGD(MODULE_ID_COMMON, "meshXBaseModel[%08" PRIx32 "] Decrementing count to %d", model_id, it->count);
129 return MESHX_SUCCESS;
130 }
131 }
132
133 return MESHX_SUCCESS;
134}
static std::forward_list< reg_info > registrations
Definition meshx_base_model_class.hpp:68
meshx_err_t control_task_msg_unsubscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Deregister a callback for a specific message code and event bitmap.
Definition meshx_control_task.c:172
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
Definition meshx_base_model_class.hpp:67

◆ from_ble_reg_cb()

template<typename ble_mesh_send_msg_params_t>
meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::from_ble_reg_cb ( void ) const

Register BLE message callback for this model.

Automatically called during model initialization to register a callback function that handles BLE messages for this model's ID.

Returns
MESHX_SUCCESS on success, error code otherwise
83{
84 if (from_ble_cb == nullptr)
85 {
86 MESHX_LOGE(MODULE_ID_COMMON, "meshXBaseModel[%08" PRIx32 "] from_ble_reg_cb: Invalid state (cb=NULL)", model_id);
87 return MESHX_FAIL;
88 }
89
90 for (auto &reg : registrations)
91 {
92 if (reg.id == model_id)
93 {
94 reg.count++;
95 MESHX_LOGD(MODULE_ID_COMMON, "meshXBaseModel[%08" PRIx32 "] Already registered, incrementing count to %d", model_id, reg.count);
96 return MESHX_SUCCESS;
97 }
98 }
99
100 registrations.push_front({model_id, 1});
101 MESHX_LOGD(MODULE_ID_COMMON, "meshXBaseModel[%08" PRIx32 "] First registration, subscribing callback %p", model_id, from_ble_cb);
103}
meshx_err_t control_task_msg_subscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Subscribe to a control task message.
Definition meshx_control_task.c:142

◆ get_from_ble_cb()

template<typename ble_mesh_send_msg_params_t>
control_task_msg_handle_t meshXBaseModel< ble_mesh_send_msg_params_t >::get_from_ble_cb ( void ) const
inline

Get the BLE message callback function.

Returns
Callback function for handling BLE messages
135{ return from_ble_cb; }

◆ get_model_id()

template<typename ble_mesh_send_msg_params_t>
uint32_t meshXBaseModel< ble_mesh_send_msg_params_t >::get_model_id ( void ) const
inline

Get the model identifier.

Returns
Model ID value
129{ return model_id; }

◆ get_model_type()

template<typename ble_mesh_send_msg_params_t>
meshXBaseModelType_t meshXBaseModel< ble_mesh_send_msg_params_t >::get_model_type ( void ) const
inline

Get the model type (server/client).

Returns
Model type enumeration value
141{ return model_type; }

◆ get_status()

template<typename ble_mesh_send_msg_params_t>
meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::get_status ( void ) const
inline

Get the current status of the model.

Returns
Current status code
123{ return status; }

◆ plat_model_init()

template<typename ble_mesh_send_msg_params_t>
virtual meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::plat_model_init ( void )
pure virtual

Initialize platform model.

Pure virtual function to be implemented by derived classes for platform-specific model initialization. This function is called during model construction.

Template Parameters
meshXBaseTDerived model type
ble_mesh_send_msg_params_tType for BLE mesh send message parameters
Returns
MESHX_SUCCESS on success, error code otherwise
Return values
MESHX_SUCCESSInitialization successful
MESHX_ERR_*Error code indicating reason for failure

Implemented in meshXBaseConfigServerModel, meshXBaseGenericClientModel, meshXBaseGenericServerModel, meshXBaseLightClientModel, meshXBaseLightServerModel, and meshXBaseSensorServerModel.

◆ plat_send_msg()

template<typename ble_mesh_send_msg_params_t>
virtual meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::plat_send_msg ( ble_mesh_send_msg_params_t * params)
pure virtual

Send message through the model.

Pure virtual function to be implemented by derived classes for sending messages through the BLE mesh network. The implementation should handle the actual transmission of the message to the BLE stack.

Template Parameters
meshXBaseTDerived model type
ble_mesh_send_msg_params_tType for BLE mesh send message parameters
Parameters
[in]paramsPointer to message parameters structure containing:
  • opcode: Message opcode
  • msg: Pointer to message data
  • len: Length of message data
  • dst: Destination address
  • app_idx: Application key index
  • ttl: Time to live value
Returns
MESHX_SUCCESS on success, error code otherwise
Return values
MESHX_SUCCESSMessage sent successfully
MESHX_ERR_INVALID_ARGInvalid parameters
MESHX_ERR_NO_MEMInsufficient memory
MESHX_ERR_INTERNALInternal error

Implemented in meshXBaseConfigServerModel, meshXBaseGenericClientModel, meshXBaseGenericServerModel, meshXBaseLightClientModel, meshXBaseLightServerModel, and meshXBaseSensorServerModel.

◆ set_from_ble_cb()

template<typename ble_mesh_send_msg_params_t>
void meshXBaseModel< ble_mesh_send_msg_params_t >::set_from_ble_cb ( control_task_msg_handle_t cb)
inline

Set the BLE message callback function.

Parameters
[in]cbCallback function for handling BLE messages
159{ from_ble_cb = cb; }

◆ set_model_id()

template<typename ble_mesh_send_msg_params_t>
void meshXBaseModel< ble_mesh_send_msg_params_t >::set_model_id ( uint32_t id)
inline

Set the model identifier.

Parameters
[in]idModel ID to set
153{ model_id = id; }

◆ set_model_type()

template<typename ble_mesh_send_msg_params_t>
void meshXBaseModel< ble_mesh_send_msg_params_t >::set_model_type ( meshXBaseModelType_t type)
inline

Set the model type.

Parameters
[in]typeModel type (server/client) to set
165{ model_type = type; }

◆ set_status()

template<typename ble_mesh_send_msg_params_t>
void meshXBaseModel< ble_mesh_send_msg_params_t >::set_status ( meshx_err_t err)
inline

Set the model status.

Parameters
[in]errStatus code to set
147{ status = err; }

Field Documentation

◆ from_ble_cb

template<typename ble_mesh_send_msg_params_t>
control_task_msg_handle_t meshXBaseModel< ble_mesh_send_msg_params_t >::from_ble_cb
protected

◆ model_id

template<typename ble_mesh_send_msg_params_t>
uint32_t meshXBaseModel< ble_mesh_send_msg_params_t >::model_id
protected

◆ model_type

template<typename ble_mesh_send_msg_params_t>
meshXBaseModelType_t meshXBaseModel< ble_mesh_send_msg_params_t >::model_type
protected

◆ registrations

template<typename ble_mesh_send_msg_params_t>
std::forward_list<reg_info> meshXBaseModel< ble_mesh_send_msg_params_t >::registrations
staticprivate

◆ status

template<typename ble_mesh_send_msg_params_t>
meshx_err_t meshXBaseModel< ble_mesh_send_msg_params_t >::status = MESHX_SUCCESS
protected

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