Dokit
Internal development documentation
Loading...
Searching...
No Matches
ScanCommand Class Reference

The ScanCommand class implements the scan CLI command, by scanning for nearby Pokit Bluetooth devices. More...

Inheritance diagram for ScanCommand:
[legend]
Collaboration diagram for ScanCommand:
[legend]

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 QMetaObjectmetaObject () 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)
 
QThreadthread () 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)
 
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 &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () 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< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 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
QObjectsender () 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().
 
PokitDiscoveryAgentdiscoveryAgent
 Agent for Pokit device descovery.
 
OutputFormat format { OutputFormat::Text }
 Selected output format.
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ScanCommand()

ScanCommand::ScanCommand ( QObject *const parent = nullptr)
explicit

Construct a new ScanCommand object with parent.

Definition at line 25 of file scancommand.cpp.

26{
27 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
30 #endif
31}
AbstractCommand(QObject *const parent=nullptr)
Constructs a new command with parent.
PokitDiscoveryAgent * discoveryAgent
Agent for Pokit device descovery.
void pokitDeviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
This signal is emitted when the Pokit device described by info is updated.
void deviceUpdated(const QBluetoothDeviceInfo &info, const QBluetoothDeviceInfo::Fields updatedFields)
Handles updated Pokit devices, writing info to stdout.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const

References QObject::connect(), deviceUpdated(), AbstractCommand::discoveryAgent, and PokitDiscoveryAgent::pokitDeviceUpdated().

Here is the call graph for this function:

Member Function Documentation

◆ deviceDiscovered

void ScanCommand::deviceDiscovered ( const QBluetoothDeviceInfo & info)
overrideprotectedslot

Handles discovered Pokit devices, writing info to stdout.

Definition at line 69 of file scancommand.cpp.

70{
71 switch (format) {
73 for (; showCsvHeader; showCsvHeader = false) {
74 std::cout << qUtf8Printable(tr("uuid,address,name,major_class,minor_class,signal_strength\n"));
75 }
76 std::cout << qUtf8Printable(QString::fromLatin1("%1,%2,%3,%4,%5,%6\n").arg(info.deviceUuid().toString(),
78 toString(info.majorDeviceClass(), info.minorDeviceClass())).arg(info.rssi()));
79 break;
81 std::cout << QJsonDocument(toJson(info)).toJson().toStdString();
82 break;
84 std::cout << qUtf8Printable(tr("%1 %2 %3 %4\n").arg(info.deviceUuid().toString(),
85 info.address().toString(), info.name()).arg(info.rssi()));
86 break;
87 }
88}
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
static QString escapeCsvField(const QString &field)
Returns an RFC 4180 compliant version of field.
static QJsonObject toJson(const QBluetoothDeviceInfo &info)
Returns info as a JSON object.
static QString toString(const QBluetoothDeviceInfo::MajorDeviceClass &majorClass)
Returns majorClass as a human-readable string, or a null QString if majorClass is not recognised.
bool showCsvHeader
Whether or not to show a header as the first line of CSV output.
Definition scancommand.h:29
QString toString() const const
QBluetoothAddress address() const const
QBluetoothUuid deviceUuid() const const
QBluetoothDeviceInfo::MajorDeviceClass majorDeviceClass() const const
quint8 minorDeviceClass() const const
QString name() const const
qint16 rssi() const const
std::string toStdString() const const
QByteArray toJson() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
QString toString() const const

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deviceDiscoveryFinished

void ScanCommand::deviceDiscoveryFinished ( )
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.

107{
108 qCDebug(lc).noquote() << tr("Finished scanning for Pokit devices.");
110}

References QCoreApplication::quit(), and QObject::tr().

Here is the call graph for this function:

◆ deviceUpdated

void ScanCommand::deviceUpdated ( const QBluetoothDeviceInfo & info,
const QBluetoothDeviceInfo::Fields updatedFields )
protectedslot

Handles updated Pokit devices, writing info to stdout.

Currently updatedFields us unused.

Definition at line 94 of file scancommand.cpp.

96{
97 Q_UNUSED(updatedFields)
98 deviceDiscovered(info);
99}
void deviceDiscovered(const QBluetoothDeviceInfo &info) override
Handles discovered Pokit devices, writing info to stdout.

References deviceDiscovered().

Referenced by ScanCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processOptions

QStringList ScanCommand::processOptions ( const QCommandLineParser & parser)
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:

QStringList CustomCommand::processOptions(const QCommandLineParser &parser)
{
if (!errors.isEmpty()) {
return errors;
}
// Do further procession of options.
return errors;
}
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
bool isEmpty() const const

