aboutsummaryrefslogtreecommitdiffstats
path: root/core/btdiscovery.h
blob: 71df24f2420059f22765e92933449cc04454d113 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: GPL-2.0
#ifndef BTDISCOVERY_H
#define BTDISCOVERY_H

#include <QObject>
#include <QString>
#include <QLoggingCategory>
#include <QAbstractListModel>
#if defined(BT_SUPPORT)
#include <QBluetoothLocalDevice>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothUuid>
#include "core/libdivecomputer.h"

#endif
#if defined(Q_OS_ANDROID)
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#endif

class ConnectionListModel : public QAbstractListModel {
	Q_OBJECT
public:
	enum CLMRole {
		AddressRole = Qt::UserRole + 1
	};
	ConnectionListModel(QObject *parent = 0);
	QHash<int, QByteArray> roleNames() const;
	QVariant data(const QModelIndex &index, int role = AddressRole) const;
	QString address(int idx) const;
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	void addAddress(const QString address);
private:
	QStringList m_addresses;
};

class BTDiscovery : public QObject {
	Q_OBJECT

public:
	BTDiscovery(QObject *parent = NULL);
	~BTDiscovery();
	static BTDiscovery *instance();

#if defined(BT_SUPPORT)
	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;
#if defined(Q_OS_ANDROID)
	void getBluetoothDevices();
#endif
	QList<btVendorProduct> getBtDcs();
#endif
private:
	static BTDiscovery *m_instance;
	bool m_btValid;
#if defined(BT_SUPPORT)
	QList<struct btVendorProduct> btDCs;		// recognized DCs
	QList<struct btVendorProduct> btAllDevices;	// all paired BT stuff
#endif
#if defined(Q_OS_ANDROID)
	bool checkException(const char* method, const QAndroidJniObject* obj);
#endif

#if defined(BT_SUPPORT)
	QList<struct btPairedDevice> btPairedDevices;
	QBluetoothLocalDevice localBtDevice;
	QBluetoothDeviceDiscoveryAgent *discoveryAgent;
#endif

signals:
	void dcVendorChanged();
	void dcProductChanged();
	void dcBtChanged();
};

#endif // BTDISCOVERY_H