Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2025 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 : class QLowEnergyController;
20 :
21 : QTPOKIT_BEGIN_NAMESPACE
22 :
23 : class AbstractPokitService;
24 :
25 : class QTPOKIT_EXPORT AbstractPokitServicePrivate : public QObject
26 : {
27 840 : Q_OBJECT
28 :
29 : public:
30 18728 : static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg); ///< Logging category.
31 :
32 : bool autoDiscover { true }; ///< Whether autodiscovery is enabled or not.
33 : QLowEnergyController * controller { nullptr }; ///< BLE controller to fetch the service from.
34 : std::optional<PokitProduct> pokitProduct; ///< The Pokit product #controller is connected to.
35 : QLowEnergyService * service { nullptr }; ///< BLE service to read/write characteristics.
36 : QBluetoothUuid serviceUuid; ///< UUIDs for #service.
37 :
38 : AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid,
39 : QLowEnergyController * controller, AbstractPokitService * const q);
40 :
41 6188 : virtual ~AbstractPokitServicePrivate() = default;
42 :
43 : bool createServiceObject();
44 : QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const;
45 : bool readCharacteristic(const QBluetoothUuid &uuid);
46 :
47 : bool enableCharacteristicNotificatons(const QBluetoothUuid &uuid);
48 : bool disableCharacteristicNotificatons(const QBluetoothUuid &uuid);
49 :
50 : static bool checkSize(const QString &label, const QByteArray &data, const int minSize,
51 : const int maxSize=-1, const bool failOnMax=false);
52 : static QString toHexString(const QByteArray &data, const int maxSize=20);
53 :
54 : protected:
55 : AbstractPokitService * q_ptr; ///< Internal q-pointer.
56 :
57 : protected Q_SLOTS:
58 : void connected();
59 : void discoveryFinished();
60 : void errorOccurred(const QLowEnergyService::ServiceError newError);
61 : virtual void serviceDiscovered(const QBluetoothUuid &newService);
62 : void stateChanged(QLowEnergyService::ServiceState newState);
63 :
64 : virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic,
65 : const QByteArray &value);
66 : virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic,
67 : const QByteArray &newValue);
68 : virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic,
69 : const QByteArray &newValue);
70 :
71 : private:
72 120 : Q_DECLARE_PUBLIC(AbstractPokitService)
73 : Q_DISABLE_COPY(AbstractPokitServicePrivate)
74 : QTPOKIT_BEFRIEND_TEST(AbstractPokitService)
75 : };
76 :
77 : QTPOKIT_END_NAMESPACE
78 :
79 : #endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H
|