Dokit
Internal development documentation
|
The ScanCommand class implements the scan
CLI command, by scanning for nearby Pokit Bluetooth devices.
More...
Public Slots | |
QStringList | processOptions (const QCommandLineParser &parser) override |
Processes the relevant options from the command line parser. | |
bool | start () override |
Begins scanning for Pokit devices. | |
Public Slots inherited from AbstractCommand | |
virtual QStringList | processOptions (const QCommandLineParser &parser) |
Processes the relevant options from the command line parser. | |
virtual bool | start ()=0 |
Begins the functionality of this command, and returns true if begun successfully, false otherwise. | |
Public Member Functions | |
ScanCommand (QObject *const parent=nullptr) | |
Construct a new ScanCommand object with parent. | |
QStringList | requiredOptions (const QCommandLineParser &parser) const override |
Returns a list of CLI option names required by this command. | |
QStringList | supportedOptions (const QCommandLineParser &parser) const override |
Returns a list of CLI option names supported by this command. | |
Public Member Functions inherited from AbstractCommand | |
AbstractCommand (QObject *const parent=nullptr) | |
Constructs a new command with parent. | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Q_DISABLE_COPY (Class) | |
Q_DISABLE_MOVE (Class) | |
Q_DISABLE_COPY_MOVE (Class) | |
T | qobject_cast (QObject *object) |
T | qobject_cast (const QObject *object) |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
Q_CLASSINFO (Name, Value) | |
Q_INTERFACES (...) | |
Q_PROPERTY (...) | |
Q_ENUMS (...) | |
Q_FLAGS (...) | |
Q_ENUM (...) | |
Q_FLAG (...) | |
Q_ENUM_NS (...) | |
Q_FLAG_NS (...) | |
Q_OBJECT Q_OBJECT | |
Q_GADGET Q_GADGET | |
Q_NAMESPACE Q_NAMESPACE | |
Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
Q_SIGNALS Q_SIGNALS | |
Q_SIGNAL Q_SIGNAL | |
Q_SLOTS Q_SLOTS | |
Q_SLOT Q_SLOT | |
Q_EMIT Q_EMIT | |
Q_INVOKABLE Q_INVOKABLE | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
Protected Slots | |
void | deviceDiscovered (const QBluetoothDeviceInfo &info) override |
Handles discovered Pokit devices, writing info to stdout. | |
void | deviceUpdated (const QBluetoothDeviceInfo &info, const QBluetoothDeviceInfo::Fields updatedFields) |
Handles updated Pokit devices, writing info to stdout. | |
void | deviceDiscoveryFinished () override |
Handles the completion of device discovery. | |
Protected Slots inherited from AbstractCommand | |
virtual void | deviceDiscovered (const QBluetoothDeviceInfo &info)=0 |
Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal. | |
virtual void | deviceDiscoveryFinished ()=0 |
Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal. | |
Static Private Member Functions | |
static QJsonObject | toJson (const QBluetoothDeviceInfo &info) |
Returns info as a JSON object. | |
static QJsonArray | toJson (const QBluetoothDeviceInfo::CoreConfigurations &configurations) |
Returns configuration as a JSON array of strings. | |
static QJsonValue | toJson (const QBluetoothDeviceInfo::MajorDeviceClass &majorClass) |
Returns majorClass as a JSON value. | |
static QJsonValue | toJson (const QBluetoothDeviceInfo::MajorDeviceClass &majorClass, const quint8 minorClass) |
Returns minorClass as a JSON value. | |
static QJsonArray | toJson (const QBluetoothDeviceInfo::ServiceClasses &classes) |
Returns classes as a JSON array of strings. | |
static QJsonArray | toJson (const QList< QBluetoothUuid > &uuids) |
Returns uuids as a JSON array. | |
static QJsonObject | toJson (const QMultiHash< quint16, QByteArray > &data) |
Returns Bluetooth manufacturer data as a JSON object that maps the manufacturer IDs (unsigned integers as strings) to arrays of one or more values. | |
static QString | toString (const QBluetoothDeviceInfo::MajorDeviceClass &majorClass) |
Returns majorClass as a human-readable string, or a null QString if majorClass is not recognised. | |
static QString | toString (const QBluetoothDeviceInfo::MajorDeviceClass &majorClass, const quint8 minorClass) |
Returns minorClass as a human-readable string, or a null QString if minorClass is not recognised as a sub-class of majorClass. | |
Private Attributes | |
bool | showCsvHeader { true } |
Whether or not to show a header as the first line of CSV output. | |
Friends | |
class | TestScanCommand |
Additional Inherited Members | |
Public Types inherited from AbstractCommand | |
enum class | OutputFormat { Csv , Json , Text } |
Supported output formats. More... | |
Static Public Member Functions inherited from AbstractCommand | |
static QString | escapeCsvField (const QString &field) |
Returns an RFC 4180 compliant version of field. | |
template<typename R > | |
static quint32 | parseNumber (const QString &value, const QString &unit, const quint32 sensibleMinimum=0) |
Returns value as an integer multiple of the ratio R. | |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Public Attributes inherited from QObject | |
typedef | QObjectList |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Static Protected Member Functions inherited from AbstractCommand | |
static | Q_LOGGING_CATEGORY (lc, "dokit.cli.command", QtInfoMsg) |
Logging category for UI commands. | |
Protected Attributes inherited from AbstractCommand | |
QString | deviceToScanFor |
Device (if any) that were passed to processOptions(). | |
PokitDiscoveryAgent * | discoveryAgent |
Agent for Pokit device descovery. | |
OutputFormat | format { OutputFormat::Text } |
Selected output format. | |
Properties inherited from QObject | |
objectName | |
The ScanCommand class implements the scan
CLI command, by scanning for nearby Pokit Bluetooth devices.
When devices are found, they are logged to stdout in the chosen format.
Definition at line 6 of file scancommand.h.
|
explicit |
Construct a new ScanCommand object with parent.
Definition at line 25 of file scancommand.cpp.
References QObject::connect(), deviceUpdated(), AbstractCommand::discoveryAgent, and PokitDiscoveryAgent::pokitDeviceUpdated().
|
overrideprotectedslot |
Handles discovered Pokit devices, writing info to stdout.
Definition at line 69 of file scancommand.cpp.
References QBluetoothDeviceInfo::address(), QString::arg(), AbstractCommand::Csv, QBluetoothDeviceInfo::deviceUuid(), AbstractCommand::escapeCsvField(), AbstractCommand::format, QString::fromLatin1(), AbstractCommand::Json, QBluetoothDeviceInfo::majorDeviceClass(), QBluetoothDeviceInfo::minorDeviceClass(), QBluetoothDeviceInfo::name(), QBluetoothDeviceInfo::rssi(), showCsvHeader, AbstractCommand::Text, QJsonDocument::toJson(), toJson(), QByteArray::toStdString(), QBluetoothAddress::toString(), QUuid::toString(), toString(), and QObject::tr().
Referenced by deviceUpdated().
|
overrideprotectedslot |
Handles the completion of device discovery.
In this override we simply exit, as the scan command is nothing more than logging of discovered devices.
Definition at line 106 of file scancommand.cpp.
References QCoreApplication::quit(), and QObject::tr().
|
protectedslot |
Handles updated Pokit devices, writing info to stdout.
Currently updatedFields us unused.
Definition at line 94 of file scancommand.cpp.
References deviceDiscovered().
Referenced by ScanCommand().
|
overrideslot |
Processes the relevant options from the command line parser.
On success, returns an empty QStringList, otherwise returns a list of CLI errors that the caller should report appropriately before exiting.
This base implementations performs some common checks, such as ensuring that required options are present. Derived classes should override this function to perform further processing, typically inovking this base implementation as a first step, such as:
Definition at line 45 of file scancommand.cpp.
References QList::isEmpty(), and AbstractCommand::processOptions().
|
overridevirtual |
Returns a list of CLI option names required by this command.
The main console appication may use this list to output an eror (and exit) if any of the returned names are not found in the parsed CLI options.
The (already parsed) parser may be used adjust the returned required options depending on the value of other options. For example, the logger
command only requires the --mode
option if the --command
option is start
.
This base implementation simply returns an empty list. Derived classes should override this function to include any required options.
Reimplemented from AbstractCommand.
Definition at line 33 of file scancommand.cpp.
References AbstractCommand::requiredOptions().
|
overrideslot |
Begins scanning for Pokit devices.
Definition at line 58 of file scancommand.cpp.
References AbstractCommand::discoveryAgent, PokitDiscoveryAgent::start(), and QObject::tr().
|
overridevirtual |
Returns a list of CLI option names supported by this command.
The main console appication may use this list to output a warning for any parsed CLI options not included in the returned list.
The (already parsed) parser may be used adjust the returned supported options depending on the value of other options. For example, the logger
command only supported the --timestamp
option if the --command
option is start
.
This base implementation simply returns requiredOptions(). Derived classes should override this function to include optional options, such as:
Reimplemented from AbstractCommand.
Definition at line 38 of file scancommand.cpp.
References AbstractCommand::supportedOptions().
|
staticprivate |
Returns info as a JSON object.
Definition at line 115 of file scancommand.cpp.
References QBluetoothDeviceInfo::address(), QBluetoothDeviceInfo::coreConfigurations(), QBluetoothDeviceInfo::deviceUuid(), QBluetoothDeviceInfo::isCached(), QByteArray::isEmpty(), QUuid::isNull(), QBluetoothDeviceInfo::isValid(), QBluetoothDeviceInfo::majorDeviceClass(), QBluetoothDeviceInfo::manufacturerData(), QBluetoothDeviceInfo::minorDeviceClass(), QBluetoothDeviceInfo::name(), QBluetoothDeviceInfo::NoService, QBluetoothDeviceInfo::rssi(), QBluetoothDeviceInfo::serviceClasses(), QBluetoothDeviceInfo::serviceUuids(), toJson(), QBluetoothAddress::toString(), QUuid::toString(), and QBluetoothDeviceInfo::UnknownCoreConfiguration.
Referenced by deviceDiscovered(), and toJson().
|
staticprivate |
Returns configuration as a JSON array of strings.
Definition at line 152 of file scancommand.cpp.
|
staticprivate |
Returns majorClass as a JSON value.
This is equivalent to toString, except that if toString does not recognise majorClass, then majorClass is returned as a JSON number (not a string).
Definition at line 172 of file scancommand.cpp.
References toString().
|
staticprivate |
Returns minorClass as a JSON value.
This is equivalent to toString, except that if toString does not recognise minorClass as a sub-class of majorClass, then minorClass is returned as a JSON number (not a string).
Definition at line 185 of file scancommand.cpp.
References toString().
|
staticprivate |
Returns classes as a JSON array of strings.
Definition at line 194 of file scancommand.cpp.
|
staticprivate |
Returns uuids as a JSON array.
Definition at line 215 of file scancommand.cpp.
References QJsonArray::append().
|
staticprivate |
Returns Bluetooth manufacturer data as a JSON object that maps the manufacturer IDs (unsigned integers as strings) to arrays of one or more values.
Definition at line 228 of file scancommand.cpp.
References QJsonArray::append(), QList::begin(), QList::end(), QString::number(), QMultiHash::uniqueKeys(), and QMultiHash::values().
|
staticprivate |
Returns majorClass as a human-readable string, or a null QString if majorClass is not recognised.
For example, if majorClass is QBluetoothDeviceInfo::ToyDevice
, then the string ToyDevice
is returned.
Definition at line 255 of file scancommand.cpp.
References QString::arg(), and QObject::tr().
Referenced by deviceDiscovered(), toJson(), and toJson().
|
staticprivate |
Returns minorClass as a human-readable string, or a null QString if minorClass is not recognised as a sub-class of majorClass.
For example, if majorClass is QBluetoothDeviceInfo::ToyDevice
, and minorClass is QBluetoothDeviceInfo::ToyRobot
, then the string ToyRobot
is returned.
Definition at line 287 of file scancommand.cpp.
References QString::arg(), QBluetoothDeviceInfo::AudioVideoDevice, QBluetoothDeviceInfo::ComputerDevice, QBluetoothDeviceInfo::HealthDevice, QBluetoothDeviceInfo::ImagingDevice, QBluetoothDeviceInfo::LANAccessDevice, QBluetoothDeviceInfo::MiscellaneousDevice, QBluetoothDeviceInfo::NetworkDevice, QBluetoothDeviceInfo::PeripheralDevice, QBluetoothDeviceInfo::PhoneDevice, QBluetoothDeviceInfo::ToyDevice, QObject::tr(), QBluetoothDeviceInfo::UncategorizedDevice, and QBluetoothDeviceInfo::WearableDevice.
|
friend |
Definition at line 42 of file scancommand.h.
|
private |
Whether or not to show a header as the first line of CSV output.
Definition at line 29 of file scancommand.h.
Referenced by deviceDiscovered().