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
meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t > Class Template Referenceabstract

#include <meshx_base_model_class.hpp>

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

Public Member Functions

virtual meshx_err_t server_state_restore (ble_mesh_plat_restore_params_t *param)=0
 meshXBaseServerModel ()=delete
virtual ~meshXBaseServerModel ()=default
 meshXBaseServerModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseServerModel class.
meshx_err_t from_ble_dereg_cb (void) const override
 Deregister BLE message callback for this model.
void set_plat_model_ptr (meshx_ptr_t p_model)
 Set the platform model pointer and update the registration list.
Public Member Functions inherited from meshXBaseModel< ble_mesh_send_msg_params_t >
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 validate_server_status_opcode (uint16_t opcode)=0

Static Protected Member Functions

static meshx_err_t base_from_ble_msg_handle (dev_struct_t *pdev, control_task_msg_evt_t evt, meshx_ptr_t params)
 Sends a BLE message from a server model.

Protected Attributes

meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< ble_mesh_send_msg_params_t >
uint32_t model_id
meshXBaseModelType_t model_type
control_task_msg_handle_t from_ble_cb
meshx_err_t status = MESHX_SUCCESS

Static Protected Attributes

static std::once_flag plat_server_init_flag
static std::forward_list< base_server_model_cb_reg_tbase_server_model_cb_list

Private Types

using base_server_model_cb_reg_t

Member Typedef Documentation

◆ base_server_model_cb_reg_t

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
using meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::base_server_model_cb_reg_t
private
Initial value:
struct base_server_model_cb_reg
{
uint16_t model_id;
}
uint32_t model_id
Definition meshx_base_model_class.hpp:52
meshx_ptr_t p_plat_model
Definition meshx_base_model_class.hpp:202
meshXBaseServerModel()=delete
std::function< meshx_err_t(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t)> control_msg_cb
Definition meshx_base_model_class.hpp:32
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
194 {
195 uint16_t model_id; /**< Model ID associated with the registration. */
196 meshx_ptr_t p_plat_model; /**< Platform model pointer for instance verification. */
197 control_msg_cb cb; /**< Callback function associated with the registration. */
198 meshXBaseServerModel *instance; /**< Instance pointer for registration management. */
199 };
Definition meshx_base_model_class.hpp:189

Constructor & Destructor Documentation

◆ meshXBaseServerModel() [1/2]

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::meshXBaseServerModel ( )
delete

◆ ~meshXBaseServerModel()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
virtual meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::~meshXBaseServerModel ( )
virtualdefault

◆ meshXBaseServerModel() [2/2]

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::meshXBaseServerModel ( uint32_t model_id,
meshx_ptr_t p_plat_model,
const control_msg_cb & from_ble_cb )

Constructor for the meshXBaseServerModel class.

This constructor initializes the meshXBaseServerModel class with the given model ID and callback function.

Parameters
[in]model_idThe unique identifier of the generic server model.
[in]p_plat_modelPointer to the platform-specific model structure.
[in]from_ble_cbThe callback function to be registered for the model.
154{
156 if (!from_ble_cb)
157 {
158 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid callback for model_id: %04x", model_id);
160 return;
161 }
162
164 this->status = MESHX_SUCCESS;
165}
meshx_err_t status
Definition meshx_base_model_class.hpp:55
control_task_msg_handle_t from_ble_cb
Definition meshx_base_model_class.hpp:54
meshXBaseModel()=delete
static std::forward_list< base_server_model_cb_reg_t > base_server_model_cb_list
Definition meshx_base_model_class.hpp:204
static meshx_err_t base_from_ble_msg_handle(dev_struct_t *pdev, control_task_msg_evt_t evt, meshx_ptr_t params)
Sends a BLE message from a server model.
Definition meshx_base_model_class.cpp:176
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114

Member Function Documentation

◆ base_from_ble_msg_handle()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
meshx_err_t meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::base_from_ble_msg_handle ( dev_struct_t * pdev,
control_task_msg_evt_t evt,
meshx_ptr_t params )
staticprotected

Sends a BLE message from a server model.

Parameters
[in]pdevPointer to the device structure.
[in]evtThe event type associated with the message.
[in]paramsPointer to the parameters of the message.
Returns
meshx_err_t Returns an error code indicating the result of the send operation.
178{
179 if (pdev == nullptr || params == nullptr)
180 return MESHX_INVALID_ARG;
181
182 auto *param = static_cast<ble_mesh_plat_cb_params_t*>(params);
183 meshx_ptr_t plat_model = param->model.p_model;
184
185 bool cb_invoked = false;
186 for (auto &node : base_server_model_cb_list)
187 {
188 if ((uint16_t)evt == node.model_id)
189 {
190 /* Only invoke if the platform model matches this instance */
192 {
193 continue;
194 }
195
196 if (node.cb)
197 {
198 node.cb(pdev, evt, params);
199 cb_invoked = true;
200 }
201 }
202 }
203
204 if (!cb_invoked)
205 {
206 MESHX_LOGW(MODULE_ID_MODEL_SERVER, "No registered server handled model_id=%04" PRIx32, (uint32_t)evt);
207 }
208
210}
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120

◆ from_ble_dereg_cb()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
meshx_err_t meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::from_ble_dereg_cb ( void ) const
overridevirtual

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 from meshXBaseModel< ble_mesh_send_msg_params_t >.

214{
215 // First, unsubscribe from control task
217
218 // Then, remove from our static callback list to prevent dangling pointers
220 return node.p_plat_model == this->p_plat_model;
221 });
222
223 return err;
224}
struct base_server_model_cb_reg { uint16_t model_id; meshx_ptr_t p_plat_model; control_msg_cb cb; meshXBaseServerModel *instance; } base_server_model_cb_reg_t
Definition meshx_base_model_class.hpp:193
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

◆ server_state_restore()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
virtual meshx_err_t meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::server_state_restore ( ble_mesh_plat_restore_params_t * param)
pure virtual

◆ set_plat_model_ptr()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
void meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::set_plat_model_ptr ( meshx_ptr_t p_model)

Set the platform model pointer and update the registration list.

Parameters
[in]p_modelPointer to the platform model instance.
228{
229 this->p_plat_model = p_model;
230 for (auto &node : base_server_model_cb_list)
231 {
232 if (node.instance == this)
233 {
235 break;
236 }
237 }
238}

◆ validate_server_status_opcode()

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
virtual meshx_err_t meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::validate_server_status_opcode ( uint16_t opcode)
protectedpure virtual

Field Documentation

◆ base_server_model_cb_list

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
std::forward_list<base_server_model_cb_reg_t> meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::base_server_model_cb_list
staticprotected

◆ p_plat_model

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
meshx_ptr_t meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::p_plat_model
protected

◆ plat_server_init_flag

template<typename baseServerModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_restore_params_t, typename ble_mesh_plat_cb_params_t>
std::once_flag meshXBaseServerModel< baseServerModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_restore_params_t, ble_mesh_plat_cb_params_t >::plat_server_init_flag
staticprotected

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