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