59 lines
1.4 KiB
C++
Executable File
59 lines
1.4 KiB
C++
Executable File
/**
|
|
* Scan directory for new XDR files
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "XDR_DirHandler.h"
|
|
|
|
#include <QtCore/QTimer>
|
|
#include <QtCore/QThread>
|
|
|
|
#ifdef WIN32
|
|
#include "XDR_DirHandler_win.h"
|
|
#else
|
|
#include "XDR_DirHandler_linux.h"
|
|
#endif
|
|
|
|
XDR_DirHandler::XDR_DirHandler(const QString &dirToWatch, bool startWatching, QObject *parent)
|
|
: QObject(parent)
|
|
, m_workerThread(new QThread)
|
|
, m_workerObject(nullptr)
|
|
, m_startWatching(startWatching)
|
|
, m_dirToWatch(dirToWatch)
|
|
{
|
|
#ifdef WIN32
|
|
m_workerObject = new XDR_DirHandlerWin(dirToWatch);
|
|
#else
|
|
m_workerObject = new XDR_DirHandlerLinux(dirToWatch);
|
|
#endif
|
|
m_workerThread->start();
|
|
m_workerObject->moveToThread(m_workerThread);
|
|
connect(m_workerObject, &XDR_DirHandlerIfc::newTelegramArrived,
|
|
this, &XDR_DirHandler::newTelegramArrived);
|
|
connect(m_workerThread, &QThread::finished,
|
|
m_workerObject, &XDR_DirHandlerIfc::deleteLater);
|
|
if (startWatching)
|
|
QTimer::singleShot(0, m_workerObject, &XDR_DirHandlerIfc::startWatching);
|
|
}
|
|
|
|
XDR_DirHandler::~XDR_DirHandler()
|
|
{
|
|
m_workerThread->requestInterruption();
|
|
m_workerThread->quit();
|
|
if (!m_workerThread->wait(10000))
|
|
m_workerThread->terminate();
|
|
delete m_workerThread;
|
|
}
|
|
|
|
void XDR_DirHandler::startWatching()
|
|
{
|
|
if (!m_startWatching)
|
|
{
|
|
QTimer::singleShot(0, m_workerObject, &XDR_DirHandlerIfc::startWatching);
|
|
m_startWatching = true;
|
|
}
|
|
}
|
|
|