네이버뉴스 댓글숫자크롤링 git-svn-id: svn://192.168.0.12/source@332 8346c931-da38-4b9b-9d4c-e48b93cbd075
178 lines
5.0 KiB
C++
178 lines
5.0 KiB
C++
#include "srunningprocess.h"
|
|
#include <QTimer>
|
|
#include <QDebug>
|
|
|
|
namespace{
|
|
const int TIMER_SECOND = 15000; // 10 second
|
|
const int HALF_SECOND = 500; // 0.5 second
|
|
}
|
|
|
|
SRunningProcess::SRunningProcess():
|
|
m_pTimer(new QTimer(this)), m_pErrorProcess(new SErrorProcess),
|
|
m_pCompanyProcess(new SCompanyProcess), m_eMode(E_PROCESS_MODE::WAIT),
|
|
m_pCurrentProcess(nullptr)
|
|
{
|
|
m_pTimer->setInterval(TIMER_SECOND);
|
|
initConnect();
|
|
}
|
|
|
|
bool SRunningProcess::isRunning()
|
|
{
|
|
if (m_pCurrentProcess == nullptr && !m_pTimer->isActive())
|
|
return false;
|
|
else
|
|
return !(m_pCurrentProcess->isWaiting() && !m_pTimer->isActive());
|
|
}
|
|
|
|
void SRunningProcess::setList(const QVector<SEffectRow>& _list)
|
|
{
|
|
qDebug() << isRunning();
|
|
|
|
if (!isRunning())
|
|
{
|
|
m_pCurrentProcess = m_pErrorProcess;
|
|
m_pCurrentProcess->setList(_list);
|
|
}
|
|
}
|
|
|
|
void SRunningProcess::setList(QVector<SEffectRow>&& _list)
|
|
{
|
|
qDebug() << isRunning();
|
|
|
|
if (!isRunning())
|
|
{
|
|
m_pCurrentProcess = m_pErrorProcess;
|
|
m_pCurrentProcess->setList(std::move(_list));
|
|
}
|
|
}
|
|
|
|
void SRunningProcess::setList(const QVector<int>& _list)
|
|
{
|
|
qDebug() << isRunning();
|
|
if (!isRunning())
|
|
{
|
|
m_pCurrentProcess = m_pCompanyProcess;
|
|
m_pCurrentProcess->setList(_list);
|
|
}
|
|
}
|
|
|
|
void SRunningProcess::setList(QVector<int>&& _list)
|
|
{
|
|
qDebug() << isRunning();
|
|
if (!isRunning())
|
|
{
|
|
m_pCurrentProcess = m_pCompanyProcess;
|
|
m_pCurrentProcess->setList(std::move(_list));
|
|
}
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
void SRunningProcess::start(QVector<T>&& _list)
|
|
{
|
|
if (!isRunning())
|
|
{
|
|
setList(std::forward(_list));
|
|
start();
|
|
}
|
|
}
|
|
|
|
void SRunningProcess::start()
|
|
{
|
|
if (!isRunning())
|
|
{
|
|
m_pTimer->start();
|
|
emit signalLog("Start Effect Process");
|
|
}
|
|
}
|
|
|
|
void SRunningProcess::update()
|
|
{
|
|
m_pCurrentProcess->update();
|
|
}
|
|
|
|
void SRunningProcess::slotLog(const QString &_strLog)
|
|
{
|
|
emit signalLog(_strLog);
|
|
}
|
|
|
|
void SRunningProcess::terminate()
|
|
{
|
|
m_pTimer->stop();
|
|
m_pCurrentProcess->setModeWait();
|
|
emit signalLog("Terminate Process");
|
|
}
|
|
|
|
void SRunningProcess::slotUserAbort()
|
|
{
|
|
terminate();
|
|
emit signalUserAbort();
|
|
}
|
|
|
|
void SRunningProcess::stop()
|
|
{
|
|
m_pCurrentProcess->stop();
|
|
}
|
|
|
|
void SRunningProcess::slotCompanyComplete(int _num)
|
|
{
|
|
qDebug() << "slotCompanyComplete";
|
|
SReportSummary summary = m_pCurrentProcess->getReportSummary(_num);
|
|
emit signalCompanyComplete(_num, summary);
|
|
}
|
|
|
|
void SRunningProcess::slotSuccessErrorCompany(int _num)
|
|
{
|
|
emit signalSuccessErrorCompany(_num);
|
|
}
|
|
|
|
void SRunningProcess::slotTerminateError()
|
|
{
|
|
terminate();
|
|
//SError error = m_pCurrentProcess->getError();
|
|
emit signalTerminateError();
|
|
}
|
|
|
|
void SRunningProcess::slotTerminateNormal()
|
|
{
|
|
qDebug() << "slotTerminteNormal ??";
|
|
QVector<SEffectRow> errors = m_pCurrentProcess->getErrorList();
|
|
QMap<int, SReportSummary> reportSummary = m_pCurrentProcess->getReportSummary();
|
|
terminate();
|
|
emit signalTerminateNormal(errors, reportSummary);
|
|
}
|
|
|
|
void SRunningProcess::initConnect()
|
|
{
|
|
QObject::connect(&(*m_pTimer), &QTimer::timeout, this, &SRunningProcess::update);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalLog, this, &SRunningProcess::slotLog);
|
|
QObject::connect(&(*m_pErrorProcess), &SErrorProcess::signalLog, this, &SRunningProcess::slotLog);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalTerminate, this, &SRunningProcess::slotTerminateError);
|
|
QObject::connect(&(*m_pErrorProcess), &SErrorProcess::signalTerminate, this, &SRunningProcess::slotTerminateError);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalTerminateNormal, this, &SRunningProcess::slotTerminateNormal);
|
|
QObject::connect(&(*m_pErrorProcess), &SErrorProcess::signalTerminateNormal, this, &SRunningProcess::slotTerminateNormal);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalTerminateCompany, this, &SRunningProcess::slotCompanyComplete);
|
|
QObject::connect(&(*m_pErrorProcess), &SErrorProcess::signalTerminateCompany, this, &SRunningProcess::slotSuccessErrorCompany);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalUserAbort, this, &SRunningProcess::slotUserAbort);
|
|
QObject::connect(&(*m_pErrorProcess), &SErrorProcess::signalUserAbort, this, &SRunningProcess::slotUserAbort);
|
|
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalCompanyStart, this, &SRunningProcess::slotCompanyStart);
|
|
QObject::connect(&(*m_pCompanyProcess), &SCompanyProcess::signalCompanyOutdated, this, &SRunningProcess::slotCompanyOutDated);
|
|
}
|
|
|
|
void SRunningProcess::slotCompanyOutDated(const QVector<int>& _vecCompanyNum)
|
|
{
|
|
emit signalCompanyOutDated(_vecCompanyNum);
|
|
}
|
|
|
|
void SRunningProcess::slotCompanyStart(int _companyNum)
|
|
{
|
|
emit signalCompanyStart(_companyNum);
|
|
}
|
|
|