summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-02-07 15:35:29 +0100
committerAlex Blasche <alexander.blasche@digia.com>2014-02-07 15:37:03 +0100
commit0a9b6759caf2f7c3d5101d541ff01ccaf14050ae (patch)
tree786fda2f7d421ab6548014e65c20f66697965c91 /src
parent05294a8c3fbfffa858c696d7113d4144b584d412 (diff)
parent85e9ce386d2d931617f3c0d76acd4ca4165cb81d (diff)
Merge branch 'stable' into dev
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothserver.cpp18
-rw-r--r--src/bluetooth/qbluetoothserver_bluez.cpp27
-rw-r--r--src/bluetooth/qbluetoothserver_qnx.cpp2
-rw-r--r--src/bluetooth/qbluetoothserviceinfo.cpp36
-rw-r--r--src/bluetooth/qbluetoothserviceinfo.h8
5 files changed, 64 insertions, 27 deletions
diff --git a/src/bluetooth/qbluetoothserver.cpp b/src/bluetooth/qbluetoothserver.cpp
index 967d4e71..e70ec1db 100644
--- a/src/bluetooth/qbluetoothserver.cpp
+++ b/src/bluetooth/qbluetoothserver.cpp
@@ -112,8 +112,11 @@ QT_BEGIN_NAMESPACE
Start listening for incoming connections to \a address on \a port.
- Returns true if the operation succeeded and the server is listening for
- incoming connections, otherwise returns false.
+ Returns \c true if the operation succeeded and the server is listening for
+ incoming connections, otherwise returns \c false.
+
+ If the server object is already listening for incoming connections this function
+ always returns \c false. \l close() should be called before calling this function.
\sa isListening(), newConnection()
*/
@@ -172,12 +175,17 @@ QBluetoothServer::~QBluetoothServer()
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.
+ which is returned can not be changed any more. To shutdown the server later on it is
+ required to call \l QBluetoothServiceInfo::unregisterService() and \l close() on this
+ server object.
Returns a registered QBluetoothServiceInfo instance if sucessful otherwise an
invalid QBluetoothServiceInfo. This function always assumes that the default Bluetooth adapter
should be used.
+ If the server object is already listening for incoming connections this function
+ returns an invalid \l QBluetoothServiceInfo.
+
For an RFCOMM server this function is equivalent to following code snippet.
\snippet qbluetoothserver.cpp listen
@@ -223,8 +231,10 @@ QBluetoothServiceInfo QBluetoothServer::listen(const QBluetoothUuid &uuid, const
protocolDescriptorList);
bool result = serviceInfo.registerService();
//! [listen3]
- if (!result)
+ if (!result) {
+ close(); //close the still listening socket
return QBluetoothServiceInfo();
+ }
return serviceInfo;
}
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp
index 0b504d9a..8acd8e20 100644
--- a/src/bluetooth/qbluetoothserver_bluez.cpp
+++ b/src/bluetooth/qbluetoothserver_bluez.cpp
@@ -105,11 +105,32 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
{
Q_D(QBluetoothServer);
+ if (d->socket->state() == QBluetoothSocket::ListeningState) {
+ qCWarning(QT_BT_BLUEZ) << "Socket already in listen mode, close server first";
+ return false; //already listening, nothing to do
+ }
+
int sock = d->socket->socketDescriptor();
if (sock < 0) {
- d->m_lastError = InputOutputError;
- emit error(d->m_lastError);
- return false;
+ /* Negative socket descriptor is not always an error case
+ * Another cause could be a call to close()/abort()
+ * Check whether we can recover by re-creating the socket
+ * we should really call Bluez::QBluetoothSocketPrivate::ensureNativeSocket
+ * but a re-creation of the socket will do as well.
+ */
+
+ delete d->socket;
+ if (serverType() == QBluetoothServiceInfo::RfcommProtocol)
+ d->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
+ else
+ d->socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
+
+ sock = d->socket->socketDescriptor();
+ if (sock < 0) {
+ d->m_lastError = InputOutputError;
+ emit error(d->m_lastError);
+ return false;
+ }
}
if (d->serverType == QBluetoothServiceInfo::RfcommProtocol) {
diff --git a/src/bluetooth/qbluetoothserver_qnx.cpp b/src/bluetooth/qbluetoothserver_qnx.cpp
index 9a16694f..d4289368 100644
--- a/src/bluetooth/qbluetoothserver_qnx.cpp
+++ b/src/bluetooth/qbluetoothserver_qnx.cpp
@@ -156,7 +156,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
// listen has already been called before
if (d->socket && d->socket->state() == QBluetoothSocket::ListeningState)
- return true;
+ return false;
d->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp
index 3a864b3c..84655b77 100644
--- a/src/bluetooth/qbluetoothserviceinfo.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo.cpp
@@ -332,18 +332,6 @@ bool QBluetoothServiceInfo::unregisterService()
*/
/*!
- \fn QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const
-
- This is a convenience function. It is equivalent to calling
- attribute(QBluetoothServiceInfo::ServiceClassIds).value<QList<QBluetoothUuid> >().
-
- Returns a list of UUIDs describing the service classes that this service conforms to.
-
- \sa attribute()
-*/
-
-
-/*!
Construct a new invalid QBluetoothServiceInfo;
*/
QBluetoothServiceInfo::QBluetoothServiceInfo()
@@ -514,6 +502,30 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfo::protocolDescriptor(QBluet
}
/*!
+ Returns a list of UUIDs describing the service classes that this service conforms to.
+
+ This is a convenience function. It is equivalent to calling
+ attribute(QBluetoothServiceInfo::ServiceClassIds).value<QBluetoothServiceInfo::Sequence>()
+ and subsequently iterating over its QBluetoothUuid entries.
+
+ \sa attribute()
+*/
+QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const
+{
+ QList<QBluetoothUuid> results;
+
+ const QVariant var = attribute(QBluetoothServiceInfo::ServiceClassIds);
+ if (!var.isValid())
+ return results;
+
+ const QBluetoothServiceInfo::Sequence seq = var.value<QBluetoothServiceInfo::Sequence>();
+ for (int i = 0; i < seq.count(); i++)
+ results.append(seq.at(i).value<QBluetoothUuid>());
+
+ return results;
+}
+
+/*!
Makes a copy of the \a other and assigns it to this QBluetoothServiceInfo object.
The two copies continue to share the same service and registration details.
*/
diff --git a/src/bluetooth/qbluetoothserviceinfo.h b/src/bluetooth/qbluetoothserviceinfo.h
index 0e6555c0..4d3b8612 100644
--- a/src/bluetooth/qbluetoothserviceinfo.h
+++ b/src/bluetooth/qbluetoothserviceinfo.h
@@ -141,7 +141,7 @@ public:
inline void setServiceUuid(const QBluetoothUuid &uuid);
inline QBluetoothUuid serviceUuid() const;
- inline QList<QBluetoothUuid> serviceClassUuids() const;
+ QList<QBluetoothUuid> serviceClassUuids() const;
QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other);
@@ -228,12 +228,6 @@ inline QBluetoothUuid QBluetoothServiceInfo::serviceUuid() const
{
return attribute(ServiceId).value<QBluetoothUuid>();
}
-
-inline QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const
-{
- return attribute(ServiceClassIds).value<QList<QBluetoothUuid> >();
-}
-
QT_END_NAMESPACE
#endif