Update to dms control phase1.
This commit is contained in:
46
src/device/DmsAsyncAction.cpp
Normal file
46
src/device/DmsAsyncAction.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "DmsAsyncAction.h"
|
||||
#include "dms_mq.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace
|
||||
{
|
||||
const int TIMEOUT_MSEC = 500;
|
||||
}
|
||||
|
||||
DmsAsyncAction::DmsAsyncAction(int aServerId, int aActionId, QObject* aObject, const QString& aResponseSignal, QObject* aParent)
|
||||
: QObject(aParent)
|
||||
, mServerId(aServerId)
|
||||
, mActionId(aActionId)
|
||||
, mTimer(new QTimer(this))
|
||||
, mObject(aObject)
|
||||
, mResponseSignal(aResponseSignal)
|
||||
, mSendData()
|
||||
{
|
||||
mTimer->setSingleShot(true);
|
||||
connect(mTimer, &QTimer::timeout, this, &DmsAsyncAction::sendTimeoutSignal);
|
||||
connect(mObject, ("2" + mResponseSignal).toStdString().c_str(), mTimer, SLOT(stop()));
|
||||
}
|
||||
|
||||
DmsAsyncAction::~DmsAsyncAction()
|
||||
{
|
||||
disconnect(mTimer, &QTimer::timeout, this, &DmsAsyncAction::sendTimeoutSignal);
|
||||
disconnect(mObject, ("2" + mResponseSignal).toStdString().c_str(), mTimer, SLOT(stop()));
|
||||
}
|
||||
|
||||
bool DmsAsyncAction::execute()
|
||||
{
|
||||
QByteArray byteArray = mSendData.toUtf8();
|
||||
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
||||
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mTimer->start(TIMEOUT_MSEC);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DmsAsyncAction::sendTimeoutSignal()
|
||||
{
|
||||
emit timeout();
|
||||
}
|
||||
Reference in New Issue
Block a user