37 if (m_applicationRegistered) {
39 qCDebug(QT_BT_BLUEZ) <<
"Bluez peripheral application already registered";
45 qCDebug(QT_BT_BLUEZ) <<
"No services, omiting Bluez peripheral application registration";
49 qCDebug(QT_BT_BLUEZ) <<
"Registering bluez peripheral application:" << m_objectPath;
54 qCWarning(QT_BT_BLUEZ) <<
"Peripheral application object registration failed";
70 if (
reply.isError()) {
71 qCWarning(QT_BT_BLUEZ) <<
"Application registration failed" << reply.error();
72 QDBusConnection::systemBus().unregisterObject(m_objectPath);
75 qCDebug(QT_BT_BLUEZ) <<
"Peripheral application registered as" << m_objectPath;
76 m_applicationRegistered = true;
85 if (!m_applicationRegistered)
87 m_applicationRegistered =
false;
89 reply.waitForFinished();
91 qCWarning(QT_BT_BLUEZ) <<
"Error in unregistering peripheral application";
93 qCDebug(QT_BT_BLUEZ) <<
"Peripheral application unregistered successfully";
97 qCDebug(QT_BT_BLUEZ) <<
"Unregistered Bluez peripheral application on DBus:" << m_objectPath;
100void QtBluezPeripheralApplication::registerServices()
103 for (
const auto service:
std::as_const(m_services))
104 service->registerObject();
105 for (
const auto& characteristic :
std::as_const(m_characteristics))
106 characteristic->registerObject();
107 for (
const auto& descriptor :
std::as_const(m_descriptors))
108 descriptor->registerObject();
111void QtBluezPeripheralApplication::unregisterServices()
114 for (
const auto service:
std::as_const(m_services))
116 for (
const auto& characteristic :
std::as_const(m_characteristics))
117 characteristic->unregisterObject();
118 for (
const auto& descriptor :
std::as_const(m_descriptors))
119 descriptor->unregisterObject();
129 m_descriptors.
clear();
131 m_characteristics.
clear();
138 if (m_applicationRegistered) {
139 qCWarning(QT_BT_BLUEZ) <<
"Adding services to a registered application is not supported "
140 "on Bluez DBus. Add services only before first advertisement or "
141 "after disconnection";
152 serviceData, m_objectPath, m_services.
size(), serviceHandle,
this);
153 m_services.
insert(serviceHandle, service);
158 for (
const auto s : std::as_const(m_services)) {
160 service->addIncludedService(
s->objectPath);
166 quint16 characteristicOrdinal{0};
168 auto characteristicHandle = handleForCharacteristic(
169 characteristicData.uuid(), servicePrivate);
172 service->objectPath, characteristicOrdinal++,
173 characteristicHandle,
this);
174 m_characteristics.
insert(characteristicHandle, characteristic);
181 for (
const auto& descriptorData : characteristicData.descriptors()) {
186 if (descriptorData.uuid()
188 || descriptorData.uuid()
192 auto descriptorHandle = handleForDescriptor(descriptorData.uuid(),
194 characteristicHandle);
197 characteristic->
objectPath, descriptorOrdinal++,
198 descriptorHandle, characteristicHandle,
this);
203 m_descriptors.
insert(descriptorHandle, descriptor);
212 auto characteristic = m_characteristics.
value(
handle);
213 if (!characteristic) {
214 qCWarning(QT_BT_BLUEZ) <<
"DBus characteristic not found for write";
217 return characteristic->localValueUpdate(
value);
226 qCWarning(QT_BT_BLUEZ) <<
"DBus descriptor not found for write";
229 return descriptor->localValueUpdate(
value);
234 return !m_applicationRegistered && !m_services.
isEmpty();
242 for (
const auto service: std::as_const(m_services))
244 for (
const auto& charac : std::as_const(m_characteristics))
246 for (
const auto& descriptor : std::as_const(m_descriptors))
249 return managedObjects;
256 const auto handles = service->characteristicList.keys();
257 for (
const auto handle : handles) {
258 if (uuid == service->characteristicList[
handle].uuid)
269 const auto characteristicData =
service->characteristicList[characteristicHandle];
270 const auto handles = characteristicData.descriptorList.keys();
271 for (
const auto handle : handles) {
272 if (uuid == characteristicData.descriptorList[
handle].uuid)
280#include "moc_bluezperipheralapplication_p.cpp"
QString sanitizeNameForDBus(const QString &text)
static constexpr QLatin1String appObjectPathTemplate
QDBusPendingReply RegisterApplication(const QDBusObjectPath &application, const QVariantMap &options)
QDBusPendingReply UnregisterApplication(const QDBusObjectPath &application)
@ CharacteristicExtendedProperties
@ ClientCharacteristicConfiguration
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
void unregisterObject(const QString &path, UnregisterMode mode=UnregisterNode)
Unregisters an object that was registered with the registerObject() at the object path given by path ...
void finished(QDBusPendingCallWatcher *self=nullptr)
This signal is emitted when the pending call has finished and its reply is available.
The QLowEnergyServiceData class is used to set up GATT service data. \inmodule QtBluetooth.
QList< QLowEnergyCharacteristicData > characteristics() const
Returns the list of characteristics.
QList< QLowEnergyService * > includedServices() const
Returns the list of included services.
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
Q_INVOKABLE ManagedObjectList GetManagedObjects()
~QtBluezPeripheralApplication()
bool localDescriptorWrite(QLowEnergyHandle handle, const QByteArray &value)
void unregisterApplication()
void remoteDeviceAccessEvent(const QString &remoteDeviceObjectPath, quint16 mtu)
void registerApplication()
QtBluezPeripheralApplication(const QString &localAdapterPath, QObject *parent=nullptr)
void addService(const QLowEnergyServiceData &serviceData, QSharedPointer< QLowEnergyServicePrivate > servicePrivate, QLowEnergyHandle serviceHandle)
void characteristicValueUpdatedByRemote(QLowEnergyHandle handle, const QByteArray &value)
bool registrationNeeded()
bool localCharacteristicWrite(QLowEnergyHandle handle, const QByteArray &value)
void descriptorValueUpdatedByRemote(QLowEnergyHandle characteristicHandle, QLowEnergyHandle descriptorHandle, const QByteArray &value)
void valueUpdatedByRemote(QLowEnergyHandle handle, const QByteArray &value)
void valueUpdatedByRemote(QLowEnergyHandle characteristicHandle, QLowEnergyHandle descriptorHandle, const QByteArray &value)
void remoteDeviceAccessEvent(const QString &remoteDeviceObjectPath, quint16 mtu)
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
Q_CORE_EXPORT QtJniTypes::Service service()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint64 GLenum void * handle
QFutureWatcher< int > watcher
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent