Fix DmsAsyncAction and DmsSyncAction to responsed from timeout.
This commit is contained in:
@@ -16,6 +16,7 @@ DmsAsyncAction::DmsAsyncAction(int aServerId, int aActionId, QObject* aObject, c
|
|||||||
, mObject(aObject)
|
, mObject(aObject)
|
||||||
, mResponseSignal(aResponseSignal)
|
, mResponseSignal(aResponseSignal)
|
||||||
, mSendData()
|
, mSendData()
|
||||||
|
, mIsResponsed(false)
|
||||||
{
|
{
|
||||||
mTimer->setSingleShot(true);
|
mTimer->setSingleShot(true);
|
||||||
mTimer->setInterval(TIMEOUT_MSEC);
|
mTimer->setInterval(TIMEOUT_MSEC);
|
||||||
@@ -31,6 +32,7 @@ DmsAsyncAction::~DmsAsyncAction()
|
|||||||
|
|
||||||
bool DmsAsyncAction::execute()
|
bool DmsAsyncAction::execute()
|
||||||
{
|
{
|
||||||
|
mIsResponsed = false;
|
||||||
QByteArray byteArray = mSendData.toUtf8();
|
QByteArray byteArray = mSendData.toUtf8();
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
||||||
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
||||||
@@ -43,7 +45,10 @@ bool DmsAsyncAction::execute()
|
|||||||
|
|
||||||
void DmsAsyncAction::sendTimeoutSignal()
|
void DmsAsyncAction::sendTimeoutSignal()
|
||||||
{
|
{
|
||||||
emit timeout();
|
if(!mIsResponsed)
|
||||||
|
{
|
||||||
|
emit timeout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DmsAsyncAction::setTimeoutInterval(int aMsec)
|
void DmsAsyncAction::setTimeoutInterval(int aMsec)
|
||||||
@@ -53,5 +58,8 @@ void DmsAsyncAction::setTimeoutInterval(int aMsec)
|
|||||||
|
|
||||||
void DmsAsyncAction::responsed()
|
void DmsAsyncAction::responsed()
|
||||||
{
|
{
|
||||||
mTimer->stop();
|
if(mTimer->isActive())
|
||||||
|
{
|
||||||
|
mIsResponsed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ private:
|
|||||||
QObject* mObject;
|
QObject* mObject;
|
||||||
QString mResponseSignal;
|
QString mResponseSignal;
|
||||||
QString mSendData;
|
QString mSendData;
|
||||||
|
bool mIsResponsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DMSASYNCACTION_H
|
#endif // DMSASYNCACTION_H
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ DmsSyncAction::DmsSyncAction(int aServerId, int aActionId, QObject* aObject, con
|
|||||||
, mTimeoutMsec(TIMEOUT_MSEC)
|
, mTimeoutMsec(TIMEOUT_MSEC)
|
||||||
, mSendData()
|
, mSendData()
|
||||||
, mActionResult()
|
, mActionResult()
|
||||||
, mIsTimeout(false)
|
, mIsResponsed(false)
|
||||||
{
|
{
|
||||||
mTimer->setSingleShot(true);
|
mTimer->setSingleShot(true);
|
||||||
connect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&)));
|
connect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&)));
|
||||||
connect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit()));
|
connect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit()));
|
||||||
connect(mTimer, &QTimer::timeout, this, &DmsSyncAction::responsed);
|
|
||||||
connect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit);
|
connect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +32,12 @@ DmsSyncAction::~DmsSyncAction()
|
|||||||
{
|
{
|
||||||
disconnect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit()));
|
disconnect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit()));
|
||||||
disconnect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&)));
|
disconnect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&)));
|
||||||
disconnect(mTimer, &QTimer::timeout, this, &DmsSyncAction::responsed);
|
|
||||||
disconnect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit);
|
disconnect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
DmsSyncActionResult DmsSyncAction::execute()
|
DmsSyncActionResult DmsSyncAction::execute()
|
||||||
{
|
{
|
||||||
|
mIsResponsed = false;
|
||||||
QByteArray byteArray = mSendData.toUtf8();
|
QByteArray byteArray = mSendData.toUtf8();
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
||||||
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
||||||
@@ -68,7 +67,7 @@ bool DmsSyncAction::waitUntilSignalReceived()
|
|||||||
{
|
{
|
||||||
mTimer->start(mTimeoutMsec);
|
mTimer->start(mTimeoutMsec);
|
||||||
mLoop->exec();
|
mLoop->exec();
|
||||||
if(mIsTimeout)
|
if(!mIsResponsed)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -79,11 +78,6 @@ void DmsSyncAction::responsed()
|
|||||||
{
|
{
|
||||||
if(mTimer->isActive())
|
if(mTimer->isActive())
|
||||||
{
|
{
|
||||||
mTimer->stop();
|
mIsResponsed = true;
|
||||||
mIsTimeout = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mIsTimeout = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ private:
|
|||||||
int mTimeoutMsec;
|
int mTimeoutMsec;
|
||||||
QString mSendData;
|
QString mSendData;
|
||||||
QString mActionResult;
|
QString mActionResult;
|
||||||
bool mIsTimeout;
|
bool mIsResponsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DMSSYNCACTION_H
|
#endif // DMSSYNCACTION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user