Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbluetoothserviceinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QUrl>
8
10
14 QBluetoothServiceInfo__Alternative)
15
16
131{
132 return d_ptr->isRegistered();
133}
134
151{
152#ifdef QT_OSX_BLUETOOTH
153 Q_UNUSED(localAdapter);
154 return d_ptr->registerService(*this);
155#else
156 return d_ptr->registerService(localAdapter);
157#endif
158}
159
173
174
326{
327 qRegisterMetaType<QBluetoothServiceInfo>();
328}
329
340
347
354{
355 return !d_ptr->attributes.isEmpty();
356}
357
367
375
383
396{
397 d_ptr->attributes[attributeId] = value;
398}
399
404{
405 return d_ptr->attributes.value(attributeId);
406}
407
412{
413 return d_ptr->attributes.keys();
414}
415
421{
422 return d_ptr->attributes.contains(attributeId);
423}
424
432{
433 d_ptr->attributes.remove(attributeId);
434}
435
451
461{
463
464 if (parameters.isEmpty())
465 return -1;
466 else if (parameters.size() == 1)
467 return 0;
468 else
469 return parameters.at(1).toUInt();
470}
471
481{
482 return d_ptr->serverChannel();
483}
484
494
504QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const
505{
506 QList<QBluetoothUuid> results;
507
509 if (!var.isValid())
510 return results;
511
513 for (qsizetype i = 0; i < seq.size(); ++i)
515
516 return results;
517}
518
529
530static void dumpAttributeVariant(QDebug dbg, const QVariant &var, const QString& indent)
531{
532 switch (var.typeId()) {
533 case QMetaType::Void:
534 dbg << QString::asprintf("%sEmpty\n", indent.toUtf8().constData());
535 break;
536 case QMetaType::UChar:
537 dbg << QString::asprintf("%suchar %u\n", indent.toUtf8().constData(), var.toUInt());
538 break;
539 case QMetaType::UShort:
540 dbg << QString::asprintf("%sushort %u\n", indent.toUtf8().constData(), var.toUInt());
541 break;
542 case QMetaType::UInt:
543 dbg << QString::asprintf("%suint %u\n", indent.toUtf8().constData(), var.toUInt());
544 break;
545 case QMetaType::Char:
546 dbg << QString::asprintf("%schar %d\n", indent.toUtf8().constData(), var.toInt());
547 break;
548 case QMetaType::Short:
549 dbg << QString::asprintf("%sshort %d\n", indent.toUtf8().constData(), var.toInt());
550 break;
551 case QMetaType::Int:
552 dbg << QString::asprintf("%sint %d\n", indent.toUtf8().constData(), var.toInt());
553 break;
554 case QMetaType::QString:
555 dbg << QString::asprintf("%sstring %s\n", indent.toUtf8().constData(),
557 break;
558 case QMetaType::QByteArray:
559 dbg << QString::asprintf("%sbytearray %s\n", indent.toUtf8().constData(),
561 break;
562 case QMetaType::Bool:
563 dbg << QString::asprintf("%sbool %d\n", indent.toUtf8().constData(), var.toBool());
564 break;
565 case QMetaType::QUrl:
566 dbg << QString::asprintf("%surl %s\n", indent.toUtf8().constData(),
568 break;
569 default:
570 if (var.typeId() == qMetaTypeId<QBluetoothUuid>()) {
572 switch (uuid.minimumSize()) {
573 case 0:
574 dbg << QString::asprintf("%suuid NULL\n", indent.toUtf8().constData());
575 break;
576 case 2:
577 dbg << QString::asprintf("%suuid2 %04x\n", indent.toUtf8().constData(),
578 uuid.toUInt16());
579 break;
580 case 4:
581 dbg << QString::asprintf("%suuid %08x\n", indent.toUtf8().constData(),
582 uuid.toUInt32());
583 break;
584 case 16:
585 dbg << QString::asprintf("%suuid %s\n",
586 indent.toUtf8().constData(),
588 break;
589 default:
590 dbg << QString::asprintf("%suuid ???\n", indent.toUtf8().constData());
591 }
592 } else if (var.typeId() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
593 dbg << QString::asprintf("%sSequence\n", indent.toUtf8().constData());
594 const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(var.data());
595 for (const QVariant &v : *sequence)
596 dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t'));
597 } else if (var.typeId() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) {
598 dbg << QString::asprintf("%sAlternative\n", indent.toUtf8().constData());
599 const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(var.data());
600 for (const QVariant &v : *alternative)
601 dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t'));
602 } else {
603 dbg << QString::asprintf("%sunknown variant type %d\n", indent.toUtf8().constData(), var.typeId());
604 }
605 }
606}
607
608#ifndef QT_NO_DEBUG_STREAM
609QDebug QBluetoothServiceInfo::streamingOperator(QDebug dbg, const QBluetoothServiceInfo &info)
610{
611 QDebugStateSaver saver(dbg);
612 dbg.noquote() << "\n";
613 const QList<quint16> attributes = info.attributes();
614 for (quint16 id : attributes) {
615 dumpAttributeVariant(dbg, info.attribute(id), QStringLiteral("(%1)\t").arg(id));
616 }
617 return dbg;
618}
619#endif
620
622{
625
628 for (const QVariant &v : sequence) {
630 if (parameters.empty())
631 continue;
632 if (parameters.at(0).userType() == qMetaTypeId<QBluetoothUuid>()) {
633 if (parameters.at(0).value<QBluetoothUuid>() == protocol)
634 return parameters;
635 }
636 }
637
639}
640
642{
644
645 if (parameters.isEmpty())
646 return -1;
647 else if (parameters.size() == 1)
648 return 0;
649 else
650 return parameters.at(1).toUInt();
651}
652
IOBluetoothDevice * device
\inmodule QtBluetooth
\inmodule QtBluetooth
QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const
QMap< quint16, QVariant > attributes
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
\inmodule QtBluetooth
QBluetoothServiceInfo()
Construct a new invalid QBluetoothServiceInfo;.
int protocolServiceMultiplexer() const
This is a convenience function.
QBluetoothServiceInfo::Protocol socketProtocol() const
Returns the protocol that the QBluetoothServiceInfo object uses.
void setDevice(const QBluetoothDeviceInfo &info)
Sets the Bluetooth device that provides this service to device.
QList< quint16 > attributes() const
Returns a list of all attribute ids that the QBluetoothServiceInfo object has.
void setAttribute(quint16 attributeId, const QVariant &value)
Sets the attribute identified by attributeId to value.
QSharedPointer< QBluetoothServiceInfoPrivate > d_ptr
~QBluetoothServiceInfo()
Destroys the QBluetoothServiceInfo object.
Protocol
This enum describes the socket protocol used by the service.
bool isComplete() const
Returns true if the QBluetoothServiceInfo object is considered complete, otherwise returns false.
bool isValid() const
Returns true if the QBluetoothServiceInfo object is valid, otherwise returns false.
bool isRegistered() const
Returns true if the service information is registered with the platform's Service Discovery Protocol ...
QVariant attribute(quint16 attributeId) const
Returns the value of the attribute attributeId.
QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const
Returns the protocol parameters as a QBluetoothServiceInfo::Sequence for protocol protocol.
int serverChannel() const
This is a convenience function.
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
void removeAttribute(quint16 attributeId)
Removes the attribute attributeId from the QBluetoothServiceInfo object.
QList< QBluetoothUuid > serviceClassUuids() const
Returns a list of UUIDs describing the service classes that this service conforms to.
bool contains(quint16 attributeId) const
Returns true if the QBluetoothServiceInfo object contains the attribute attributeId,...
bool unregisterService()
Unregisters this service with the platform's Service Discovery Protocol (SDP) implementation.
QBluetoothServiceInfo & operator=(const QBluetoothServiceInfo &other)
Makes a copy of the other and assigns it to this QBluetoothServiceInfo object.
QBluetoothDeviceInfo device() const
Returns the address of the Bluetooth device that provides this service.
\inmodule QtBluetooth
quint16 toUInt16(bool *ok=nullptr) const
Returns the 16 bit representation of this UUID.
int minimumSize() const
Returns the minimum size in bytes that this UUID can be represented in.
quint32 toUInt32(bool *ok=nullptr) const
Returns the 32 bit representation of this UUID.
ProtocolUuid
This enum is a convienience type for Bluetooth protocol UUIDs.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
QByteArray toHex(char separator='\0') const
Returns a hex encoded copy of the byte array.
\inmodule QtCore
\inmodule QtCore
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
bool empty() const noexcept
Definition qlist.h:685
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
T value(qsizetype i) const
Definition qlist.h:664
void append(parameter_type t)
Definition qlist.h:458
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
bool contains(const Key &key) const
Definition qmap.h:341
size_type remove(const Key &key)
Definition qmap.h:300
QList< Key > keys() const
Definition qmap.h:383
bool isEmpty() const
Definition qmap.h:269
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toUtf8() const &
Definition qstring.h:634
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7263
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
@ Id128
Definition quuid.h:55
QByteArray toByteArray(StringFormat mode=WithBraces) const
Definition quuid.cpp:691
\inmodule QtCore
Definition qvariant.h:65
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
T value() const &
Definition qvariant.h:516
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:714
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
int userType() const
Definition qvariant.h:339
uint toUInt(bool *ok=nullptr) const
Returns the variant as an unsigned int if the variant has userType() \l QMetaType::UInt,...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
int typeId() const
Returns the storage type of the value stored in the variant.
Definition qvariant.h:340
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has userType() \l QMetaType::QUrl; otherwise returns an ...
Combined button and popup list for selecting options.
static void dumpAttributeVariant(QDebug dbg, const QVariant &var, const QString &indent)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
Definition qmetatype.h:1384
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1390
GLsizei const GLfloat * v
[13]
SSL_CTX int void * arg
#define QStringLiteral(str)
#define Q_UNUSED(x)
unsigned short quint16
Definition qtypes.h:48
ptrdiff_t qsizetype
Definition qtypes.h:165
QSharedPointer< T > other(t)
[5]
QHostInfo info
[0]
view create()
\inmodule QtCore \reentrant
Definition qchar.h:18