From 8f9b145b743764032f21dc9dc576347fd4a96532 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 3 Sep 2013 16:49:22 +1000 Subject: Fix Geoclue plugin when used with slow Geoclue providers. The Geoclue plugin expected the master provider to select a positioning provider quickly and would fail if one was not selected. This is likely to happen if the only provider available is GPS based and has to obtain a fix from a cold start. Fixed by changing the Geoclue plugin to report success as long as the master client interface is successfully created. Change-Id: Ib74e3800a2444eb80afd26c671371de884759119 Reviewed-by: Alex Blasche --- src/plugins/position/geoclue/qgeocluemaster.cpp | 19 ----- .../qgeopositioninfosource_geocluemaster.cpp | 84 ++++++---------------- .../qgeosatelliteinfosource_geocluemaster.cpp | 25 ++----- 3 files changed, 26 insertions(+), 102 deletions(-) (limited to 'src/plugins/position/geoclue') diff --git a/src/plugins/position/geoclue/qgeocluemaster.cpp b/src/plugins/position/geoclue/qgeocluemaster.cpp index a3eb9b14..7f34f9ab 100644 --- a/src/plugins/position/geoclue/qgeocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeocluemaster.cpp @@ -124,25 +124,6 @@ bool QGeoclueMaster::createMasterClient(GeoclueAccuracyLevel accuracy, GeoclueRe return false; } - char *service = 0; - char *path = 0; - - if (!geoclue_master_client_get_position_provider(m_client, 0, 0, &service, &path, 0) || - !qstrlen(service) || !qstrlen(path)) { - qCritical("QGeoclueMaster failed to get position provider service/path"); - g_object_unref(m_masterPosition); - m_masterPosition = 0; - g_object_unref(m_client); - m_client = 0; - return false; - } - - const QByteArray pService = QByteArray(service); - const QByteArray pPath = QByteArray(path); - - QMetaObject::invokeMethod(m_handler, "positionProviderChanged", Q_ARG(QByteArray, pService), - Q_ARG(QByteArray, pPath)); - return true; } diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp index 2279d832..d6269858 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp @@ -244,12 +244,7 @@ bool QGeoPositionInfoSourceGeoclueMaster::configurePositionSource(GeoclueAccurac cleanupPositionSource(); releaseMasterClient(); - if (!createMasterClient(accuracy, resourceFlags)) - return false; - - // createMasterClient() will call positionProviderChanged() slot on success, which sets m_pos - // and possibly m_vel. Return true if m_pos is set. - return m_pos; + return createMasterClient(accuracy, resourceFlags); } void QGeoPositionInfoSourceGeoclueMaster::cleanupPositionSource() @@ -282,16 +277,15 @@ void QGeoPositionInfoSourceGeoclueMaster::setPreferredPositioningMethods(Positio if (previousPreferredPositioningMethods == preferredPositioningMethods()) return; - bool status; switch (preferredPositioningMethods()) { case SatellitePositioningMethods: - status = configurePositionSource(GEOCLUE_ACCURACY_LEVEL_DETAILED, GEOCLUE_RESOURCE_GPS); + configurePositionSource(GEOCLUE_ACCURACY_LEVEL_DETAILED, GEOCLUE_RESOURCE_GPS); break; case NonSatellitePositioningMethods: - status = configurePositionSource(GEOCLUE_ACCURACY_LEVEL_NONE, GeoclueResourceFlags(GEOCLUE_RESOURCE_CELL | GEOCLUE_RESOURCE_NETWORK)); + configurePositionSource(GEOCLUE_ACCURACY_LEVEL_NONE, GeoclueResourceFlags(GEOCLUE_RESOURCE_CELL | GEOCLUE_RESOURCE_NETWORK)); break; case AllPositioningMethods: - status = configurePositionSource(GEOCLUE_ACCURACY_LEVEL_NONE, GEOCLUE_RESOURCE_ALL); + configurePositionSource(GEOCLUE_ACCURACY_LEVEL_NONE, GEOCLUE_RESOURCE_ALL); break; default: qWarning("GeoPositionInfoSourceGeoClueMaster unknown preferred method."); @@ -304,34 +298,6 @@ void QGeoPositionInfoSourceGeoclueMaster::setPreferredPositioningMethods(Positio m_lastPositionIsFresh = false; m_lastVelocityIsFresh = false; - - // If updates ongoing, connect to the new objects - if (m_updateTimer.isActive()) { - if (status) { - g_signal_connect (G_OBJECT (m_pos), "position-changed", - G_CALLBACK (position_changed),this); - if (m_vel) { - g_signal_connect (G_OBJECT (m_vel), "velocity-changed", - G_CALLBACK (velocity_changed),this); - } - } else { - // Changing source failed and there was active reques - m_updateTimer.stop(); - emit updateTimeout(); - } - } - // If a request ongoing, ask it from new object - if (m_requestTimer.isActive()) { - if (status) { - geoclue_position_get_position_async (m_pos, - (GeocluePositionCallback)position_callback, - this); - } else { - // Changing source failed and there was active reques - m_requestTimer.stop(); - emit updateTimeout(); - } - } } QGeoPositionInfo QGeoPositionInfoSourceGeoclueMaster::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const @@ -440,37 +406,27 @@ void QGeoPositionInfoSourceGeoclueMaster::startUpdatesTimeout() void QGeoPositionInfoSourceGeoclueMaster::positionProviderChanged(const QByteArray &service, const QByteArray &path) { - if (m_pos) { - if (service == dbus_g_proxy_get_bus_name(m_pos->provider.proxy) && - path == dbus_g_proxy_get_path(m_pos->provider.proxy)) { - // Provider hasn't actually changed. This can happen when first connecting as - // createMasterClient() will emit a signal independent of the DBus signal. - return; - } - + if (m_pos) cleanupPositionSource(); - } m_pos = geoclue_position_new(service.constData(), path.constData()); - if (!m_pos) - qCritical("QGeoPositionInfoSourceGeoclueMaster failed to get a position object"); - - if (m_pos) - g_signal_connect(G_OBJECT(m_pos), "position-changed", G_CALLBACK(position_changed), this); - - // Succeeding velocity is not mandatory. Master does not provide abstraction - // for velocity provider, hence directly get the current provider. - m_vel = geoclue_velocity_new(service.constData(), path.constData()); -#ifdef Q_LOCATION_GEOCLUE_DEBUG - if (!m_vel) - qDebug("QGeoPositionInfoSourceGeoclueMaster velocity provider not available."); -#endif + if (m_pos) { + if (m_updateTimer.isActive()) + g_signal_connect(G_OBJECT(m_pos), "position-changed", + G_CALLBACK(position_changed), this); - if (m_vel) - g_signal_connect(G_OBJECT(m_vel), "velocity-changed", G_CALLBACK(velocity_changed), this); + // Get the current position immediately. + geoclue_position_get_position_async(m_pos, position_callback, this); - // Get the current position immediately. - geoclue_position_get_position_async(m_pos, position_callback, this); + m_vel = geoclue_velocity_new(service.constData(), path.constData()); + if (m_vel && m_updateTimer.isActive()) + g_signal_connect(G_OBJECT(m_vel), "velocity-changed", + G_CALLBACK(velocity_changed), this); + } else { + m_updateTimer.stop(); + m_requestTimer.stop(); + emit updateTimeout(); + } } // Helper function to convert data into a QGeoPositionInfo diff --git a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp index c6dd9bdb..2a8d19fc 100644 --- a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp @@ -217,22 +217,14 @@ void QGeoSatelliteInfoSourceGeoclueMaster::requestUpdateFinished(int timestamp, void QGeoSatelliteInfoSourceGeoclueMaster::positionProviderChanged(const QByteArray &service, const QByteArray &path) { - if (m_sat) { - if (service == dbus_g_proxy_get_bus_name(m_sat->provider.proxy) && - path == dbus_g_proxy_get_path(m_sat->provider.proxy)) { - // Provider hasn't actually changed. This can happen when first connecting as - // createMasterClient() will emit a signal independent of the DBus signal. - return; - } - + if (m_sat) cleanupSatelliteSource(); - } m_sat = geoclue_satellite_new(service.constData(), path.constData()); - if (!m_sat) - qCritical("QGeoSatelliteInfoSourceGeoclueMaster failed to get a satellite object"); - else - g_signal_connect(G_OBJECT(m_sat), "satellite-changed", G_CALLBACK(satellite_changed), this); + if (m_sat) { + g_signal_connect(G_OBJECT(m_sat), "satellite-changed", + G_CALLBACK(satellite_changed), this); + } } bool QGeoSatelliteInfoSourceGeoclueMaster::configureSatelliteSource() @@ -240,12 +232,7 @@ bool QGeoSatelliteInfoSourceGeoclueMaster::configureSatelliteSource() cleanupSatelliteSource(); releaseMasterClient(); - if (!createMasterClient(GEOCLUE_ACCURACY_LEVEL_DETAILED, GEOCLUE_RESOURCE_GPS)) - return false; - - // createMasterClient() will call positionProviderChanged() slot on success, which sets m_sat. - // Return true if m_sat is set. - return m_sat; + return createMasterClient(GEOCLUE_ACCURACY_LEVEL_DETAILED, GEOCLUE_RESOURCE_GPS); } void QGeoSatelliteInfoSourceGeoclueMaster::cleanupSatelliteSource() -- cgit v1.2.1