summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserver_qnx.cpp
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-09-20 15:29:39 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-20 17:47:15 +0200
commitc231e60cd3aa982b10512c5c23bbca04223ed407 (patch)
treefabf340c905e4237d466f28e17e7dd83e664f804 /src/bluetooth/qbluetoothserver_qnx.cpp
parentac2edceb02a61c1d670312385b1d709417961799 (diff)
Error handling for QBluetoothServer
Task-number: QTBUG-32669 Change-Id: I0f12b19f7989972b7c8305f6e11a95f7f25a281d Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothserver_qnx.cpp')
-rw-r--r--src/bluetooth/qbluetoothserver_qnx.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/bluetooth/qbluetoothserver_qnx.cpp b/src/bluetooth/qbluetoothserver_qnx.cpp
index bc222b85..d937a275 100644
--- a/src/bluetooth/qbluetoothserver_qnx.cpp
+++ b/src/bluetooth/qbluetoothserver_qnx.cpp
@@ -54,7 +54,8 @@ QT_BEGIN_NAMESPACE
extern QHash<QBluetoothServerPrivate*, int> __fakeServerPorts;
QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol sType)
- : socket(0),maxPendingConnections(1),securityFlags(QBluetooth::NoSecurity), serverType(sType)
+ : socket(0),maxPendingConnections(1), securityFlags(QBluetooth::NoSecurity), serverType(sType),
+ m_lastError(QBluetoothServer::NoError)
{
ppsRegisterControl();
}
@@ -79,10 +80,16 @@ void QBluetoothServerPrivate::controlReply(ppsResult result)
int socketFD = ::open(result.dat.first().toStdString().c_str(), O_RDWR | O_NONBLOCK);
if (socketFD == -1) {
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
qWarning() << Q_FUNC_INFO << "RFCOMM Server: Could not open socket FD" << errno;
} else {
- if (!socket)
+ if (!socket) { // Should never happen
+ qWarning() << "Socket not valid";
+ m_lastError = QBluetoothServer::UnknownError;
+ emit q->error(m_lastError);
return;
+ }
socket->setSocketDescriptor(socketFD, QBluetoothServiceInfo::RfcommProtocol,
QBluetoothSocket::ConnectedState);
@@ -97,6 +104,7 @@ void QBluetoothServerPrivate::controlReply(ppsResult result)
void QBluetoothServerPrivate::controlEvent(ppsResult result)
{
+ Q_Q(QBluetoothServer);
if (result.msg == QStringLiteral("service_connected")) {
qBBBluetoothDebug() << "SPP: Server: Sending request for mount point path";
qBBBluetoothDebug() << result.dat;
@@ -113,6 +121,8 @@ void QBluetoothServerPrivate::controlEvent(ppsResult result)
ppsSendControlMessage("get_mount_point_path", 0x1101, m_uuid, nextClientAddress,
m_serviceName, this, BT_SPP_SERVER_SUBTYPE);
} else {
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
qWarning() << Q_FUNC_INFO << "address not specified in service connect reply";
}
}
@@ -122,8 +132,8 @@ void QBluetoothServer::close()
{
Q_D(QBluetoothServer);
if (!d->socket) {
- // there is no way to propagate the error to user
- // so just ignore the problem ;)
+ d->m_lastError = UnknownError;
+ emit error(d->m_lastError);
return;
}
d->socket->close();
@@ -137,10 +147,13 @@ void QBluetoothServer::close()
bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
{
Q_UNUSED(address)
- if (serverType() != QBluetoothServiceInfo::RfcommProtocol)
+ Q_D(QBluetoothServer);
+ if (serverType() != QBluetoothServiceInfo::RfcommProtocol) {
+ d->m_lastError = UnsupportedProtocolError;
+ emit error(d->m_lastError);
return false;
+ }
- Q_D(QBluetoothServer);
// listen has already been called before
if (d->socket && d->socket->state() == QBluetoothSocket::ListeningState)
return true;
@@ -164,6 +177,8 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
qBBBluetoothDebug() << "Port" << port << "registered";
} else {
qWarning() << "server with port" << port << "already registered or port invalid";
+ d->m_lastError = ServiceAlreadyRegisteredError;
+ emit error(d->m_lastError);
return false;
}