LCOV - code coverage report
Current view: top level - src/cli - abstractcommand.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             : #ifndef DOKIT_ABSTRACTCOMMAND_H
       5             : #define DOKIT_ABSTRACTCOMMAND_H
       6             : 
       7             : #include <QBluetoothDeviceInfo>
       8             : #include <QCommandLineParser>
       9             : #include <QLoggingCategory>
      10             : #include <QObject>
      11             : 
      12             : class PokitDiscoveryAgent;
      13             : 
      14        7593 : class AbstractCommand : public QObject
      15             : {
      16         396 :     Q_OBJECT
      17             : 
      18             : public:
      19             :     enum class OutputFormat {
      20             :         Csv,  ///< RFC 4180 compliant CSV text.
      21             :         Json, ///< RFC 8259 compliant JSON text.
      22             :         Text, ///< Plain unstructured text.
      23             :     };
      24             : 
      25             :     explicit AbstractCommand(QObject * const parent);
      26             : 
      27             :     virtual QStringList requiredOptions(const QCommandLineParser &parser) const;
      28             :     virtual QStringList supportedOptions(const QCommandLineParser &parser) const;
      29             : 
      30             :     static QString escapeCsvField(const QString &field);
      31             :     static quint32 parseMicroValue(const QString &value, const QString &unit,
      32             :                                    const quint32 sensibleMinimum=0);
      33             :     static quint32 parseMilliValue(const QString &value, const QString &unit,
      34             :                                    const quint32 sensibleMinimum=0);
      35             :     static quint32 parseWholeValue(const QString &value, const QString &unit);
      36             : 
      37             : public slots:
      38             :     virtual QStringList processOptions(const QCommandLineParser &parser);
      39             :     virtual bool start() = 0;
      40             : 
      41             : protected:
      42             :     QString deviceToScanFor; ///< Device (if any) that were passed to processOptions().
      43             :     PokitDiscoveryAgent * discoveryAgent; ///< Agent for Pokit device descovery.
      44             :     OutputFormat format { OutputFormat::Text }; ///< Selected output format.
      45       28154 :     static Q_LOGGING_CATEGORY(lc, "dokit.cli.command", QtInfoMsg); ///< Logging category for UI commands.
      46             : 
      47             : protected slots:
      48             :     virtual void deviceDiscovered(const QBluetoothDeviceInfo &info) = 0;
      49             :     virtual void deviceDiscoveryFinished() = 0;
      50             : 
      51             :     friend class TestAbstractCommand;
      52             : };
      53             : 
      54             : #endif // DOKIT_ABSTRACTCOMMAND_H

Generated by: LCOV version 1.14