Definition at line 45 of file scancommand.cpp.

46{
48 if (!errors.isEmpty()) {
49 return errors;
50 }
51
52 return errors;
53}

References QList::isEmpty(), and AbstractCommand::processOptions().

Here is the call graph for this function:

◆ requiredOptions()

QStringList ScanCommand::requiredOptions ( const QCommandLineParser & parser) const
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.

34{
36}
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.

References AbstractCommand::requiredOptions().

Here is the call graph for this function:

◆ start

bool ScanCommand::start ( )
overrideslot

Begins scanning for Pokit devices.

Definition at line 58 of file scancommand.cpp.

59{
60 Q_ASSERT(discoveryAgent);
61 qCInfo(lc).noquote() << tr("Scanning for Pokit devices...");
63 return true;
64}
void start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
Starts Pokit device discovery.

References AbstractCommand::discoveryAgent, PokitDiscoveryAgent::start(), and QObject::tr().

Here is the call graph for this function:

◆ supportedOptions()

QStringList ScanCommand::supportedOptions ( const QCommandLineParser & parser) const
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:

QStringList Derived::supportedOptions(const QCommandLineParser &parser) const
{
list.sort();
list.removeDuplicates(); // Optional, recommended.
return list;
}
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
int removeDuplicates()
void sort(Qt::CaseSensitivity cs)

Reimplemented from AbstractCommand.

Definition at line 38 of file scancommand.cpp.

39{
41 };
42}

References AbstractCommand::supportedOptions().

Here is the call graph for this function:

◆ toJson() [1/7]

QJsonObject ScanCommand::toJson ( const QBluetoothDeviceInfo & info)
staticprivate

Returns info as a JSON object.

Definition at line 115 of file scancommand.cpp.

116{
117 if (!info.isValid()) {
118 return QJsonObject();
119 }
120 QJsonObject json{
121 { QLatin1String("address"), info.address().toString() },
122 { QLatin1String("name"), info.name() },
123 { QLatin1String("isCached"), info.isCached() },
124 { QLatin1String("majorDeviceClass"), info.majorDeviceClass() },
125 { QLatin1String("majorDeviceClass"), toJson(info.majorDeviceClass()) },
126 { QLatin1String("minorDeviceClass"), toJson(info.majorDeviceClass(), info.minorDeviceClass()) },
127 { QLatin1String("signalStrength"), info.rssi() },
128 };
130 json.insert(QLatin1String("coreConfiguration"), toJson(info.coreConfigurations()));
131 }
132 if (!info.deviceUuid().isNull()) {
133 json.insert(QLatin1String("deviceUuid"), info.deviceUuid().toString());
134 }
135 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Added in Qt 5.12.
136 if (!info.manufacturerData().isEmpty()) {
137 json.insert(QLatin1String("manufacturerData"), toJson(info.manufacturerData()));
138 }
139 #endif
141 json.insert(QLatin1String("serviceClasses"), toJson(info.serviceClasses()));
142 }
143 if (!info.serviceUuids().isEmpty()) {
144 json.insert(QLatin1String("serviceUuids"), toJson(info.serviceUuids()));
145 }
146 return json;
147}
QBluetoothDeviceInfo::CoreConfigurations coreConfigurations() const const
bool isCached() const const
bool isValid() const const
QByteArray manufacturerData(quint16 manufacturerId) const const
QBluetoothDeviceInfo::ServiceClasses serviceClasses() const const
QList< QBluetoothUuid > serviceUuids(QBluetoothDeviceInfo::DataCompleteness *completeness) const const
bool isEmpty() const const
bool isNull() const const

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toJson() [2/7]

QJsonArray ScanCommand::toJson ( const QBluetoothDeviceInfo::CoreConfigurations & configurations)
staticprivate

Returns configuration as a JSON array of strings.

Definition at line 152 of file scancommand.cpp.

