summaryrefslogtreecommitdiff
path: root/libsowatchbt/bluetoothwatchscanner.cpp
blob: 192da0d8fae29b3b72dee6b8c47b18328d670b78 (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
41
42
43
44
45
46
#include <QtConnectivity/QBluetoothDeviceInfo>
#include <QtConnectivity/QBluetoothAddress>

#include "bluetoothwatchscanner.h"

QTM_USE_NAMESPACE
using namespace sowatch;


int BluetoothWatchScanner::_instances = 0;
QBluetoothServiceDiscoveryAgent *BluetoothWatchScanner::_agent = 0;

BluetoothWatchScanner::BluetoothWatchScanner(QObject *parent) :
	WatchScanner(parent)
{
	if (_instances == 0) {
		Q_ASSERT(!_agent);
		_agent = new QBluetoothServiceDiscoveryAgent;
	}
	_instances++;
	Q_ASSERT(_agent);
}

BluetoothWatchScanner::~BluetoothWatchScanner()
{
	_instances--;
	if (_instances == 0) {
		delete _agent;
		_agent = 0;
	}
}

void BluetoothWatchScanner::start()
{
	Q_ASSERT(_agent);
	connect(_agent, SIGNAL(finished()), this, SIGNAL(finished()));
	connect(_agent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
			this, SLOT(handleDiscoveredService(QBluetoothServiceInfo)));

	if (!_agent->isActive()) {
		qDebug() << "started bluetooth scan";
		_agent->start();
	}

	emit started();
}