summaryrefslogtreecommitdiff
path: root/sowatchd/allscanner.cpp
blob: a3e7d333449fb35cdb5de7183f7d27f6b187be8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "allscanner.h"

using namespace sowatch;

AllScanner::AllScanner(QObject *parent) :
	WatchScanner(parent), _finishedCount(0)
{
	QList<WatchPluginInterface*> plugins = Registry::registry()->getWatchPlugins();
	foreach (WatchPluginInterface* driver, plugins) {
		WatchScanner* scanner = driver->getScanner(this);
		if (scanner) {
			_scanners += scanner;
			connect(scanner, SIGNAL(finished()), this, SLOT(handleFinished()));
			connect(scanner, SIGNAL(watchFound(QVariantMap)),
			        this, SIGNAL(watchFound(QVariantMap)));
		}
	}
}

void AllScanner::start()
{
	if (_scanners.empty()) {
		emit finished();
	} else {
		foreach (WatchScanner* scanner, _scanners) {
			scanner->start();
		}
		emit started();
	}
}

void AllScanner::handleFinished()
{
	qDebug() << "one finished";
	_finishedCount++;
	if (_finishedCount >= _scanners.length()) {
		qDebug() << "all finished";
		emit finished();
	}
}