summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-07-25 14:27:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-01 13:42:51 +0200
commit8b529e3da27b00bf4a20b19cdbfccb085b387267 (patch)
tree0b99172c24b55445d8acb0be54fcebcd5b57a96f
parent2011c3f63d5283b34bc1999ad35404cf93e286c9 (diff)
Adding a convenience function for registering an SPP server
Change-Id: Ieef40295b3fb5a6b16f3cf8b9c75a9306c161025 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/bluetooth/doc/qtbluetooth.qdocconf3
-rw-r--r--src/bluetooth/qrfcommserver.cpp52
-rw-r--r--src/bluetooth/qrfcommserver.h2
3 files changed, 56 insertions, 1 deletions
diff --git a/src/bluetooth/doc/qtbluetooth.qdocconf b/src/bluetooth/doc/qtbluetooth.qdocconf
index 940b7765..45c0d3b4 100644
--- a/src/bluetooth/doc/qtbluetooth.qdocconf
+++ b/src/bluetooth/doc/qtbluetooth.qdocconf
@@ -45,7 +45,8 @@ sourcedirs += .. \
../../imports/bluetooth \
exampledirs += ../../../examples/bluetooth \
- snippets/
+ snippets/ \
+ ../
imagedirs += images
diff --git a/src/bluetooth/qrfcommserver.cpp b/src/bluetooth/qrfcommserver.cpp
index 727f1872..7e42186c 100644
--- a/src/bluetooth/qrfcommserver.cpp
+++ b/src/bluetooth/qrfcommserver.cpp
@@ -42,6 +42,7 @@
#include "qrfcommserver.h"
#include "qrfcommserver_p.h"
#include "qbluetoothsocket.h"
+#include "qbluetoothserviceinfo.h"
QT_BEGIN_NAMESPACE_BLUETOOTH
@@ -142,6 +143,57 @@ QRfcommServer::~QRfcommServer()
}
/*!
+ \fn QBluetoothServiceInfo QRfcommServer::listen(const QBluetoothUuid &uuid, const QString &serviceName)
+
+ Convenience function for registering an SPP service with \a uuid and \a serviceName.
+ Because this function already registers the service, the QBluetoothServiceInfo object
+ which is returned can not be changed any more.
+
+ Returns a registered QBluetoothServiceInfo instance if sucessful otherwise an
+ invalid QBluetoothServiceInfo.
+
+ This function is equivalent to following code snippet.
+
+ \snippet qrfcommserver.cpp listen
+
+ \sa isListening(), newConnection(), listen()
+*/
+QBluetoothServiceInfo QRfcommServer::listen(const QBluetoothUuid &uuid, const QString &serviceName)
+{
+ if (!listen())
+ return QBluetoothServiceInfo();
+//! [listen]
+ QBluetoothServiceInfo serviceInfo;
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, serviceName);
+ serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,
+ QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
+
+ QBluetoothServiceInfo::Sequence classId;
+ classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
+ serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
+ classId);
+
+ serviceInfo.setServiceUuid(uuid);
+
+ QBluetoothServiceInfo::Sequence protocolDescriptorList;
+ QBluetoothServiceInfo::Sequence protocol;
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ protocol.clear();
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
+ << QVariant::fromValue(quint8(serverPort()));
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
+ protocolDescriptorList);
+ bool result = serviceInfo.registerService();
+//! [listen]
+ if (!result)
+ return QBluetoothServiceInfo();
+ return serviceInfo;
+}
+
+/*!
Returns true if the RFCOMM server is listening for incoming connections, otherwise false.
*/
bool QRfcommServer::isListening() const
diff --git a/src/bluetooth/qrfcommserver.h b/src/bluetooth/qrfcommserver.h
index 2e6778d0..a4625208 100644
--- a/src/bluetooth/qrfcommserver.h
+++ b/src/bluetooth/qrfcommserver.h
@@ -49,6 +49,7 @@
#include <QtBluetooth/QBluetoothAddress>
#include <QtBluetooth/qbluetooth.h>
#include <QtBluetooth/QBluetoothSocket>
+#include <QtBluetooth/QBluetoothServiceInfo>
QT_BEGIN_NAMESPACE_BLUETOOTH
@@ -66,6 +67,7 @@ public:
void close();
bool listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0);
+ QBluetoothServiceInfo listen(const QBluetoothUuid &uuid, const QString &serviceName = QString());
bool isListening() const;
void setMaxPendingConnections(int numConnections);