6#include <QtCore/QLoggingCategory>
8#include <QtBluetooth/QBluetoothLocalDevice>
9#include <QtBluetooth/QLowEnergyCharacteristicData>
10#include <QtBluetooth/QLowEnergyDescriptorData>
11#include <QtBluetooth/QLowEnergyServiceData>
28#if defined(QT_WINRT_BLUETOOTH) || defined(Q_OS_DARWIN)
35 bool adapterFound =
false;
56 errorString = QLowEnergyController::tr(
"Remote device cannot be found");
59 errorString = QLowEnergyController::tr(
"Cannot find local adapter");
62 errorString = QLowEnergyController::tr(
"Error occurred during connection I/O");
65 errorString = QLowEnergyController::tr(
"Error occurred trying to connect to remote device.");
68 errorString = QLowEnergyController::tr(
"Error occurred trying to start advertising");
71 errorString = QLowEnergyController::tr(
"Remote device closed the connection");
74 errorString = QLowEnergyController::tr(
"Failed to authorize on the remote device");
77 errorString = QLowEnergyController::tr(
"Missing permissions error");
80 errorString = QLowEnergyController::tr(
"Error reading RSSI value");
86 errorString = QLowEnergyController::tr(
"Unknown Error");
90 emit q->errorOccurred(newError);
96 qCDebug(QT_BT) <<
"QLowEnergyControllerPrivate setting state to" <<
newState;
116 const QList<QSharedPointer<QLowEnergyServicePrivate>>
values = currentList.values();
117 for (
auto service:
values)
118 if (service->startHandle <=
handle && handle <= service->endHandle)
121 return QSharedPointer<QLowEnergyServicePrivate>();
132 if (service.isNull())
135 if (service->characteristicList.isEmpty())
139 if (service->characteristicList.contains(
handle))
143 QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
144 std::sort(charHandles.begin(), charHandles.end());
145 for (
qsizetype i = charHandles.size() - 1;
i >= 0; --
i) {
146 if (charHandles.at(
i) >
handle)
163 if (!matchingChar.isValid())
167 d_ptr->characteristicList[matchingChar.attributeHandle()];
169 if (charData.descriptorList.contains(
handle))
182 QSharedPointer<QLowEnergyServicePrivate> service =
serviceForHandle(charHandle);
183 if (!service.isNull()) {
185 if (charIt != service->characteristicList.end()) {
189 charDetails.value +=
value;
191 charDetails.value =
value;
193 return charDetails.value.size();
207 QSharedPointer<QLowEnergyServicePrivate> service =
serviceForHandle(charHandle);
208 if (!service.isNull()) {
210 if (charIt != service->characteristicList.end()) {
214 if (descIt != charDetails.descriptorList.end()) {
218 descDetails.value +=
value;
220 descDetails.value =
value;
222 return descDetails.value.size();
232 for (QSharedPointer<QLowEnergyServicePrivate> service :
serviceList.values())
233 service->setController(
nullptr);
235 for (QSharedPointer<QLowEnergyServicePrivate> service :
localServices.values())
236 service->setController(
nullptr);
251 servicePrivate->setController(
this);
253 servicePrivate->uuid = service.uuid();
256 const QList<QLowEnergyService *> includedServices = service.includedServices();
258 servicePrivate->includedServices << includedService->serviceUuid();
266 const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics();
271 charData.
uuid = cd.uuid();
272 charData.properties = cd.properties();
273 charData.value = cd.value();
274 const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors();
277 descData.
uuid = dd.uuid();
278 descData.
value = dd.value();
281 servicePrivate->characteristicList.
insert(declHandle, charData);
285 if (handleOverflow) {
286 qCWarning(QT_BT) <<
"Not enough attribute handles left to create this service";
292 qCWarning(QT_BT) <<
"Overriding existing local service with uuid"
293 << servicePrivate->uuid;
295 this->
localServices.insert(servicePrivate->uuid, servicePrivate);
303 qCWarning(QT_BT,
"This platform does not support reading RSSI");
309#include "moc_qlowenergycontrollerbase_p.cpp"
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
QByteArray & insert(qsizetype i, QByteArrayView data)
The QLowEnergyCharacteristicData class is used to set up GATT service data. \inmodule QtBluetooth.
QLowEnergyCharacteristic characteristicForHandle(QLowEnergyHandle handle)
Returns a valid characteristic if the given handle is the handle of the characteristic itself or one ...
QSharedPointer< QLowEnergyServicePrivate > serviceForHandle(QLowEnergyHandle handle)
void invalidateServices()
virtual ~QLowEnergyControllerPrivate()
quint16 updateValueOfDescriptor(QLowEnergyHandle charHandle, QLowEnergyHandle descriptorHandle, const QByteArray &value, bool appendValue)
Returns the length of the updated descriptor value.
QLowEnergyDescriptor descriptorForHandle(QLowEnergyHandle handle)
Returns a valid descriptor if handle belongs to a descriptor; otherwise an invalid one.
ServiceDataMap localServices
ServiceDataMap serviceList
bool isValidLocalAdapter()
QLowEnergyController::Error error
void setError(QLowEnergyController::Error newError)
QLowEnergyController::Role role
QLowEnergyHandle lastLocalHandle
quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle, const QByteArray &value, bool appendValue)
Returns the length of the updated characteristic value.
QBluetoothAddress localAdapter
virtual void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle)=0
virtual QLowEnergyService * addServiceHelper(const QLowEnergyServiceData &service)
QLowEnergyController::ControllerState state
QBluetoothAddress remoteDevice
void setState(QLowEnergyController::ControllerState newState)
ControllerState
Indicates the state of the controller object.
Error
Indicates all possible error conditions found during the controller's existence.
@ UnknownRemoteDeviceError
@ InvalidBluetoothAdapterError
@ MissingPermissionsError
The QLowEnergyDescriptorData class is used to create GATT service data. \inmodule QtBluetooth.
The QLowEnergyServiceData class is used to set up GATT service data. \inmodule QtBluetooth.
QScopedPointer< QObjectData > d_ptr
static QSharedPointer create(Args &&...arguments)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QT_BEGIN_NAMESPACE typedef QMap< QBluetoothUuid, QSharedPointer< QLowEnergyServicePrivate > > ServiceDataMap
GLenum GLsizei GLsizei GLint * values
[15]
GLuint64 GLenum void * handle
GLdouble GLdouble GLdouble GLdouble q
QLowEnergyHandle valueHandle