Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
abstractcommand.h
1// SPDX-FileCopyrightText: 2022-2025 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
8
9#include <QBluetoothDeviceInfo>
10#include <QCommandLineParser>
11#include <QLoggingCategory>
12#include <QObject>
13
15
17{
19
20public:
21 /// Supported output formats.
22 enum class OutputFormat {
23 Csv, ///< RFC 4180 compliant CSV text.
24 Json, ///< RFC 8259 compliant JSON text.
25 Text, ///< Plain unstructured text.
26 };
27
28 explicit AbstractCommand(QObject * const parent = nullptr);
29
30 virtual QStringList requiredOptions(const QCommandLineParser &parser) const;
31 virtual QStringList supportedOptions(const QCommandLineParser &parser) const;
32
33 static QString escapeCsvField(const QString &field);
34
35 template<typename R>
36 static quint32 parseNumber(const QString &value, const QString &unit, const quint32 sensibleMinimum = 0);
37
38public slots:
39 virtual QStringList processOptions(const QCommandLineParser &parser);
40 virtual bool start() = 0;
41
42protected:
43 QString deviceToScanFor; ///< Device (if any) that were passed to processOptions().
44 PokitDiscoveryAgent * discoveryAgent; ///< Agent for Pokit device discovery.
45 OutputFormat format { OutputFormat::Text }; ///< Selected output format.
46 static Q_LOGGING_CATEGORY(lc, "dokit.cli.command", QtInfoMsg); ///< Logging category for UI commands.
47
48protected slots:
49 virtual void deviceDiscovered(const QBluetoothDeviceInfo &info) = 0;
50 virtual void deviceDiscoveryFinished() = 0;
51
53};
54
55#endif // DOKIT_ABSTRACTCOMMAND_H
The AbstractCommand class provides a consistent base for the classes that implement CLI commands.
QString deviceToScanFor
Device (if any) that were passed to processOptions().
AbstractCommand(QObject *const parent=nullptr)
Constructs a new command with parent.
virtual void deviceDiscovered(const QBluetoothDeviceInfo &info)=0
Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
PokitDiscoveryAgent * discoveryAgent
Agent for Pokit device discovery.
OutputFormat format
Selected output format.
OutputFormat
Supported output formats.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
static Q_LOGGING_CATEGORY(lc, "dokit.cli.command", QtInfoMsg)
Logging category for UI commands.
virtual bool start()=0
Begins the functionality of this command, and returns true if begun successfully, false otherwise.
virtual void deviceDiscoveryFinished()=0
Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.
The PokitDiscoveryAgent class discovers nearby Pokit devices.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Global QtPokit library macros.
#define QTPOKIT_FORWARD_DECLARE_CLASS(name)
Macro for forward declaring classes in the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_BEFRIEND_TEST(Class)
Macro for befriending a related unit test class, but only when QT_TESTLIB_LIB is defined.