diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-05-14 01:57:34 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-05-14 01:57:34 +0200 |
commit | 9e3eff1c3a2b7105fecf6d0d7f052eb9943fbada (patch) | |
tree | e28d75366e004e3865deefb5bcaa2dc8e0d3a773 /libsowatchbt | |
parent | 80c58c124caf17f670d8efc120f5ae4bfd9aa09f (diff) | |
download | sowatch-9e3eff1c3a2b7105fecf6d0d7f052eb9943fbada.tar.gz sowatch-9e3eff1c3a2b7105fecf6d0d7f052eb9943fbada.zip |
perform only one bluetooth discovery for all watches
Diffstat (limited to 'libsowatchbt')
-rw-r--r-- | libsowatchbt/bluetoothwatchscanner.cpp | 41 | ||||
-rw-r--r-- | libsowatchbt/bluetoothwatchscanner.h | 7 |
2 files changed, 31 insertions, 17 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(); } diff --git a/libsowatchbt/bluetoothwatchscanner.h b/libsowatchbt/bluetoothwatchscanner.h index 1ab974a..e2d78ef 100644 --- a/libsowatchbt/bluetoothwatchscanner.h +++ b/libsowatchbt/bluetoothwatchscanner.h @@ -19,17 +19,16 @@ class SOWATCHBT_EXPORT BluetoothWatchScanner : public WatchScanner public: BluetoothWatchScanner(QObject *parent); + ~BluetoothWatchScanner(); void start(); -protected: - void setUuidFilter(const QBluetoothUuid & uuid); - protected slots: virtual void handleDiscoveredService(const QBluetoothServiceInfo& info) = 0; private: - QBluetoothServiceDiscoveryAgent *_agent; + static int _instances; + static QBluetoothServiceDiscoveryAgent *_agent; }; } |