summaryrefslogtreecommitdiff
path: root/src/location
diff options
context:
space:
mode:
authorCarsten Bürger <carsten.burger@nokia.com>2011-12-02 16:11:19 +0100
committerQt by Nokia <qt-info@nokia.com>2011-12-08 00:46:51 +0100
commit3b00c5c23c56554b9e160c41e619f1c62c9f1757 (patch)
treeae32b9367f60997c162830b1d709b1a0b1971fbc /src/location
parent81453d0345d49c492e9becfaefea28d9e156b7fa (diff)
downloadqtlocation-3b00c5c23c56554b9e160c41e619f1c62c9f1757.tar.gz
adding updateInterval to qGeoSatelliteInfoSource
Change-Id: I58e4263c3ddb9f4c9d6fc6f805a34acb0de7c863 Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/location')
-rw-r--r--src/location/qgeosatelliteinfosource.cpp80
-rw-r--r--src/location/qgeosatelliteinfosource.h9
-rw-r--r--src/location/qgeosatelliteinfosource_npe_backend.cpp90
-rw-r--r--src/location/qgeosatelliteinfosource_npe_backend_p.h6
4 files changed, 171 insertions, 14 deletions
diff --git a/src/location/qgeosatelliteinfosource.cpp b/src/location/qgeosatelliteinfosource.cpp
index b7a586df..9bd22597 100644
--- a/src/location/qgeosatelliteinfosource.cpp
+++ b/src/location/qgeosatelliteinfosource.cpp
@@ -76,6 +76,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
class QGeoSatelliteInfoSourcePrivate
{
public:
+ int interval;
static QList<QGeoPositionInfoSourceFactory*> pluginsSorted();
static QHash<QString, QGeoPositionInfoSourceFactory*> plugins(bool reload = false);
static void loadDynamicPlugins(QHash<QString, QGeoPositionInfoSourceFactory*> &plugins);
@@ -205,6 +206,7 @@ void QGeoSatelliteInfoSourcePrivate::loadStaticPlugins(QHash<QString, QGeoPositi
qobject_cast<QGeoPositionInfoSourceFactory*>(staticPlugins.at(i));
if (f) {
+
QString name = f->sourceName();
#if !defined QT_NO_DEBUG
@@ -237,18 +239,80 @@ void QGeoSatelliteInfoSourcePrivate::loadStaticPlugins(QHash<QString, QGeoPositi
When an update is available, satellitesInViewUpdated() and/or
satellitesInUseUpdated() will be emitted.
+ If regular satellite updates are required, setUpdateInterval() can be used
+ to specify how often these updates should be emitted. If no interval is
+ specified, updates are simply provided whenever they are available.
+ For example:
+
+ \code
+ // Emit updates every 10 seconds if available
+ QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0);
+ if (source)
+ source->setUpdateInterval(10000);
+ \endcode
+
+ To remove an update interval that was previously set, call
+ setUpdateInterval() with a value of 0.
+
+ Note that the satellite source may have a minimum value requirement for
+ update intervals, as returned by minimumUpdateInterval().
+
\warning On Windows CE it is not possible to detect if a device is GPS enabled.
The default satellite source on a Windows CE device without GPS support will never provide any satellite data.
*/
/*!
- Creates a source with the specified \a parent.
+ Creates a satellite source with the specified \a parent.
*/
QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ d(new QGeoSatelliteInfoSourcePrivate)
+{
+ d->interval = 0;
+}
+
+/*!
+ Destroys the satellite source.
+*/
+QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource()
+{
+ delete d;
+}
+
+/*!
+ \property QGeoSatelliteInfoSource::updateInterval
+ \brief This property holds the requested interval in milliseconds between each update.
+
+ If the update interval is not set (or is set to 0) the
+ source will provide updates as often as necessary.
+
+ If the update interval is set, the source will provide updates at an
+ interval as close to the requested interval as possible. If the requested
+ interval is less than the minimumUpdateInterval(),
+ the minimum interval is used instead.
+
+ Changes to the update interval will happen as soon as is practical, however the
+ time the change takes may vary between implementations. Whether or not the elapsed
+ time from the previous interval is counted as part of the new interval is also
+ implementation dependent.
+
+ The default value for this property is 0.
+
+ Note: Subclass implementations must call the base implementation of
+ setUpdateInterval() so that updateInterval() returns the correct value.
+*/
+void QGeoSatelliteInfoSource::setUpdateInterval(int msec)
+{
+ d->interval = msec;
+}
+
+int QGeoSatelliteInfoSource::updateInterval() const
{
+ return d->interval;
}
+
+
/*!
Creates and returns a source with the specified \a parent that reads
from the system's default source of satellite update information, or the
@@ -369,6 +433,15 @@ QStringList QGeoSatelliteInfoSource::availableSources()
*/
/*!
+ \property QGeoSatelliteInfoSource::minimumUpdateInterval
+ \brief This property holds the minimum time (in milliseconds) required to retrieve a satellite update.
+
+ This is the minimum value accepted by setUpdateInterval() and
+ requestUpdate().
+*/
+
+
+/*!
\fn virtual void QGeoSatelliteInfoSource::startUpdates() = 0;
Starts emitting updates at regular intervals. The updates will be
@@ -389,7 +462,8 @@ QStringList QGeoSatelliteInfoSource::availableSources()
Attempts to get the current satellite information and emit
satellitesInViewUpdated() and satellitesInUseUpdated() with this
information. If the current position cannot be found
- within the given \a timeout (in milliseconds), requestTimeout() is
+ within the given \a timeout (in milliseconds) or if \a timeout is less than the value returned by
+ minimumUpdateInterval(), requestTimeout() is
emitted.
If the timeout is zero, the timeout defaults to a reasonable timeout
diff --git a/src/location/qgeosatelliteinfosource.h b/src/location/qgeosatelliteinfosource.h
index 4206888d..0bc02224 100644
--- a/src/location/qgeosatelliteinfosource.h
+++ b/src/location/qgeosatelliteinfosource.h
@@ -51,18 +51,25 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
class QGeoSatelliteInfoSourcePrivate;
class Q_LOCATION_EXPORT QGeoSatelliteInfoSource : public QObject
{
Q_OBJECT
+ Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval)
+ Q_PROPERTY(int minimumUpdateInterval READ minimumUpdateInterval)
+
public:
explicit QGeoSatelliteInfoSource(QObject *parent);
+ virtual ~QGeoSatelliteInfoSource();
static QGeoSatelliteInfoSource *createDefaultSource(QObject *parent);
static QGeoSatelliteInfoSource *createSource(const QString &sourceName, QObject *parent);
static QStringList availableSources();
+ virtual void setUpdateInterval(int msec);
+ int updateInterval() const;
+ virtual int minimumUpdateInterval() const = 0;
+
public Q_SLOTS:
virtual void startUpdates() = 0;
virtual void stopUpdates() = 0;
diff --git a/src/location/qgeosatelliteinfosource_npe_backend.cpp b/src/location/qgeosatelliteinfosource_npe_backend.cpp
index 8717c7b7..4c240f6e 100644
--- a/src/location/qgeosatelliteinfosource_npe_backend.cpp
+++ b/src/location/qgeosatelliteinfosource_npe_backend.cpp
@@ -41,14 +41,16 @@
#include "qgeosatelliteinfosource_npe_backend_p.h"
#include <sys/stat.h>
-
+// #include <mtlocationd/locationd-strings.h>
// API for socket communication towards locationd
const QString ksatelliteStartUpdates = QLatin1String("satelliteStartUpdates");
const QString ksatelliteRequestUpdate = QLatin1String("satelliteRequestUpdate");
const QString ksatelliteStopUpdates = QLatin1String("satelliteStopUpdates");
const QString ksatelliteInfoUpdate = QLatin1String("satelliteInfoUpdate");
-
+const QString ksetUpdateInterval = QLatin1String("setUpdateInterval");
+const QString kgetMinimumUpdateInterval = QLatin1String("getMinimumUpdateInterval");
+const QString kgetMinimumUpdateIntervalReply = QLatin1String("getMinimumUpdateIntervalReply");
// Attributes for socket communication towards locationd
const QString ksatId = QLatin1String("satId");
const QString kazimuth = QLatin1String("azimuth");
@@ -59,6 +61,8 @@ const QString ksystem = QLatin1String("system"); // {"GPS", "SBASS", "GLONASS",
const QString kGPS = QLatin1String("GPS");
const QString kGLONASS = QLatin1String("GLONASS");
const QString ksatStatus = QLatin1String("satStatus");
+const QString kinterval = QLatin1String("interval");
+
// Bitmask Table for satStatus
// Satellite is above elevation mask
@@ -87,7 +91,7 @@ bool QGeoSatelliteInfoSourceNpeBackend::init()
if (mStream) {
connect(mStream, SIGNAL(receive(const QVariantMap&)), this, SLOT(onStreamReceived(const QVariantMap&)), Qt::QueuedConnection);
}
- mSocket->connectToServer("/var/run/locationd/locationd.socket");
+ mSocket->connectToServer((QLatin1String)"/var/run/locationd/locationd.socket");
return(mSocket->waitForConnected(500)); // wait up to 0.5 seconds to get connected, otherwise return false
}
}
@@ -95,6 +99,40 @@ bool QGeoSatelliteInfoSourceNpeBackend::init()
}
+void QGeoSatelliteInfoSourceNpeBackend::setUpdateInterval(int msec)
+{
+ QVariantMap action;
+ QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
+ connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
+ action.insert(JsonDbString::kActionStr, kgetMinimumUpdateInterval);
+ mStream->send(action);
+ loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
+ if (msec < minInterval && msec != 0)
+ msec = minInterval;
+ QGeoSatelliteInfoSource::setUpdateInterval(msec);
+ if (!requestTimer->isActive()) {
+ QVariantMap actionUpdate;
+ QVariantMap object;
+ actionUpdate.insert(JsonDbString::kActionStr, ksetUpdateInterval);
+ object.insert(kinterval, msec);
+ actionUpdate.insert(JsonDbString::kDataStr, object);
+ mStream->send(actionUpdate);
+ }
+}
+
+
+int QGeoSatelliteInfoSourceNpeBackend::minimumUpdateInterval() const
+{
+ QVariantMap action;
+ QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
+ connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
+ action.insert(JsonDbString::kActionStr, kgetMinimumUpdateInterval);
+ mStream->send(action);
+ loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
+ return(minInterval);
+}
+
+
void QGeoSatelliteInfoSourceNpeBackend::startUpdates()
{
if (!satOngoing) {
@@ -121,8 +159,24 @@ void QGeoSatelliteInfoSourceNpeBackend::requestUpdate(int timeout)
{
// ignore if another requestUpdate is still pending
if (!requestTimer->isActive()) {
- if (timeout == 0) {
- timeout = 30000; // set timeout to 30s if provided timeout is 0
+ int minimumInterval = minimumUpdateInterval();
+ if (timeout == 0)
+ timeout = 5*minimumInterval; // set reasonable timeout if provided timeout is 0
+ // do not start request if timeout can not be fullfilled by the source
+ if (timeout < minimumInterval) {
+ emit requestTimeout();
+ return;
+ }
+ // get satellite update as fast as possible in case of ongoing tracking session
+ if ( satOngoing ) {
+ if ( QGeoSatelliteInfoSource::updateInterval() != minimumInterval) {
+ QVariantMap actionUpdate;
+ QVariantMap object;
+ actionUpdate.insert(JsonDbString::kActionStr, ksetUpdateInterval);
+ object.insert(kinterval, minimumInterval);
+ actionUpdate.insert(JsonDbString::kDataStr, object);
+ mStream->send(actionUpdate);
+ }
}
// request the update only if no tracking session is active
if ( !satOngoing) {
@@ -137,8 +191,20 @@ void QGeoSatelliteInfoSourceNpeBackend::requestUpdate(int timeout)
void QGeoSatelliteInfoSourceNpeBackend::requestTimerExpired()
{
- requestTimer->stop();
emit requestTimeout();
+ shutdownRequestSession();
+}
+
+
+void QGeoSatelliteInfoSourceNpeBackend::shutdownRequestSession()
+{
+ requestTimer->stop();
+ // Restore updateInterval from before Request Session in case of ongoing tracking session
+ if ( satOngoing ) {
+ int minimumInterval = minimumUpdateInterval();
+ if ( QGeoSatelliteInfoSource::updateInterval() != minimumInterval)
+ setUpdateInterval(QGeoSatelliteInfoSource::updateInterval());
+ }
}
@@ -148,6 +214,12 @@ void QGeoSatelliteInfoSourceNpeBackend::onStreamReceived(const QVariantMap& map)
if (map.contains(JsonDbString::kActionStr)) {
QString action = map.value(JsonDbString::kActionStr).toString();
+ if (action == kgetMinimumUpdateIntervalReply) {
+ QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
+ minInterval = tmp.value(kinterval).toInt();
+ emit minimumUpdateIntervalReceived();
+ }
+
if (action == ksatelliteInfoUpdate) {
QVariantMap sat_info = map.value(JsonDbString::kDataStr).toMap();
if (sat_info.contains(ksatList))
@@ -180,10 +252,11 @@ void QGeoSatelliteInfoSourceNpeBackend::onStreamReceived(const QVariantMap& map)
}
if (inUse.count() > 0) // emit updated signal if satellite list is not empty
emit satellitesInUseUpdated(inUse);
+ qDebug() << "emit satelliteUpdated signals: in use count: " << inUse.count() << ", in view count: " <<inView.count();
if (inView.count() > 0)
emit satellitesInViewUpdated(inView);
if ( requestTimer->isActive() )
- requestTimer->stop();
+ shutdownRequestSession();
}
}
}
@@ -199,6 +272,3 @@ void QGeoSatelliteInfoSourceNpeBackend::onSocketConnected()
void QGeoSatelliteInfoSourceNpeBackend::onSocketDisconnected()
{
}
-
-
-
diff --git a/src/location/qgeosatelliteinfosource_npe_backend_p.h b/src/location/qgeosatelliteinfosource_npe_backend_p.h
index ded4c055..94d084f4 100644
--- a/src/location/qgeosatelliteinfosource_npe_backend_p.h
+++ b/src/location/qgeosatelliteinfosource_npe_backend_p.h
@@ -58,6 +58,7 @@
#include <mtcore/variantstream.h>
#include <private/jsondb-strings_p.h>
#include <qlocalsocket.h>
+#include <qeventloop.h>
#include <qtimer.h>
@@ -70,6 +71,8 @@ class QGeoSatelliteInfoSourceNpeBackend: public QGeoSatelliteInfoSource
public:
QGeoSatelliteInfoSourceNpeBackend(QObject *parent = 0);
bool init();
+ void setUpdateInterval(int interval);
+ int minimumUpdateInterval() const;
public Q_SLOTS:
void startUpdates();
@@ -78,18 +81,21 @@ public Q_SLOTS:
Q_SIGNALS:
void requestTimeout();
+ void minimumUpdateIntervalReceived();
private Q_SLOTS:
void onStreamReceived(const QVariantMap& map);
void onSocketConnected();
void onSocketDisconnected();
void requestTimerExpired();
+ void shutdownRequestSession();
private:
QLocalSocket* mSocket;
VariantStream* mStream;
bool satOngoing;
QTimer* requestTimer;
+ int minInterval;
};
#endif // QGEOSATELLITEINFOSOURCE_NPE_BACKEND_H