feat: Add CEchoAction class
This commit is contained in:
97
src/dicom/CEchoAction.cpp
Normal file
97
src/dicom/CEchoAction.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "CEchoAction.h"
|
||||
|
||||
#include "recon/ReconManager.h"
|
||||
|
||||
#include <QThread>
|
||||
#include <dcmtk/dcmnet/scu.h>
|
||||
|
||||
CEchoAction::CEchoAction(QObject* aParent):AsyncAction(aParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEchoAction::~CEchoAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CEchoAction::run(){
|
||||
for (size_t i = 0; i < mSettings.length(); i++)
|
||||
{
|
||||
if (mSettings[i].Type==0)
|
||||
{
|
||||
emit actionStepStart(QString(tr("Connecting from device to %1:%2......").arg(mSettings[i].IP.data()).arg(mSettings[i].Port)));
|
||||
DcmSCU scu;
|
||||
scu.setMaxReceivePDULength(ASC_DEFAULTMAXPDU);
|
||||
scu.setACSETimeout(3);
|
||||
scu.setDIMSEBlockingMode(DIMSE_BLOCKING);
|
||||
scu.setDIMSETimeout(3);
|
||||
scu.setAETitle(mSettings[i].AETitle.data());
|
||||
scu.setPeerHostName(mSettings[i].IP.data());
|
||||
scu.setPeerPort(mSettings[i].Port);
|
||||
scu.setPeerAETitle(mSettings[i].ServerTitle.data());
|
||||
scu.setVerbosePCMode(OFFalse);
|
||||
OFList<OFString> syntaxes;
|
||||
syntaxes.push_back(UID_LittleEndianImplicitTransferSyntax);
|
||||
scu.addPresentationContext(UID_VerificationSOPClass, syntaxes);
|
||||
scu.setConnectionTimeout(3);
|
||||
|
||||
OFCondition cond = scu.initNetwork();
|
||||
QString errorMessage = QString(tr("Connection from device test to %1:%2 failed")).arg(mSettings[i].IP.data()).arg(mSettings[i].Port);
|
||||
if (cond.bad())
|
||||
{
|
||||
doCompletedEmit(ActionResult(Failed,errorMessage),i,mSettings.length());
|
||||
continue;
|
||||
}
|
||||
cond = scu.negotiateAssociation();
|
||||
if (cond.bad())
|
||||
{
|
||||
doCompletedEmit(ActionResult(Failed,errorMessage),i,mSettings.length());
|
||||
continue;
|
||||
}
|
||||
cond = scu.sendECHORequest(scu.findPresentationContextID(UID_VerificationSOPClass,""));
|
||||
if (cond.bad())
|
||||
{
|
||||
doCompletedEmit(ActionResult(Failed,errorMessage),i,mSettings.length());
|
||||
continue;
|
||||
}
|
||||
scu.releaseAssociation();
|
||||
QString message = QString(tr("Connection test from device to %1:%2 successed")).arg(mSettings[i].IP.data()).arg(mSettings[i].Port);
|
||||
doCompletedEmit(ActionResult(Sucessed,message),i,mSettings.length());
|
||||
}
|
||||
else{
|
||||
emit actionStepStart(QString(tr("Connecting from server to %1:%2......").arg(mSettings[i].IP.data()).arg(mSettings[i].Port)));
|
||||
bool ret = true;
|
||||
QString message;
|
||||
ReconManager::CEcho(mSettings[i].IP.data(),mSettings[i].Port,mSettings[i].ServerTitle.data(),ret,message);
|
||||
if(ret){
|
||||
message = QString(tr("Connection test from server to %1:%2 successed")).arg(mSettings[i].IP.data()).arg(mSettings[i].Port);
|
||||
doCompletedEmit(ActionResult(Sucessed,message),i,mSettings.length());
|
||||
}
|
||||
else{
|
||||
QString errorMessage = QString(tr("Connection test from Recon to %1:%2 failed"))
|
||||
.arg(mSettings[i].IP.data()).arg(mSettings[i].Port);
|
||||
doCompletedEmit(ActionResult(Failed,errorMessage),i,mSettings.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CEchoAction::addCEchoActionItem(const CEchoSetting& aSetting)
|
||||
{
|
||||
mSettings.append(aSetting);
|
||||
}
|
||||
|
||||
void CEchoAction::doCompletedEmit(const ActionResult& aResult, size_t aIndex, size_t aLength)
|
||||
{
|
||||
if (aIndex == aLength-1){
|
||||
emit actionCompleted(aResult);
|
||||
}
|
||||
else{
|
||||
emit actionStepCompleted(aResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
src/dicom/CEchoAction.h
Normal file
29
src/dicom/CEchoAction.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef AAD49461_3276_47D6_B033_156B91C94F74
|
||||
#define AAD49461_3276_47D6_B033_156B91C94F74
|
||||
|
||||
#include "action/AsyncAction.h"
|
||||
#include "CEchoSetting.h"
|
||||
|
||||
#include <QList>
|
||||
enum CEchoType{
|
||||
LOCAL,REMOTE
|
||||
};
|
||||
|
||||
class CEchoAction : public AsyncAction
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CEchoAction(QObject* aParent = nullptr);
|
||||
~CEchoAction() override;
|
||||
void run() override;
|
||||
void addCEchoActionItem(const CEchoSetting& aSetting);
|
||||
signals:
|
||||
void actionStepCompleted(const ActionResult& aResult);
|
||||
void actionStepStart(const QString& aMessage);
|
||||
|
||||
private:
|
||||
QList<CEchoSetting> mSettings;
|
||||
void doCompletedEmit(const ActionResult& aResult, size_t aIndex, size_t aLength);
|
||||
};
|
||||
|
||||
#endif /* AAD49461_3276_47D6_B033_156B91C94F74 */
|
||||
Reference in New Issue
Block a user