mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
05200f9266
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>
78 lines
2 KiB
C++
78 lines
2 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef BTDISCOVERY_H
|
|
#define BTDISCOVERY_H
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QLoggingCategory>
|
|
#include <QAbstractListModel>
|
|
#include <QBluetoothLocalDevice>
|
|
#include <QBluetoothDeviceDiscoveryAgent>
|
|
#include <QBluetoothUuid>
|
|
#include "core/libdivecomputer.h"
|
|
#include "core/singleton.h"
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
#include <QAndroidJniObject>
|
|
#include <QAndroidJniEnvironment>
|
|
#endif
|
|
|
|
void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo);
|
|
bool isBluetoothAddress(const QString &address);
|
|
bool matchesKnownDiveComputerNames(QString btName);
|
|
QString extractBluetoothAddress(const QString &address);
|
|
QString extractBluetoothNameAddress(const QString &address, QString &name);
|
|
QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr);
|
|
|
|
class BTDiscovery : public QObject, public SillySingleton<BTDiscovery> {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
BTDiscovery(QObject *parent = NULL);
|
|
~BTDiscovery();
|
|
|
|
struct btPairedDevice {
|
|
QString address;
|
|
QString name;
|
|
};
|
|
|
|
struct btVendorProduct {
|
|
btPairedDevice btpdi;
|
|
dc_descriptor_t *dcDescriptor;
|
|
int vendorIdx;
|
|
int productIdx;
|
|
};
|
|
|
|
void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
|
|
void btDeviceDiscoveredMain(const btPairedDevice &device);
|
|
bool btAvailable() const;
|
|
void showNonDiveComputers(bool show);
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
void getBluetoothDevices();
|
|
#endif
|
|
QList<btVendorProduct> getBtDcs();
|
|
QBluetoothLocalDevice localBtDevice;
|
|
void BTDiscoveryReDiscover();
|
|
void discoverAddress(QString address);
|
|
|
|
private:
|
|
bool m_btValid;
|
|
bool m_showNonDiveComputers;
|
|
|
|
QList<struct btVendorProduct> btDCs; // recognized DCs
|
|
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
bool checkException(const char* method, const QAndroidJniObject* obj);
|
|
#endif
|
|
|
|
QList<struct btPairedDevice> btPairedDevices;
|
|
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
|
|
|
|
signals:
|
|
void dcVendorChanged();
|
|
void dcProductChanged();
|
|
void dcBtChanged();
|
|
};
|
|
#endif // BTDISCOVERY_H
|