summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qnx/ppshelpers.cpp
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-08-08 11:14:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-08 15:31:06 +0200
commitf0e7da6dab3a19a9c978f2cbba2dea60fcea619b (patch)
tree51006c66a4fdc0ae02f93f9cede817c751f4706b /src/bluetooth/qnx/ppshelpers.cpp
parent343107a157cde0e47698200c9ec6fe8f83cd49b5 (diff)
QNX: Make the device discovery agent more robust
Also fixes the autotests. Change-Id: I71983fa3cc49a88bb7b94544b7f24bebbd3cf86e Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qnx/ppshelpers.cpp')
-rw-r--r--src/bluetooth/qnx/ppshelpers.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/bluetooth/qnx/ppshelpers.cpp b/src/bluetooth/qnx/ppshelpers.cpp
index 1b1eb82b..5d05c88c 100644
--- a/src/bluetooth/qnx/ppshelpers.cpp
+++ b/src/bluetooth/qnx/ppshelpers.cpp
@@ -72,16 +72,15 @@ QList<QPair<QString, QObject*> > evtRegistration;
void BBSocketNotifier::distribute()
{
- qBBBluetoothDebug() << "Distributing";
ppsDecodeControlResponse();
}
void BBSocketNotifier::closeControlFD()
{
if (count <= 0) {
+ delete ppsCtrlNotifier;
qt_safe_close(ppsCtrlFD);
ppsCtrlFD = -1;
- delete ppsCtrlNotifier;
ppsCtrlNotifier = 0;
}
}
@@ -98,7 +97,12 @@ QPair<int, QObject*> takeObjectInWList(int id)
void ppsRegisterControl()
{
qBBBluetoothDebug() << "Register for Control";
- if (count == 0) {
+ count++;
+ if (count == 1) {
+ if (ppsCtrlFD != -1) {
+ qBBBluetoothDebug() << "PPS control FD not properly deinitialized";
+ return;
+ }
ppsCtrlFD = qt_safe_open(btControlFDPath, O_RDWR | O_SYNC);
if (ppsCtrlFD == -1) {
qWarning() << Q_FUNC_INFO << "ppsCtrlFD - failed to qt_safe_open" << btControlFDPath;
@@ -107,7 +111,6 @@ void ppsRegisterControl()
QObject::connect(ppsCtrlNotifier, SIGNAL(activated(int)), &bbSocketNotifier, SLOT(distribute()));
}
}
- count++;
}
void ppsUnregisterControl(QObject *obj)
@@ -143,7 +146,8 @@ bool endCtrlMessage(pps_encoder_t *encoder)
if (pps_encoder_buffer(encoder) != 0) {
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;
+ qWarning() << Q_FUNC_INFO << "Error when writing to control FD. Is Bluetooth powerd on?"
+ << errno << ppsCtrlFD;
return false;
}
}
@@ -201,7 +205,9 @@ void ppsDecodeControlResponse()
if (ppsCtrlFD != -1) {
char buf[ppsBufferSize];
- qt_safe_read( ppsCtrlFD, &buf, sizeof(buf) );
+ qt_safe_read(ppsCtrlFD, &buf, sizeof(buf) );
+ if (buf[0] != '@')
+ return;
qBBBluetoothDebug() << "CTRL Response" << buf;
pps_decoder_t ppsDecoder;
@@ -229,6 +235,11 @@ void ppsDecodeControlResponse()
if (pps_decoder_get_string(&ppsDecoder, "errstr", &buf) == PPS_DECODER_OK)
result.errorMsg = QString::fromUtf8(buf);
+ int dat;
+ if (pps_decoder_get_int(&ppsDecoder, "err", &dat) == PPS_DECODER_OK) {
+ result.error = dat;
+ }
+
//The dat object can be either a string or a array
pps_node_type_t nodeType = pps_decoder_type(&ppsDecoder,"dat");
if (nodeType == PPS_TYPE_STRING) {
@@ -276,7 +287,7 @@ void ppsDecodeControlResponse()
if (wMessage.second != 0)
wMessage.second->metaObject()->invokeMethod(wMessage.second, "controlReply", Q_ARG(ppsResult, result));
} else if (resType == EVENT) {
- qBBBluetoothDebug() << "Distributing event" << result.msg;
+ //qBBBluetoothDebug() << "Distributing event" << result.msg;
for (int i=0; i < evtRegistration.size(); i++) {
if (result.msg == evtRegistration.at(i).first)
evtRegistration.at(i).second->metaObject()->invokeMethod(evtRegistration.at(i).second, "controlEvent", Q_ARG(ppsResult, result));