diff options
author | Fabian Bumberger <fbumberger@rim.com> | 2013-08-07 10:16:22 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-07 15:46:37 +0200 |
commit | 5402b11d4f21e135181ccf909e6d8b1a9c347d4b (patch) | |
tree | 2d8b50f28a7cf2d102f1cd753e3c4f8351b7f420 /src | |
parent | c519d87265d61b6f81c8db2437781478f094402d (diff) |
QNX: Close the BT control FD with a delay
Otherwise messages might not be passed to the BT service correctly.
Change-Id: I3ff26caa853283b09a995806631fdc82ac851e6f
Reviewed-by: Bernd Weimer <bweimer@blackberry.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qnx/ppshelpers.cpp | 27 | ||||
-rw-r--r-- | src/bluetooth/qnx/ppshelpers_p.h | 5 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/bluetooth/qnx/ppshelpers.cpp b/src/bluetooth/qnx/ppshelpers.cpp index eb7f4f31..1b1eb82b 100644 --- a/src/bluetooth/qnx/ppshelpers.cpp +++ b/src/bluetooth/qnx/ppshelpers.cpp @@ -43,6 +43,7 @@ #include <QtCore/private/qcore_unix_p.h> #include <QDebug> #include "../qrfcommserver_p.h" +#include <QTimer> QT_BEGIN_NAMESPACE_BLUETOOTH @@ -61,6 +62,10 @@ static const int ppsBufferSize = 1024; static int ctrlId = 20; +static QList<QPair<int, QObject*> > waitingCtrlMsgs; + +static BBSocketNotifier bbSocketNotifier; + QHash<QRfcommServerPrivate*, int> __fakeServerPorts; QList<QPair<QString, QObject*> > evtRegistration; @@ -71,6 +76,16 @@ void BBSocketNotifier::distribute() ppsDecodeControlResponse(); } +void BBSocketNotifier::closeControlFD() +{ + if (count <= 0) { + qt_safe_close(ppsCtrlFD); + ppsCtrlFD = -1; + delete ppsCtrlNotifier; + ppsCtrlNotifier = 0; + } +} + QPair<int, QObject*> takeObjectInWList(int id) { for (int i=0; i<waitingCtrlMsgs.size(); i++) { @@ -84,7 +99,7 @@ void ppsRegisterControl() { qBBBluetoothDebug() << "Register for Control"; if (count == 0) { - ppsCtrlFD = qt_safe_open(btControlFDPath, O_RDWR | O_NONBLOCK); + ppsCtrlFD = qt_safe_open(btControlFDPath, O_RDWR | O_SYNC); if (ppsCtrlFD == -1) { qWarning() << Q_FUNC_INFO << "ppsCtrlFD - failed to qt_safe_open" << btControlFDPath; } else { @@ -100,10 +115,10 @@ void ppsUnregisterControl(QObject *obj) qBBBluetoothDebug() << "Unregistering Control"; count--; if (count == 0) { - qt_safe_close(ppsCtrlFD); - ppsCtrlFD = -1; - delete ppsCtrlNotifier; - ppsCtrlNotifier = 0; + //QMetaObject::invokeMethod(&bbSocketNotifier, "closeControlFD",Qt::QueuedConnection); + //We need to postpone the closing of the file descriptor, otherwise the last message + //might not have gone through...a queued connection is not enough here + QTimer::singleShot(5, &bbSocketNotifier, SLOT(closeControlFD())); } for (int i = waitingCtrlMsgs.size()-1; i >= 0 ; i--) { if (waitingCtrlMsgs.at(i).second == obj) @@ -126,7 +141,7 @@ bool endCtrlMessage(pps_encoder_t *encoder) { qBBBluetoothDebug() << "writing" << pps_encoder_buffer(encoder); if (pps_encoder_buffer(encoder) != 0) { - int res = write(ppsCtrlFD, pps_encoder_buffer(encoder), pps_encoder_length(encoder)); + int res = qt_safe_write(ppsCtrlFD, pps_encoder_buffer(encoder), pps_encoder_length(encoder)); if (res == -1) { qWarning() << Q_FUNC_INFO << "Error when writing to control FD. Is Bluetooth powerd on?" << errno; return false; diff --git a/src/bluetooth/qnx/ppshelpers_p.h b/src/bluetooth/qnx/ppshelpers_p.h index d09768a3..3e7293f2 100644 --- a/src/bluetooth/qnx/ppshelpers_p.h +++ b/src/bluetooth/qnx/ppshelpers_p.h @@ -79,10 +79,9 @@ class BBSocketNotifier : public QObject Q_OBJECT public Q_SLOTS: void distribute(); + void closeControlFD(); }; -static BBSocketNotifier bbSocketNotifier; - enum ResultType {UNKNOWN, EVENT, MESSAGE, RESPONSE}; struct ppsResult { @@ -96,8 +95,6 @@ struct ppsResult { int error; }; -static QList<QPair<int, QObject*> > waitingCtrlMsgs; - QPair<int, QObject*> takeObjectInWList(int id); void ppsRegisterControl(); |