diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-09-22 14:33:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-09-25 13:35:30 -0700 |
commit | 05200f9266a4e8e723450abb281c597a48da2e9f (patch) | |
tree | 670d7b30f4b77f40e35253243f95fb219d5c7aea /core/btdiscovery.cpp | |
parent | f20d6187f0135ef3cf7f583785be65012336a99d (diff) | |
download | subsurface-05200f9266a4e8e723450abb281c597a48da2e9f.tar.gz |
Cleanup: unify idiosyncratic singletons
The way we handle singletons in QML, QML insists on allocating the
objects. This leads to a very idiosyncratic way of handling
singletons: The global instance pointer is set in the constructor.
Unify all these by implementing a "SillySingleton" template. All
of the weird singleton-classes can derive from this template and
don't have to bother with reimplementing the instance() function
with all the safety-checks, etc.
This serves firstly as documentation but also improves debugging
as we will now see wanted and unwanted creation and destruction
of these weird singletons.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/btdiscovery.cpp')
-rw-r--r-- | core/btdiscovery.cpp | 14 |
1 files changed, 0 insertions, 14 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 8db1e02cc..1387be400 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -15,7 +15,6 @@ extern QMap<QString, dc_descriptor_t *> descriptorLookup; namespace { QHash<QString, QBluetoothDeviceInfo> btDeviceInfo; } -BTDiscovery *BTDiscovery::m_instance = NULL; static dc_descriptor_t *getDeviceType(QString btName) // central function to convert a BT name to a Subsurface known vendor/model pair @@ -139,11 +138,6 @@ BTDiscovery::BTDiscovery(QObject*) : m_btValid(false), m_showNonDiveComputers(false), discoveryAgent(nullptr) { - if (m_instance) { - qDebug() << "trying to create an additional BTDiscovery object"; - return; - } - m_instance = this; #if defined(BT_SUPPORT) QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); BTDiscoveryReDiscover(); @@ -202,19 +196,11 @@ void BTDiscovery::BTDiscoveryReDiscover() BTDiscovery::~BTDiscovery() { - m_instance = NULL; #if defined(BT_SUPPORT) delete discoveryAgent; #endif } -BTDiscovery *BTDiscovery::instance() -{ - if (!m_instance) - m_instance = new BTDiscovery(); - return m_instance; -} - #if defined(BT_SUPPORT) extern void addBtUuid(QBluetoothUuid uuid); extern QHash<QString, QStringList> productList; |