diff options
Diffstat (limited to 'libsowatchbt/bluetoothwatchscanner.cpp')
-rw-r--r-- | libsowatchbt/bluetoothwatchscanner.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/libsowatchbt/bluetoothwatchscanner.cpp b/libsowatchbt/bluetoothwatchscanner.cpp index eeae5f7..192da0d 100644 --- a/libsowatchbt/bluetoothwatchscanner.cpp +++ b/libsowatchbt/bluetoothwatchscanner.cpp @@ -6,26 +6,41 @@ QTM_USE_NAMESPACE using namespace sowatch; + +int BluetoothWatchScanner::_instances = 0; +QBluetoothServiceDiscoveryAgent *BluetoothWatchScanner::_agent = 0; + BluetoothWatchScanner::BluetoothWatchScanner(QObject *parent) : - WatchScanner(parent), - _agent(new QBluetoothServiceDiscoveryAgent(this)) + WatchScanner(parent) { - connect(_agent, SIGNAL(finished()), this, SIGNAL(finished())); - connect(_agent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), - this, SLOT(handleDiscoveredService(QBluetoothServiceInfo))); + if (_instances == 0) { + Q_ASSERT(!_agent); + _agent = new QBluetoothServiceDiscoveryAgent; + } + _instances++; + Q_ASSERT(_agent); } -void BluetoothWatchScanner::start() +BluetoothWatchScanner::~BluetoothWatchScanner() { - if (_agent->isActive()) { - _agent->stop(); + _instances--; + if (_instances == 0) { + delete _agent; + _agent = 0; } - _agent->start(); - qDebug() << "started bluetooth scan"; - emit started(); } -void BluetoothWatchScanner::setUuidFilter(const QBluetoothUuid & uuid) +void BluetoothWatchScanner::start() { - _agent->setUuidFilter(uuid); + 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(); } |