153{
154 QJsonArray array;
155 #define DOKIT_INTERNAL_IF_SET_THEN_APPEND(flag) \
156 if (configurations.testFlag(QBluetoothDeviceInfo::flag)) \
157 array.append(QLatin1String(#flag))
158 DOKIT_INTERNAL_IF_SET_THEN_APPEND(UnknownCoreConfiguration);
159 DOKIT_INTERNAL_IF_SET_THEN_APPEND(LowEnergyCoreConfiguration);
160 DOKIT_INTERNAL_IF_SET_THEN_APPEND(BaseRateCoreConfiguration);
161 //DOKIT_INTERNAL_IF_SET_THEN_APPEND(BaseRateAndLowEnergyCoreConfiguration); // Combination flag.
162 #undef DOKIT_INTERNAL_IF_SET_THEN_APPEND
163 return array;
164}

◆ toJson() [3/7]

QJsonValue ScanCommand::toJson ( const QBluetoothDeviceInfo::MajorDeviceClass & majorClass)
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).

See also
toString(const QBluetoothDeviceInfo::MajorDeviceClass &majorClass)

Definition at line 172 of file scancommand.cpp.

173{
174 const QString string = toString(majorClass);
175 return (string.isNull() ? QJsonValue(majorClass) : QJsonValue(string));
176}

References toString().

Here is the call graph for this function:

◆ toJson() [4/7]

QJsonValue ScanCommand::toJson ( const QBluetoothDeviceInfo::MajorDeviceClass & majorClass,
const quint8 minorClass )
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).

See also
toString(const QBluetoothDeviceInfo::MajorDeviceClass &majorClass, const quint8 minorClass)

Definition at line 185 of file scancommand.cpp.

186{
187 const QString string = toString(majorClass, minorClass);
188 return (string.isNull() ? QJsonValue(minorClass) : QJsonValue(string));
189}

References toString().

Here is the call graph for this function:

◆ toJson() [5/7]

QJsonArray ScanCommand::toJson ( const QBluetoothDeviceInfo::ServiceClasses & classes)
staticprivate

Returns classes as a JSON array of strings.

Definition at line 194 of file scancommand.cpp.

195{
196 QJsonArray array;
197 #define DOKIT_INTERNAL_IF_SET_THEN_APPEND(flag) \
198 if (classes.testFlag(QBluetoothDeviceInfo::flag)) \
199 array.append(QLatin1String(#flag))
200 DOKIT_INTERNAL_IF_SET_THEN_APPEND(PositioningService);
201 DOKIT_INTERNAL_IF_SET_THEN_APPEND(NetworkingService);
202 DOKIT_INTERNAL_IF_SET_THEN_APPEND(RenderingService);
203 DOKIT_INTERNAL_IF_SET_THEN_APPEND(CapturingService);
204 DOKIT_INTERNAL_IF_SET_THEN_APPEND(ObjectTransferService);
205 DOKIT_INTERNAL_IF_SET_THEN_APPEND(AudioService);
206 DOKIT_INTERNAL_IF_SET_THEN_APPEND(TelephonyService);
207 DOKIT_INTERNAL_IF_SET_THEN_APPEND(InformationService);
208 #undef DOKIT_INTERNAL_IF_SET_THEN_APPEND
209 return array;
210}

◆ toJson() [6/7]

QJsonArray ScanCommand::toJson ( const QList< QBluetoothUuid > & uuids)
staticprivate

Returns uuids as a JSON array.

Definition at line 215 of file scancommand.cpp.

216{
217 QJsonArray array;
218 for (const QBluetoothUuid &uuid: uuids) {
219 array.append(uuid.toString());
220 }
221 return array;
222}
void append(const QJsonValue &value)

References QJsonArray::append().

Here is the call graph for this function:

◆ toJson() [7/7]

QJsonObject ScanCommand::toJson ( const QMultiHash< quint16, QByteArray > & data)
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.

229{
230 QJsonObject object;
231 QList<quint16> keys = data.uniqueKeys();
232 std::sort(keys.begin(), keys.end());
233 for (const quint16 key: keys) {
234 // Convert the key's values to a JSON array, reversing the order, because QMultiHash
235 // guarantees that the values are orderer "from the most recently inserted to the least
236 // recently inserted", which is the oppoosit of what we want.
237 QList<QByteArray> values = data.values(key);
238 std::reverse(values.begin(), values.end());
239 QJsonArray array;
240 for (const QByteArray &value: values) {
241 array.append(QLatin1String(value.toBase64()));
242 }
243 object.insert(QString::number(key), array);
244 }
245 return object;
246}
QList::iterator begin()
QList::iterator end()
QList< Key > uniqueKeys() const const
QList< T > values(const Key &key) const const
QString number(int n, int base)

References QJsonArray::append(), QList::begin(), QList::end(), QString::number(), QMultiHash::uniqueKeys(), and QMultiHash::values().

Here is the call graph for this function:

◆ toString() [1/2]

QString ScanCommand::toString ( const QBluetoothDeviceInfo::MajorDeviceClass & majorClass)
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.

256{
257 #define DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(value) \
258 if (majorClass == QBluetoothDeviceInfo::value) \
259 return QLatin1String(#value)
260 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(MiscellaneousDevice);
261 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ComputerDevice);
262 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(PhoneDevice);
263 #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
264 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(LANAccessDevice); // Deprecated since Qt 5.13.
265 #else
266 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkDevice); // Added in Qt 5.13.
267 #endif
268 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(AudioVideoDevice);
269 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(PeripheralDevice);
270 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ImagingDevice);
271 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableDevice);
272 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyDevice);
273 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthDevice);
274 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedDevice);
275 #undef DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN
276 qCDebug(lc).noquote() << tr("Unknown major class %1.").arg(majorClass);
277 return QString(); // Null QString indicates unknown minor class.
278}

