summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/heartrate-game/connectionhandler.h
blob: e51fcbef4c3a095c230c61d7e8f40f356df0e0a6 (plain)
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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef CONNECTIONHANDLER_H
#define CONNECTIONHANDLER_H

#include <QBluetoothLocalDevice>

#include <QObject>

#include <QQmlEngine>

class ConnectionHandler : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool alive READ alive NOTIFY deviceChanged)
    Q_PROPERTY(bool hasPermission READ hasPermission NOTIFY deviceChanged)
    Q_PROPERTY(QString name READ name NOTIFY deviceChanged)
    Q_PROPERTY(QString address READ address NOTIFY deviceChanged)
    Q_PROPERTY(bool requiresAddressType READ requiresAddressType CONSTANT)

    QML_ELEMENT
public:
    explicit ConnectionHandler(QObject *parent = nullptr);

    bool alive() const;
    bool hasPermission() const;
    bool requiresAddressType() const;
    QString name() const;
    QString address() const;

signals:
    void deviceChanged();

private slots:
    void hostModeChanged(QBluetoothLocalDevice::HostMode mode);
    void initLocalDevice();

private:
    QBluetoothLocalDevice *m_localDevice = nullptr;
    bool m_hasPermission = false;
};

#endif // CONNECTIONHANDLER_H