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
qlowenergycharacteristic.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 BlackBerry Limited. All rights reserved.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include <QHash>
7
9
11
12
70
82
90 d_ptr(other.d_ptr)
91{
92 if (other.data) {
94 data->handle = other.data->handle;
95 }
96}
97
102 QSharedPointer<QLowEnergyServicePrivate> p, QLowEnergyHandle handle):
103 d_ptr(p)
104{
106 data->handle = handle;
107}
108
116
133
139{
140 if (d_ptr.isNull() || !data
141 || !d_ptr->characteristicList.contains(data->handle))
142 return QBluetoothUuid();
143
144 return d_ptr->characteristicList[data->handle].uuid;
145}
146
152QLowEnergyCharacteristic::PropertyTypes QLowEnergyCharacteristic::properties() const
153{
154 if (d_ptr.isNull() || !data
155 || !d_ptr->characteristicList.contains(data->handle))
157
158 return d_ptr->characteristicList[data->handle].properties;
159}
160
179{
180 if (d_ptr.isNull() || !data
181 || !d_ptr->characteristicList.contains(data->handle))
182 return QByteArray();
183
184 return d_ptr->characteristicList[data->handle].value;
185}
186
197QLowEnergyHandle QLowEnergyCharacteristic::handle() const
198{
199 if (d_ptr.isNull() || !data
200 || !d_ptr->characteristicList.contains(data->handle))
201 return 0;
202
203 return d_ptr->characteristicList[data->handle].valueHandle;
204}
205
211{
212 d_ptr = other.d_ptr;
213
214 if (!other.data) {
215 if (data) {
216 delete data;
217 data = nullptr;
218 }
219 } else {
220 if (!data)
222
223 data->handle = other.data->handle;
224 }
225 return *this;
226}
227
257bool QLowEnergyCharacteristic::equals(const QLowEnergyCharacteristic &a,
259{
260 if (a.d_ptr != b.d_ptr)
261 return false;
262
263 if ((a.data && !b.data) || (!a.data && b.data))
264 return false;
265
266 if (!a.data)
267 return true;
268
269 if (a.data->handle != b.data->handle)
270 return false;
271
272 return true;
273}
274
289{
290 if (d_ptr.isNull() || !data)
291 return false;
292
294 return false;
295
296 return true;
297}
298
311QLowEnergyHandle QLowEnergyCharacteristic::attributeHandle() const
312{
313 if (d_ptr.isNull() || !data)
314 return 0;
315
316 return data->handle;
317}
318
325{
326 if (d_ptr.isNull() || !data)
327 return QLowEnergyDescriptor();
328
329 CharacteristicDataMap::const_iterator charIt = d_ptr->characteristicList.constFind(data->handle);
330 if (charIt != d_ptr->characteristicList.constEnd()) {
331 const QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
332
333 DescriptorDataMap::const_iterator descIt = charDetails.descriptorList.constBegin();
334 for ( ; descIt != charDetails.descriptorList.constEnd(); ++descIt) {
335 const QLowEnergyHandle descHandle = descIt.key();
336 const QLowEnergyServicePrivate::DescData &descDetails = descIt.value();
337
338 if (descDetails.uuid == uuid)
339 return QLowEnergyDescriptor(d_ptr, data->handle, descHandle);
340 }
341 }
342
343 return QLowEnergyDescriptor();
344}
345
399
406QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const
407{
408 QList<QLowEnergyDescriptor> result;
409
410 if (d_ptr.isNull() || !data
411 || !d_ptr->characteristicList.contains(data->handle))
412 return result;
413
414 QList<QLowEnergyHandle> descriptorKeys = d_ptr->characteristicList[data->handle].
415 descriptorList.keys();
416
417 std::sort(descriptorKeys.begin(), descriptorKeys.end());
418
419 for (const QLowEnergyHandle descHandle : std::as_const(descriptorKeys)) {
420 QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle);
421 result.append(descriptor);
422 }
423
424 return result;
425}
426
457
\inmodule QtBluetooth
static QString characteristicToString(CharacteristicType uuid)
Returns a human-readable and translated name for the given characteristic type represented by uuid.
\inmodule QtCore
Definition qbytearray.h:57
static QByteArray fromHex(const QByteArray &hexEncoded)
Returns a decoded copy of the hex encoded array hexEncoded.
static const QByteArray CCCDEnableIndication
QByteArray value() const
Returns the cached value of the characteristic.
QLowEnergyCharacteristic()
Construct a new QLowEnergyCharacteristic.
static const QByteArray CCCDDisable
\variable QLowEnergyCharacteristic::CCCDDisable
QString name() const
Returns the human-readable name of the characteristic.
~QLowEnergyCharacteristic()
Destroys the QLowEnergyCharacteristic object.
QLowEnergyCharacteristic::PropertyTypes properties() const
Returns the properties of the characteristic.
QLowEnergyDescriptor clientCharacteristicConfiguration() const
Returns the Client Characteristic Configuration Descriptor or an invalid \l QLowEnergyDescriptor inst...
QBluetoothUuid uuid() const
Returns the UUID of the characteristic if \l isValid() returns true; otherwise a \l {QUuid::isNull()}...
static const QByteArray CCCDEnableNotification
QLowEnergyDescriptor descriptor(const QBluetoothUuid &uuid) const
Returns the descriptor for uuid or an invalid \l QLowEnergyDescriptor instance.
bool isValid() const
Returns true if the QLowEnergyCharacteristic object is valid, otherwise returns false.
QLowEnergyCharacteristic & operator=(const QLowEnergyCharacteristic &other)
Makes a copy of other and assigns it to this \l QLowEnergyCharacteristic object.
QList< QLowEnergyDescriptor > descriptors() const
Returns the list of descriptors belonging to this characteristic; otherwise an empty list.
\inmodule QtBluetooth
QLowEnergyService::ServiceState state
QHash< QLowEnergyHandle, CharData > characteristicList
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
quint16 QLowEnergyHandle
Definition qbluetooth.h:42
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1390
GLboolean GLboolean GLboolean b
GLuint64 GLenum void * handle
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]