References QString::arg(), and QObject::tr().

Referenced by deviceDiscovered(), toJson(), and toJson().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString() [2/2]

QString ScanCommand::toString ( const QBluetoothDeviceInfo::MajorDeviceClass & majorClass,
const quint8 minorClass )
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.

288{
289 #define DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(value) \
290 if (minorClass == QBluetoothDeviceInfo::value) \
291 return QLatin1String(#value)
292 switch (majorClass) {
294 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedMiscellaneous);
295 break;
297 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedComputer);
298 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(DesktopComputer);
299 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ServerComputer);
300 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(LaptopComputer);
301 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HandheldClamShellComputer);
302 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HandheldComputer);
303 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableComputer);
304 break;
306 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedPhone);
307 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(CellularPhone);
308 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(CordlessPhone);
309 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(SmartPhone);
310 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WiredModemOrVoiceGatewayPhone);
311 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(CommonIsdnAccessPhone);
312 break;
313 #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
314 case QBluetoothDeviceInfo::LANAccessDevice: // Deprecated since Qt 5.13.
315 #else
316 case QBluetoothDeviceInfo::NetworkDevice: // Added in Qt 5.13.
317 #endif
318 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkFullService);
319 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorOne);
320 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorTwo);
321 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorThree);
322 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorFour);
323 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorFive);
324 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkLoadFactorSix);
325 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(NetworkNoService);
326 break;
328 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedAudioVideoDevice);
329 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableHeadsetDevice);
330 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HandsFreeDevice);
331 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(Microphone);
332 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(Loudspeaker);
333 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(Headphones);
334 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(PortableAudioDevice);
335 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(CarAudio);
336 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(SetTopBox);
337 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HiFiAudioDevice);
338 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(Vcr);
339 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(VideoCamera);
340 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(Camcorder);
341 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(VideoMonitor);
342 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(VideoDisplayAndLoudspeaker);
343 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(VideoConferencing);
344 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(GamingDevice);
345 break;
347 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedPeripheral);
348 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(KeyboardPeripheral);
349 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(PointingDevicePeripheral);
350 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(KeyboardWithPointingDevicePeripheral);
351 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(JoystickPeripheral);
352 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(GamepadPeripheral);
353 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(RemoteControlPeripheral);
354 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(SensingDevicePeripheral);
355 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(DigitizerTabletPeripheral);
356 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(CardReaderPeripheral);
357 break;
359 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedImagingDevice);
360 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ImageDisplay);
361 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ImageCamera);
362 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ImageScanner);
363 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ImagePrinter);
364 break;
366 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedWearableDevice);
367 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableWristWatch);
368 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearablePager);
369 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableJacket);
370 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableHelmet);
371 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(WearableGlasses);
372 break;
374 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedToy);
375 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyRobot);
376 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyVehicle);
377 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyDoll);
378 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyController);
379 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(ToyGame);
380 break;
382 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(UncategorizedHealthDevice);
383 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthBloodPressureMonitor);
384 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthThermometer);
385 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthWeightScale);
386 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthGlucoseMeter);
387 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthPulseOximeter);
388 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthDataDisplay);
389 DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN(HealthStepCounter);
390 break;
392 // There are no minor classes defined (in Qt) for uncategorized devices.
393 break;
394 }
395 #undef DOKIT_INTERNAL_IF_EQUAL_THEN_RETURN
396 qCDebug(lc).noquote() << tr("Unknown minor class %1 for major class %2.")
397 .arg(minorClass).arg(majorClass);
398 return QString(); // Null QString indicates unknown minor class.
399}

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.

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ TestScanCommand

friend class TestScanCommand
friend

Definition at line 42 of file scancommand.h.

Member Data Documentation

◆ showCsvHeader

bool ScanCommand::showCsvHeader { true }
private

Whether or not to show a header as the first line of CSV output.

Definition at line 29 of file scancommand.h.

29{ true }; ///< Whether or not to show a header as the first line of CSV output.

Referenced by deviceDiscovered().


The documentation for this class was generated from the following files: