Dokit
Internal development documentation
Loading...
Searching...
No Matches
abstractpokitservice_p.h
Go to the documentation of this file.
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
14
15#include <QLoggingCategory>
16#include <QLowEnergyService>
17#include <QObject>
18
19#include <optional>
20
22
24
26
28{
29 Q_OBJECT
30
31public:
32 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
41 QLowEnergyController * controller, AbstractPokitService * const q);
42
43 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
56protected:
57 AbstractPokitService * q_ptr; ///< Internal q-pointer.
58
59protected 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
73private:
74 Q_DECLARE_PUBLIC(AbstractPokitService)
76 friend class TestAbstractPokitService;
77};
78
80
81#endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H
The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService.
static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg)
Logging category.
QBluetoothUuid serviceUuid
UUIDs for service.
AbstractPokitService * q_ptr
Internal q-pointer.
std::optional< PokitProduct > pokitProduct
The Pokit product controller is connected to.
The AbstractPokitService class provides a common base for Pokit services classes.
Declares the PokitProduct enumeration, and related helper functions.
Q_DISABLE_COPY(Class)
Q_SLOTSQ_SLOTS
Global QtPokit library macros.
#define QTPOKIT_BEGIN_NAMESPACE
Macro for starting the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_EXPORT
QtPokit library export/import macro.
#define QTPOKIT_END_NAMESPACE
Macro for ending the QtPokit library's top-most namespace (if one is defined).