Dokit
Internal development documentation
Loading...
Searching...
No Matches
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 descovery.
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
QString deviceToScanFor
Device (if any) that were passed to processOptions().
AbstractCommand(QObject *const parent=nullptr)
Constructs a new command with parent.
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
static quint32 parseNumber(const QString &value, const QString &unit, const quint32 sensibleMinimum=0)
Returns value as an integer multiple of the ratio R.
virtual void deviceDiscovered(const QBluetoothDeviceInfo &info)=0
Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
PokitDiscoveryAgent * discoveryAgent
Agent for Pokit device descovery.
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 QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
virtual void deviceDiscoveryFinished()=0
Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.
static QString escapeCsvField(const QString &field)
Returns an RFC 4180 compliant version of field.
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.
The PokitDiscoveryAgent class discovers nearby Pokit devices.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const
Global QtPokit library macros.
#define QTPOKIT_BEFRIEND_TEST(Class)
Macro for befriending a related unit test class, but only when QT_TESTLIB_LIB is defined.