summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergyserviceinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth/qlowenergyserviceinfo.cpp')
-rw-r--r--src/bluetooth/qlowenergyserviceinfo.cpp263
1 files changed, 263 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergyserviceinfo.cpp b/src/bluetooth/qlowenergyserviceinfo.cpp
new file mode 100644
index 00000000..92758da1
--- /dev/null
+++ b/src/bluetooth/qlowenergyserviceinfo.cpp
@@ -0,0 +1,263 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyserviceinfo.h"
+#include "qlowenergyserviceinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \enum QLowEnergyServiceInfo::ServiceType
+
+ This enum describes the type of the service. One LE device can have one or more primary services.
+
+ \value PrimaryService The primary service. The primary service can have one or
+ more included services.
+ \value IncludedService The included service by primary services.
+*/
+
+/*!
+ \enum QLowEnergyServiceInfo::Error
+
+ This enum describes the type of an error that can appear.
+
+ \value ConnectionRefused The connection to the service was refused. This can be caused if the device
+ got turned off or it has a random device address. To solve
+ the case if device has a random address on linux platform
+ setRandomAddress() method must be called before connecting.
+ \value DeviceBusy The device is already connected to another Bluetooth device.
+ \value InitializationFailed Could not initialize GATT callbacks.
+ \value MemoryAllocation Could not initialize memory needed for reading GATT characteristics.
+ \value DisconnectFail Could not disconnect from the service.
+ \value UnknownError Unknown error.
+*/
+
+/*!
+ Method for parsing the service name with given \a uuid.
+ * \brief parseUuid
+ * \param uuid
+ * \return
+ */
+QString parseUuid(const QBluetoothUuid &uuid)
+{
+ static QHash<int, QString> uuidnames;
+ if ( uuidnames.isEmpty() ) {
+ uuidnames[0x1800] = QStringLiteral("Generic Access");
+ uuidnames[0x1801] = QStringLiteral("Generic Attribute");
+ uuidnames[0x1802] = QStringLiteral("ImmediateAlert");
+ uuidnames[0x1803] = QStringLiteral("Link Loss");
+ uuidnames[0x1804] = QStringLiteral("Tx Power");
+ uuidnames[0x1805] = QStringLiteral("Current Time Service");
+ uuidnames[0x1806] = QStringLiteral("Reference Time Update Service");
+ uuidnames[0x1807] = QStringLiteral("Next DST Change Service");
+ uuidnames[0x1808] = QStringLiteral("Glucose");
+ uuidnames[0x1809] = QStringLiteral("Health Thermometer");
+ uuidnames[0x180A] = QStringLiteral("Device Information");
+ uuidnames[0x180D] = QStringLiteral("Heart Rate");
+ uuidnames[0x180E] = QStringLiteral("Phone Alert Status Service");
+ uuidnames[0x180F] = QStringLiteral("Battery Service");
+ uuidnames[0x1810] = QStringLiteral("Blood Pressure");
+ uuidnames[0x1811] = QStringLiteral("Alert Notification Service");
+ uuidnames[0x1812] = QStringLiteral("Human Interface Device");
+ uuidnames[0x1813] = QStringLiteral("Scan Parameters");
+ uuidnames[0x1814] = QStringLiteral("Running Speed and Cadance");
+ uuidnames[0x1816] = QStringLiteral("Cycling Speed and Cadance");
+ uuidnames[0x1818] = QStringLiteral("Cycling Power");
+ uuidnames[0x1819] = QStringLiteral("Location and Navigation");
+ }
+ QString name = uuidnames.value(uuid.toUInt16(), QStringLiteral("Unknow Service"));
+ return name;
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo():
+ d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate))
+{
+ d_ptr->q_ptr = this;
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo object with the given \a uuid.
+
+ Based on uuid, corresponsing service name is given.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QBluetoothUuid &uuid):
+ d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate))
+{
+ d_ptr->uuid = QBluetoothUuid(uuid);
+ d_ptr->q_ptr = this;
+ d_ptr->serviceName = parseUuid(d_ptr->uuid);
+}
+
+/*!
+ Construct a new QLowEnergyServiceInfo that is a copy of \a other.
+
+ The two copies continue to share the same underlying data which does not detach
+ upon write.
+*/
+QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QLowEnergyServiceInfo &other):
+ d_ptr(other.d_ptr)
+{
+ d_ptr->q_ptr = this;
+}
+
+/*!
+ Destroys the QLowEnergyServiceInfo object.
+*/
+QLowEnergyServiceInfo::~QLowEnergyServiceInfo()
+{
+
+}
+
+/*!
+ Returns the gatt service uuid.
+*/
+QBluetoothUuid QLowEnergyServiceInfo::uuid() const
+{
+ return d_ptr->uuid;
+}
+
+/*!
+ Returns the list of service characteristics. If service was not connected, an empty
+ list will be returned.
+*/
+QList<QLowEnergyCharacteristicInfo> QLowEnergyServiceInfo::getCharacteristics() const
+{
+ return d_ptr->characteristicList;
+}
+
+/*!
+ Returns the service name.
+*/
+QString QLowEnergyServiceInfo::name() const
+{
+ return d_ptr->serviceName;
+}
+
+/*!
+ Sets service type with \a type.
+*/
+void QLowEnergyServiceInfo::setServiceType(QLowEnergyServiceInfo::ServiceType type)
+{
+ d_ptr->serviceType = type;
+}
+
+/*!
+ Returns the service type. If setServiceType is not called default service type
+ (PrimaryService) is returned.
+*/
+QLowEnergyServiceInfo::ServiceType QLowEnergyServiceInfo::getServiceType() const
+{
+ return d_ptr->serviceType;
+}
+
+/*!
+ Makes a copy of the \a other and assigns it to this QLowEnergyServiceInfo object.
+ The two copies continue to share the same service and registration details.
+*/
+QLowEnergyServiceInfo &QLowEnergyServiceInfo::operator=(const QLowEnergyServiceInfo &other)
+{
+ d_ptr = other.d_ptr;
+ d_ptr->q_ptr = this;
+ return *this;
+}
+
+/*!
+ Checks whether service is connected.
+ */
+bool QLowEnergyServiceInfo::isConnected() const
+{
+ return d_ptr->connected;
+}
+
+/*!
+ This method is called if a device has a random device address that is used for connecting.
+ It should be called before connecting to a service; otherwise connecting will not be
+ successful and ConnectionRefused error will be emitted.
+ */
+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.
+*/
+QBluetoothDeviceInfo QLowEnergyServiceInfo::device() const
+{
+ return d_ptr->deviceInfo;
+}
+
+/*!
+ Sets the Bluetooth device that provides this service to \a device.
+*/
+void QLowEnergyServiceInfo::setDevice(const QBluetoothDeviceInfo &device)
+{
+ d_ptr->deviceInfo = device;
+}
+
+/*!
+ Returns true if the QLowEnergyServiceInfo object is valid, otherwise returns false.
+*/
+bool QLowEnergyServiceInfo::isValid() const
+{
+ if (d_ptr->uuid == QBluetoothUuid())
+ return false;
+ if (!d_ptr->deviceInfo.isValid())
+ return false;
+ if (!d_ptr->valid())
+ return false;
+ return true;
+}
+
+QT_END_NAMESPACE
+
+