Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
2 : // SPDX-License-Identifier: LGPL-3.0-or-later
3 :
4 : /*!
5 : * \file
6 : * Declares the AbstractPokitServicePrivate class.
7 : */
8 :
9 : #ifndef QTPOKIT_ABSTRACTPOKITSERVICE_P_H
10 : #define QTPOKIT_ABSTRACTPOKITSERVICE_P_H
11 :
12 : #include <qtpokit/qtpokit_global.h>
13 : #include <qtpokit/pokitproducts.h>
14 :
15 : #include <QLoggingCategory>
16 : #include <QLowEnergyService>
17 : #include <QObject>
18 :
19 : #include <optional>
20 :
21 : class QLowEnergyController;
22 :
23 : QTPOKIT_BEGIN_NAMESPACE
24 :
25 : class AbstractPokitService;
26 :
27 : class QTPOKIT_EXPORT AbstractPokitServicePrivate : public QObject
28 : {
29 798 : Q_OBJECT
30 :
31 : public:
32 16798 : static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg); ///< Logging category.
33 :
34 : bool autoDiscover { true }; ///< Whether autodiscovery is enabled or not.
35 : QLowEnergyController * controller { nullptr }; ///< BLE controller to fetch the service from.
36 : std::optional<PokitProduct> pokitProduct; ///< The Pokit product #controller is connected to.
37 : QLowEnergyService * service { nullptr }; ///< BLE service to read/write characteristics.
38 : QBluetoothUuid serviceUuid; ///< UUIDs for #service.
39 :
40 : AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid,
41 : QLowEnergyController * controller, AbstractPokitService * const q);
42 :
43 5868 : virtual ~AbstractPokitServicePrivate() = default;
44 :
45 : bool createServiceObject();
46 : QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const;
47 : bool readCharacteristic(const QBluetoothUuid &uuid);
48 :
49 : bool enableCharacteristicNotificatons(const QBluetoothUuid &uuid);
50 : bool disableCharacteristicNotificatons(const QBluetoothUuid &uuid);
51 :
52 : static bool checkSize(const QString &label, const QByteArray &data, const int minSize,
53 : const int maxSize=-1, const bool failOnMax=false);
54 : static QString toHexString(const QByteArray &data, const int maxSize=20);
55 :
56 : protected:
57 : AbstractPokitService * q_ptr; ///< Internal q-pointer.
58 :
59 : protected Q_SLOTS:
60 : void connected();
61 : void discoveryFinished();
62 : void errorOccurred(const QLowEnergyService::ServiceError newError);
63 : virtual void serviceDiscovered(const QBluetoothUuid &newService);
64 : void stateChanged(QLowEnergyService::ServiceState newState);
65 :
66 : virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic,
67 : const QByteArray &value);
68 : virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic,
69 : const QByteArray &newValue);
70 : virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic,
71 : const QByteArray &newValue);
72 :
73 : private:
74 114 : Q_DECLARE_PUBLIC(AbstractPokitService)
75 : Q_DISABLE_COPY(AbstractPokitServicePrivate)
76 : friend class TestAbstractPokitService;
77 : };
78 :
79 : QTPOKIT_END_NAMESPACE
80 :
81 : #endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H
|