mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-23 21:50:55 +01:00
Return NimBLEMeshModel pointer from NimBLEMeshElement::createModel
This commit is contained in:
parent
4d78c3013b
commit
06037f8bf6
3 changed files with 23 additions and 9 deletions
|
@ -22,6 +22,8 @@ NimBLEMeshElement::~NimBLEMeshElement() {
|
||||||
for(auto &it : m_modelsVec) {
|
for(auto &it : m_modelsVec) {
|
||||||
delete (NimBLEMeshModel*)it.user_data;
|
delete (NimBLEMeshModel*)it.user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_modelsVec.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +31,10 @@ NimBLEMeshElement::~NimBLEMeshElement() {
|
||||||
* @param [in] type The type of model to create.
|
* @param [in] type The type of model to create.
|
||||||
* @param [in] pCallbacks a pointer to a callback instance for this model.
|
* @param [in] pCallbacks a pointer to a callback instance for this model.
|
||||||
*/
|
*/
|
||||||
void NimBLEMeshElement::createModel(uint16_t type, NimBLEMeshModelCallbacks *pCallbacks) {
|
NimBLEMeshModel* NimBLEMeshElement::createModel(uint16_t type, NimBLEMeshModelCallbacks *pCallbacks) {
|
||||||
for(auto &it : m_modelsVec) {
|
if(getModel(type) != nullptr) {
|
||||||
if(it.id == type) {
|
NIMBLE_LOGE(LOG_TAG, "Error: element already has a type %04x model", type);
|
||||||
NIMBLE_LOGE(LOG_TAG, "Error: element already has a type %04x model", type);
|
return nullptr;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NIMBLE_LOGD(LOG_TAG, "Creating model type: %04x", type);
|
NIMBLE_LOGD(LOG_TAG, "Creating model type: %04x", type);
|
||||||
|
@ -53,10 +53,11 @@ void NimBLEMeshElement::createModel(uint16_t type, NimBLEMeshModelCallbacks *pCa
|
||||||
|
|
||||||
default:
|
default:
|
||||||
NIMBLE_LOGE(LOG_TAG, "Error: model type %04x not supported", type);
|
NIMBLE_LOGE(LOG_TAG, "Error: model type %04x not supported", type);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_modelsVec.push_back(bt_mesh_model{{type},0,0,0, &pModel->m_opPub,{0},{0},pModel->m_opList, pModel});
|
m_modelsVec.push_back(bt_mesh_model{{type},0,0,0, &pModel->m_opPub,{0},{0},pModel->m_opList, pModel});
|
||||||
|
return pModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,6 +68,18 @@ void NimBLEMeshElement::addModel(bt_mesh_model* model) {
|
||||||
m_modelsVec.push_back(*model);
|
m_modelsVec.push_back(*model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NimBLEMeshModel* NimBLEMeshElement::getModel(uint16_t type) {
|
||||||
|
for(auto &it : m_modelsVec) {
|
||||||
|
if(it.id == type) {
|
||||||
|
return (NimBLEMeshModel*)it.user_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a bt_mesh_elem for registering with the nimble stack.
|
* @brief Creates a bt_mesh_elem for registering with the nimble stack.
|
||||||
* @returns A pointer to the bt_mesh_elem created.
|
* @returns A pointer to the bt_mesh_elem created.
|
||||||
|
|
|
@ -19,10 +19,12 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class NimBLEMeshModelCallbacks;
|
class NimBLEMeshModelCallbacks;
|
||||||
|
class NimBLEMeshModel;
|
||||||
|
|
||||||
class NimBLEMeshElement {
|
class NimBLEMeshElement {
|
||||||
public:
|
public:
|
||||||
void createModel(uint16_t type, NimBLEMeshModelCallbacks* pCallbacks=nullptr);
|
NimBLEMeshModel* createModel(uint16_t type, NimBLEMeshModelCallbacks* pCallbacks=nullptr);
|
||||||
|
NimBLEMeshModel* getModel(uint16_t type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class NimBLEMeshNode;
|
friend class NimBLEMeshNode;
|
||||||
|
|
|
@ -118,7 +118,6 @@ void NimBLEMeshModel::publish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimBLEMeshModel::setPubMsg() {
|
void NimBLEMeshModel::setPubMsg() {
|
||||||
NIMBLE_LOGD(LOG_TAG,"Base setPubMsg");
|
|
||||||
m_opPub.msg = NULL;
|
m_opPub.msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue