From cdc3ee8b00380ad208561e6c9bf575762fa398fb Mon Sep 17 00:00:00 2001 From: Nedim Hadzic Date: Wed, 19 Feb 2014 15:59:53 +0100 Subject: Renaming QLowEnergyServiceInfo methods Ensures that QLowEnergyServiceInfo and QBluetoothServiceInfo are more alike. Tests and examples updated as well. Change-Id: I0f6a97900891a9673f99578bdc8d156a8c403513 Reviewed-by: Alex Blasche --- .../qbluetoothservicediscoveryagent_qnx.cpp | 2 +- src/bluetooth/qlowenergycharacteristicinfo.cpp | 11 -------- src/bluetooth/qlowenergycharacteristicinfo.h | 2 -- src/bluetooth/qlowenergycontroller.cpp | 33 ++++++++++++++++------ src/bluetooth/qlowenergycontroller.h | 1 + src/bluetooth/qlowenergycontroller_p.h | 1 + src/bluetooth/qlowenergyserviceinfo.cpp | 12 ++------ src/bluetooth/qlowenergyserviceinfo.h | 6 ++-- 8 files changed, 31 insertions(+), 37 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp index 056cb4de..4ef40497 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp @@ -364,7 +364,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::remoteDevicesChanged(int fd) QLowEnergyServiceInfo lowEnergyService(leUuid); lowEnergyService.setDevice(discoveredDevices.at(0)); - qCDebug(QT_BT_QNX) << "Adding Low Energy service" << lowEnergyService.uuid(); + qCDebug(QT_BT_QNX) << "Adding Low Energy service" << lowEnergyService.serviceUuid(); q_ptr->serviceDiscovered(lowEnergyService); } diff --git a/src/bluetooth/qlowenergycharacteristicinfo.cpp b/src/bluetooth/qlowenergycharacteristicinfo.cpp index 128f9f97..948499a4 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo.cpp +++ b/src/bluetooth/qlowenergycharacteristicinfo.cpp @@ -305,15 +305,4 @@ QList QLowEnergyCharacteristicInfo::descriptors() cons return d_ptr->descriptorsList; } -/*! - Returns an error string if error occurred. An error is emitted in the - QLowEnergyController class. - - \sa QLowEnergyController::error(const QLowEnergyCharacteristicInfo &) -*/ -QString QLowEnergyCharacteristicInfo::errorString() const -{ - return d_ptr->errorString; -} - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycharacteristicinfo.h b/src/bluetooth/qlowenergycharacteristicinfo.h index c3121253..e2285c63 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo.h +++ b/src/bluetooth/qlowenergycharacteristicinfo.h @@ -101,8 +101,6 @@ public: bool isValid() const; - QString errorString() const; - protected: QSharedPointer d_ptr; diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index 2dbd1a87..e2ca99cc 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE This signal is emitted when the service error occurs. - \sa QLowEnergyServiceInfo::errorString() + \sa errorString() */ /*! @@ -91,7 +91,7 @@ QT_BEGIN_NAMESPACE This signal is emitted when the characteristic error occurs. - \sa QLowEnergyCharacteristicInfo::errorString() + \sa errorString() */ /*! @@ -123,7 +123,7 @@ QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate() void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid) { for (int i = 0; i < m_leServices.size(); i++) { - if (((QLowEnergyServiceInfo)m_leServices.at(i)).uuid() == uuid) + if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) emit q_ptr->connected((QLowEnergyServiceInfo)m_leServices.at(i)); } @@ -132,8 +132,11 @@ void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid) { for (int i = 0; i < m_leServices.size(); i++) { - if (((QLowEnergyServiceInfo)m_leServices.at(i)).uuid() == uuid) - emit q_ptr->error((QLowEnergyServiceInfo)m_leServices.at(i)); + if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) { + QLowEnergyServiceInfo service((QLowEnergyServiceInfo)m_leServices.at(i)); + errorString = service.d_ptr->errorString; + emit q_ptr->error(service); + } } } @@ -142,8 +145,10 @@ void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &u for (int i = 0; i < m_leServices.size(); i++) { QList characteristics = m_leServices.at(i).characteristics(); for (int j = 0; j < characteristics.size(); j++) { - if (characteristics.at(j).uuid() == uuid) + if (characteristics.at(j).uuid() == uuid) { + errorString = characteristics.at(j).d_ptr->errorString; emit q_ptr->error(characteristics.at(j)); + } } } } @@ -165,7 +170,7 @@ void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid) void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid) { for (int i = 0; i < m_leServices.size(); i++) { - if (((QLowEnergyServiceInfo)m_leServices.at(i)).uuid() == uuid) { + if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) { QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid))); QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid))); QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid))); @@ -179,7 +184,7 @@ void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &se bool in = false; if (service.isValid()) { for (int i = 0; i < m_leServices.size(); i++) { - if (((QLowEnergyServiceInfo)m_leServices.at(i)).uuid() == service.uuid() && !((QLowEnergyServiceInfo)m_leServices.at(i)).isConnected()) { + if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == service.serviceUuid() && !((QLowEnergyServiceInfo)m_leServices.at(i)).isConnected()) { in = true; QObject::connect(m_leServices.at(i).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid))); QObject::connect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid))); @@ -202,7 +207,7 @@ void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo { if (service.isValid()) { for (int i = 0; i < m_leServices.size(); i++) { - if (((QLowEnergyServiceInfo)m_leServices.at(i)).uuid() == service.uuid() && service.isConnected()) { + if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == service.serviceUuid() && service.isConnected()) { ((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr->unregisterServiceWatcher(); break; } @@ -301,4 +306,14 @@ void QLowEnergyController::disableNotifications(const QLowEnergyCharacteristicIn } } } + +/*! + Returns a human-readable description of the last error that occurred. + + \sa error(const QLowEnergyServiceInfo &), error(const QLowEnergyCharacteristicInfo &) +*/ +QString QLowEnergyController::errorString() const +{ + return d_ptr->errorString; +} QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h index 16f1bc55..842a2e7e 100644 --- a/src/bluetooth/qlowenergycontroller.h +++ b/src/bluetooth/qlowenergycontroller.h @@ -64,6 +64,7 @@ public: void disconnectFromService(const QLowEnergyServiceInfo &leService = QLowEnergyServiceInfo()); bool enableNotifications(const QLowEnergyCharacteristicInfo &characteristic); void disableNotifications(const QLowEnergyCharacteristicInfo &characteristic); + QString errorString() const; Q_SIGNALS: void connected(const QLowEnergyServiceInfo &); diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h index b19f7024..1d68f4b7 100644 --- a/src/bluetooth/qlowenergycontroller_p.h +++ b/src/bluetooth/qlowenergycontroller_p.h @@ -61,6 +61,7 @@ public: void _q_serviceDisconnected(const QBluetoothUuid &uuid); QList m_leServices; + QString errorString; private: QLowEnergyController *q_ptr; diff --git a/src/bluetooth/qlowenergyserviceinfo.cpp b/src/bluetooth/qlowenergyserviceinfo.cpp index 618bd9c7..ca6df923 100644 --- a/src/bluetooth/qlowenergyserviceinfo.cpp +++ b/src/bluetooth/qlowenergyserviceinfo.cpp @@ -166,7 +166,7 @@ QLowEnergyServiceInfo::~QLowEnergyServiceInfo() /*! Returns the gatt service uuid. */ -QBluetoothUuid QLowEnergyServiceInfo::uuid() const +QBluetoothUuid QLowEnergyServiceInfo::serviceUuid() const { return d_ptr->uuid; } @@ -183,7 +183,7 @@ QList QLowEnergyServiceInfo::characteristics() con /*! Returns the service name. */ -QString QLowEnergyServiceInfo::name() const +QString QLowEnergyServiceInfo::serviceName() const { return d_ptr->serviceName; } @@ -233,14 +233,6 @@ void QLowEnergyServiceInfo::setRandomAddress() d_ptr->randomAddress = true; } -/*! - Returns an error string if error occurred. - */ -QString QLowEnergyServiceInfo::errorString() const -{ - return d_ptr->errorString; -} - /*! Returns the address of the Bluetooth device that provides this service. */ diff --git a/src/bluetooth/qlowenergyserviceinfo.h b/src/bluetooth/qlowenergyserviceinfo.h index 08c5fde4..14321aeb 100644 --- a/src/bluetooth/qlowenergyserviceinfo.h +++ b/src/bluetooth/qlowenergyserviceinfo.h @@ -84,11 +84,11 @@ public: void setDevice(const QBluetoothDeviceInfo &info); QBluetoothDeviceInfo device() const; - QBluetoothUuid uuid() const; + QBluetoothUuid serviceUuid() const; QList characteristics() const; - QString name() const; + QString serviceName() const; void setServiceType(QLowEnergyServiceInfo::ServiceType type); QLowEnergyServiceInfo::ServiceType serviceType() const; @@ -97,8 +97,6 @@ public: bool isConnected() const; - QString errorString() const; - bool isValid() const; protected: -- cgit v1.2.3