Skip to content

Commit

Permalink
New message callback mechanism implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed May 8, 2024
1 parent dcda397 commit 6346d12
Show file tree
Hide file tree
Showing 7 changed files with 1,029 additions and 952 deletions.
8 changes: 5 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"type": "shell",
"command": "cd build; make -j4 -Wall",
"args": [],
"group": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc",
"label": "build"
},
Expand All @@ -15,8 +18,7 @@
"command": "cd build; make clean; cmake -DCMAKE_BUILD_TYPE=Debug .. ; make -j4 -Wall",
"args": [],
"group": {
"kind": "build",
"isDefault": true
"kind": "build"
},
"problemMatcher": {
"owner": "cpp",
Expand Down
62 changes: 43 additions & 19 deletions src/cfrmnodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ CMdfFileWidgetItem::~CMdfFileWidgetItem()
// //emit CFrmSession::receiveRow(pev, true);
// }

static void
eventReceived(vscpEvent &ev, void* pobj)
{
vscpEvent* pevnew = new vscpEvent;
pevnew->sizeData = 0;
pevnew->pdata = nullptr;
vscp_copyEvent(pevnew, &ev);
// static void
// eventReceived(vscpEvent &ev, void* pobj)
// {
// vscpEvent* pevnew = new vscpEvent;
// pevnew->sizeData = 0;
// pevnew->pdata = nullptr;
// vscp_copyEvent(pevnew, &ev);

CFrmSession* pSession = (CFrmSession*)pobj;
pSession->threadReceive(pevnew);
}
// CFrmNodeConfig* pNodeConfig = (CFrmNodeConfig*)pobj;
// pNodeConfig->threadReceive(pevnew);
// }

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -346,6 +346,11 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
*/
m_bFullLevel2 = m_connObject["bfull-l2"].toBool();

using namespace std::placeholders;
auto cb = std::bind(&CFrmNodeConfig::receiveCallback, this, _1, _2);
// lambda version for reference
//auto cb = [this](auto a, auto b) { this->receiveCallback(a, b); };

switch (m_vscpConnType) {

case CVscpClient::connType::NONE:
Expand Down Expand Up @@ -390,7 +395,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)

m_vscpClient = new vscpClientTcp();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand Down Expand Up @@ -446,7 +451,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
// GUID
m_vscpClient = new vscpClientWs1();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand All @@ -455,7 +460,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
// GUID
m_vscpClient = new vscpClientWs2();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand Down Expand Up @@ -529,7 +534,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
// GUID
m_vscpClient = new vscpClientUdp();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand All @@ -538,7 +543,7 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
// GUID
m_vscpClient = new vscpClientMulticast();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand All @@ -547,15 +552,15 @@ CFrmNodeConfig::CFrmNodeConfig(QWidget* parent, QJsonObject* pconn)
case CVscpClient::connType::RAWCAN:
m_vscpClient = new vscpClientRawCan();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;

case CVscpClient::connType::RAWMQTT:
m_vscpClient = new vscpClientRawMqtt();
m_vscpClient->initFromJson(strJson.toStdString());
m_vscpClient->setCallbackEv(eventReceived, this);
m_vscpClient->setCallbackEv(/*eventReceived*/cb, this);
ui->actionConnect->setChecked(true);
connectToRemoteHost(true);
break;
Expand Down Expand Up @@ -1181,10 +1186,29 @@ CFrmNodeConfig::receiveRxRow(vscpEvent* pev)
// threadReceive
//

// void
// CFrmNodeConfig::threadReceive(vscpEvent* pev)
// {
// emit dataReceived(pev);
// }

///////////////////////////////////////////////////////////////////////////////
// receiveCallback
//

void
CFrmNodeConfig::threadReceive(vscpEvent* pev)
CFrmNodeConfig::receiveCallback(vscpEvent& ev, void *pobj)
{
emit dataReceived(pev);
vscpEvent* pevnew = new vscpEvent;
pevnew->sizeData = 0;
pevnew->pdata = nullptr;
vscp_copyEvent(pevnew, &ev);

emit dataReceived(pevnew);

// Alternative method for reference
//CFrmSession* pSession = (CFrmSession*)pobj;
//pSession->threadReceive(pevnew);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 6346d12

Please sign in to comment.