summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2013-11-22 16:03:16 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-25 04:07:13 +0100
commit642098c893be76ad9c049910661059bb926dc6d6 (patch)
tree0b65e03e9068c1366126eac9dc1d9e035a3902b4
parent090c01babee0ea2ee112ccf0c6eed5fe1efa69cc (diff)
downloadqtlocation-642098c893be76ad9c049910661059bb926dc6d6.tar.gz
Don't start Geoclue satellite providers until necessary.
This builds on 2509cc2f13b15de099c3d68769e9bce869400ef7. It implements similar changes to the Geoclue satellite info source. Change-Id: I657f110e049c84b35f534a3bfffd14d57ee9c37a Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp53
-rw-r--r--src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h2
2 files changed, 46 insertions, 9 deletions
diff --git a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp
index 6dcedeec..ffa976a8 100644
--- a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp
+++ b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp
@@ -155,10 +155,10 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, QList<QGeoSatelli
QGeoSatelliteInfoSourceGeoclueMaster::QGeoSatelliteInfoSourceGeoclueMaster(QObject *parent)
: QGeoSatelliteInfoSource(parent), QGeoclueMaster(this), m_sat(0), m_error(NoError),
- m_satellitesChangedConnected(false)
+ m_satellitesChangedConnected(false), m_running(false)
{
m_requestTimer.setSingleShot(true);
- connect(&m_requestTimer, SIGNAL(timeout()), this, SIGNAL(requestTimeout()));
+ connect(&m_requestTimer, SIGNAL(timeout()), this, SLOT(requestUpdateTimeout()));
}
QGeoSatelliteInfoSourceGeoclueMaster::~QGeoSatelliteInfoSourceGeoclueMaster()
@@ -170,7 +170,7 @@ bool QGeoSatelliteInfoSourceGeoclueMaster::init()
{
g_type_init();
- return configureSatelliteSource();
+ return true;
}
int QGeoSatelliteInfoSourceGeoclueMaster::minimumUpdateInterval() const
@@ -185,6 +185,16 @@ QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSourceGeoclueMaster::error() con
void QGeoSatelliteInfoSourceGeoclueMaster::startUpdates()
{
+ if (m_running)
+ return;
+
+ m_running = true;
+
+ // Start Geoclue provider.
+ if (!hasMasterClient())
+ configureSatelliteSource();
+
+ // m_sat is likely to be invalid until Geoclue master selects a position provider.
if (!m_sat)
return;
@@ -193,13 +203,24 @@ void QGeoSatelliteInfoSourceGeoclueMaster::startUpdates()
void QGeoSatelliteInfoSourceGeoclueMaster::stopUpdates()
{
- if (!m_sat)
+ if (!m_running)
+ return;
+
+ if (m_sat)
g_signal_handlers_disconnect_by_func(G_OBJECT(m_sat), gpointer(satellite_changed), this);
+
+ m_running = false;
+
+ // Only stop positioning if single update not requested.
+ if (!m_requestTimer.isActive()) {
+ cleanupSatelliteSource();
+ releaseMasterClient();
+ }
}
void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdate(int timeout)
{
- if ((timeout < minimumUpdateInterval() && timeout != 0) || !m_sat) {
+ if (timeout < minimumUpdateInterval() && timeout != 0) {
emit requestTimeout();
return;
}
@@ -207,8 +228,13 @@ void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdate(int timeout)
if (m_requestTimer.isActive())
return;
+ if (!hasMasterClient())
+ configureSatelliteSource();
+
m_requestTimer.start(qMax(timeout, minimumUpdateInterval()));
- geoclue_satellite_get_satellite_async(m_sat, satellite_callback, this);
+
+ if (m_sat)
+ geoclue_satellite_get_satellite_async(m_sat, satellite_callback, this);
}
void QGeoSatelliteInfoSourceGeoclueMaster::satelliteChanged(int timestamp, int satellitesUsed,
@@ -252,6 +278,18 @@ void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdateFinished(int timestamp,
satelliteChanged(timestamp, satellitesUsed, satellitesVisible, usedPrn, satInfos);
}
+void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdateTimeout()
+{
+ // If we end up here, there has not been a valid satellite info update.
+ emit requestTimeout();
+
+ // Only stop satellite info if regular updates not active.
+ if (!m_running) {
+ cleanupSatelliteSource();
+ releaseMasterClient();
+ }
+}
+
void QGeoSatelliteInfoSourceGeoclueMaster::positionProviderChanged(const QByteArray &service, const QByteArray &path)
{
if (m_sat)
@@ -326,9 +364,6 @@ void QGeoSatelliteInfoSourceGeoclueMaster::satellitesChanged(const QDBusMessage
bool QGeoSatelliteInfoSourceGeoclueMaster::configureSatelliteSource()
{
- cleanupSatelliteSource();
- releaseMasterClient();
-
return createMasterClient(GEOCLUE_ACCURACY_LEVEL_DETAILED, GEOCLUE_RESOURCE_GPS);
}
diff --git a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h
index 52cbb316..a770ee5f 100644
--- a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h
+++ b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h
@@ -78,6 +78,7 @@ public:
const QList<int> &usedPrn, const QList<QGeoSatelliteInfo> &satInfos);
private slots:
+ void requestUpdateTimeout();
void positionProviderChanged(const QByteArray &service, const QByteArray &path);
void satellitesChanged(const QDBusMessage &message);
@@ -91,6 +92,7 @@ private:
QList<QGeoSatelliteInfo> m_inUse;
Error m_error;
bool m_satellitesChangedConnected;
+ bool m_running;
};
QT_END_NAMESPACE