summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-07-09 14:15:59 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-12 02:28:35 +0200
commit5464963f9afae3bf7329d9b0ea7102231125f794 (patch)
tree840eaf19cea84d2185105272a651dc1675130731
parenta355c3a54cdc1c8bfd2129307c7824dd7012bd11 (diff)
Blackberry: Implement buffering
The API provided by QSensor does not fit nicely for what the OS service API provides. Instead of adding yet another buffer-related property to QSensor, I added documentation to QSensor describing the differences in behaviour. Change-Id: I2d81d9c62ce7e8b50c27631a28aa7fbcaca70373 Reviewed-by: Adam Parco <aparco@rim.com> Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.cpp23
-rw-r--r--src/sensors/qsensor.cpp11
2 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
index 7a8a2933..c13bc585 100644
--- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
@@ -45,6 +45,7 @@
#include <fcntl.h>
static const int microSecondsPerSecond = 1000 * 1000;
+static const int defaultBufferSize = 10;
static int microSecondsToHertz(uint microSeconds)
{
@@ -62,6 +63,10 @@ BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_
{
QCoreApplication::instance()->installEventFilter(this);
connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty()));
+
+ // Set some sensible default values
+ sensor->setProperty("efficientBufferSize", defaultBufferSize);
+ sensor->setProperty("maxBufferSize", defaultBufferSize);
}
QFile &BbSensorBackendBase::deviceFile()
@@ -169,6 +174,24 @@ void BbSensorBackendBase::start()
return;
}
+ // Activate event queuing if needed
+ bool ok = false;
+ const int requestedBufferSize = sensor()->property("bufferSize").toInt(&ok);
+ if (ok && requestedBufferSize > 1) {
+ sensor_devctl_queue_u queueControl;
+ queueControl.tx.enable = 1;
+ const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL);
+ if (result != EOK) {
+ perror(QString::fromLatin1("Enabling sensor queuing for %1 failed")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
+ }
+
+ const int actualBufferSize = queueControl.rx.size;
+ sensor()->setProperty("bufferSize", actualBufferSize);
+ sensor()->setProperty("efficientBufferSize", actualBufferSize);
+ sensor()->setProperty("maxBufferSize", actualBufferSize);
+ }
+
applyAlwaysOnProperty();
m_socketNotifier.reset(new QSocketNotifier(m_deviceFile.handle(), QSocketNotifier::Read));
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
index 2949e771..be0c7862 100644
--- a/src/sensors/qsensor.cpp
+++ b/src/sensors/qsensor.cpp
@@ -776,6 +776,17 @@ int QSensor::error() const
When the sensor is started with buffering option, values are collected from that
moment onwards. There is no pre-existing buffer that can be utilized.
+ Some backends like Blackberry only support enabling or disabling the buffer and do not give
+ control over the size. In this case, the maxBufferSize and efficientBufferSize properties
+ might not be set at all, even though buffering is supported. Setting the bufferSize property
+ to any value greater than 1 will enable buffering. After the sensor has been started,
+ the bufferSize property will be set to the actual value by the backend.
+
+ On Blackberry, buffering will not wait until the buffer is full to deliver new
+ readings. Instead, the buffer will be used if the backend does not manage to retrieve the readings
+ in time, for example when the event loop is blocked for too long. Without a buffer, these readings
+ would simply be dropped.
+
The buffer size can only be changed while the sensor is not active.
\sa QSensor::maxBufferSize, QSensor::efficientBufferSize