LCOV - code coverage report
Current view: top level - src/lib - abstractpokitservice_p.h (source / functions) Hit Total Coverage
Project: Dokit Lines: 3 3 100.0 %
Version: Functions: 1 1 100.0 %

          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             : #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         414 :     Q_OBJECT
      28             : 
      29             : public:
      30        6288 :     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             :     /// \todo Use std::optional<PokitProduct> when we shift to C++17 (or later).
      35             :     PokitProduct pokitProduct { static_cast<PokitProduct>(255) }; ///< The Pokit product #controller is connected to.
      36             :     QLowEnergyService * service { nullptr };       ///< BLE service to read/write characteristics.
      37             :     QBluetoothUuid serviceUuid;                    ///< UUIDs for #service.
      38             : 
      39             :     AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid,
      40             :         QLowEnergyController * controller, AbstractPokitService * const q);
      41             : 
      42             :     bool createServiceObject();
      43             :     QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const;
      44             :     bool readCharacteristic(const QBluetoothUuid &uuid);
      45             : 
      46             :     bool enableCharacteristicNotificatons(const QBluetoothUuid &uuid);
      47             :     bool disableCharacteristicNotificatons(const QBluetoothUuid &uuid);
      48             : 
      49             :     static bool checkSize(const QString &label, const QByteArray &data, const int minSize,
      50             :                           const int maxSize=-1, const bool failOnMax=false);
      51             :     static QString toHexString(const QByteArray &data, const int maxSize=20);
      52             : 
      53             : protected:
      54             :     AbstractPokitService * q_ptr; ///< Internal q-pointer.
      55             : 
      56             : protected slots:
      57             :     void connected();
      58             :     void discoveryFinished();
      59             :     void errorOccurred(const QLowEnergyService::ServiceError newError);
      60             :     virtual void serviceDiscovered(const QBluetoothUuid &newService);
      61             :     void stateChanged(QLowEnergyService::ServiceState newState);
      62             : 
      63             :     virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic,
      64             :                                     const QByteArray &value);
      65             :     virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic,
      66             :                                        const QByteArray &newValue);
      67             :     virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic,
      68             :                                        const QByteArray &newValue);
      69             : 
      70             : private:
      71          54 :     Q_DECLARE_PUBLIC(AbstractPokitService)
      72             :     Q_DISABLE_COPY(AbstractPokitServicePrivate)
      73             :     friend class TestAbstractPokitService;
      74             : };
      75             : 
      76             : QTPOKIT_END_NAMESPACE
      77             : 
      78             : #endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H

Generated by: LCOV version 1.14