diff options
author | Alex Wilson <alex.wilson@nokia.com> | 2012-03-07 16:38:50 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-12 03:25:51 +0100 |
commit | 369fa99b132f8c1425da8a41f1436b8d86aaa50e (patch) | |
tree | a13d675390d1590df27c70a4ee47b6490cc58800 /src/plugins | |
parent | c435861528161ee931287034f41023c11dfb7ba3 (diff) | |
download | qtlocation-369fa99b132f8c1425da8a41f1436b8d86aaa50e.tar.gz |
Update positioning sources to use new plugin style
Notably, also splits the default sources that were previously compiled
into the library, out into their own plugins. This follows a similar
pattern to the geoservices change.
We also drop the "plugin whitelisting" feature in favour of a simple
Priority value in the plugin JSON -- the whitelist provides no
additional security over this solution on any of our platforms.
Task-number: QTBUG-24331
Change-Id: I62a9c940157ad2e33a9a575fa09633b98656b276
Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/plugins')
46 files changed, 4724 insertions, 1 deletions
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 94f3a9d9..27f910e8 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += geoservices +SUBDIRS += geoservices position diff --git a/src/plugins/position/geoclue/geoclue.pro b/src/plugins/position/geoclue/geoclue.pro new file mode 100644 index 00000000..1cd099d7 --- /dev/null +++ b/src/plugins/position/geoclue/geoclue.pro @@ -0,0 +1,30 @@ +load(qt_module) + +TARGET = qtposition_geoclue +QT += location gui + +load(qt_plugin) + +DESTDIR = $$QT.location.plugins/position +#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)" + +HEADERS += \ + qgeopositioninfosource_geocluemaster_p.h \ + qgeopositioninfosourcefactory_geoclue.h + +SOURCES += \ + qgeopositioninfosource_geocluemaster_p.h \ + qgeopositioninfosourcefactory_geoclue.cpp + +INCLUDEPATH += $$QT.location.includes + +CONFIG += qdbus link_pkgconfig +DEFINES += GEOCLUE_MASTER_AVAILABLE=1 +PKGCONFIG += geoclue +QMAKE_PKGCONFIG_REQUIRES += geoclue + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target + +OTHER_FILES += \ + plugin.json diff --git a/src/plugins/position/geoclue/plugin.json b/src/plugins/position/geoclue/plugin.json new file mode 100644 index 00000000..12970207 --- /dev/null +++ b/src/plugins/position/geoclue/plugin.json @@ -0,0 +1,7 @@ +{ + "Keys": ["geoclue"], + "Provider": "geoclue", + "Position": true, + "Satellite": false, + "Priority": 1000 +} diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp new file mode 100644 index 00000000..4da6c5e5 --- /dev/null +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp @@ -0,0 +1,556 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> + +#ifdef Q_LOCATION_GEOCLUE_DEBUG +#include <QDebug> +#endif + +#include "qgeopositioninfosource_geocluemaster_p.h" +#include <gconf/gconf-client.h> + +QT_BEGIN_NAMESPACE + +#define MINIMUM_UPDATE_INTERVAL 1000 +#define UPDATE_TIMEOUT_COLD_START 120000 + +// Callback for position-changed -signal +static void position_changed (GeocluePosition *position, + GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy, + gpointer userdata) // Ptr to this +{ + Q_UNUSED(position); + if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->regularUpdateFailed(); + } else { + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->regularUpdateSucceeded( + fields, timestamp, latitude, longitude, altitude, accuracy); + } +} + +// Callback for velocity-changed -signal +static void velocity_changed (GeoclueVelocity *velocity, + GeoclueVelocityFields fields, + int timestamp, + double speed, + double direction, + double climb, + gpointer userdata) // Ptr to this +{ + Q_UNUSED(velocity) + Q_UNUSED(timestamp) + Q_UNUSED(direction) + Q_UNUSED(climb) + if (!(fields & GEOCLUE_VELOCITY_FIELDS_SPEED)) { + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->velocityUpdateFailed(); + return; + } + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->velocityUpdateSucceeded(speed); +} + +// Callback for single async update +static void position_callback (GeocluePosition *pos, + GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy, + GError *error, + gpointer userdata) +{ + Q_UNUSED(pos); + Q_UNUSED(accuracy); + + if (error) + g_error_free (error); + if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE && + fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->singleUpdateFailed(); + + } else { + static_cast<QGeoPositionInfoSourceGeoclueMaster*>(userdata)->singleUpdateSucceeded( + fields, timestamp, latitude, longitude, altitude, accuracy); + } +} + +QGeoPositionInfoSourceGeoclueMaster::QGeoPositionInfoSourceGeoclueMaster(QObject *parent) + : QGeoPositionInfoSource(parent), m_updateInterval(0), m_preferredResources(GEOCLUE_RESOURCE_ALL), + m_preferredAccuracy(GEOCLUE_ACCURACY_LEVEL_NONE), + m_client(0), m_pos(0), m_vel(0), m_lastPositionIsFresh(false), m_lastVelocityIsFresh(false), + m_lastVelocity(0), m_lastPositionFromSatellite(false), m_methods(AllPositioningMethods) +{ + m_requestTimer.setSingleShot(true); + QObject::connect(&m_requestTimer, SIGNAL(timeout()), this, SLOT(requestUpdateTimeout())); + QObject::connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(startUpdatesTimeout())); +} + +QGeoPositionInfoSourceGeoclueMaster::~QGeoPositionInfoSourceGeoclueMaster() +{ + if (m_pos) + g_object_unref (m_pos); + if (m_vel) + g_object_unref(m_vel); + if (m_client) + g_object_unref (m_client); +} + +void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateFailed() +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster velocity update failed."; +#endif + // Set the velocitydata non-fresh. + m_lastVelocityIsFresh = false; +} + +void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateSucceeded(double speed) +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster velocity update succeeded, speed: " << speed; +#endif + // Store the velocity and mark it as fresh. Simple but hopefully adequate. + m_lastVelocity = speed * 0.514444; // convert knots to m/s + m_lastVelocityIsFresh = true; +} + +void QGeoPositionInfoSourceGeoclueMaster::singleUpdateFailed() +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster single update failed (requestUpdate)"; +#endif + if (m_requestTimer.isActive()) + m_requestTimer.stop(); + // Send timeout even if time wasn't up yet, because we are not trying again + emit updateTimeout(); +} + +void QGeoPositionInfoSourceGeoclueMaster::singleUpdateSucceeded(GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy) +{ + QGeoPositionInfo info = geoclueToPositionInfo(fields, timestamp, latitude, longitude, altitude, accuracy); + m_lastPosition = info; + if (m_requestTimer.isActive()) + m_requestTimer.stop(); + if (m_lastVelocityIsFresh) + info.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity); // assume groundspeed +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster single update succeeded: "; + qDebug() << "Lat, lon, alt, speed:" << info.coordinate().latitude() << info.coordinate().longitude() << info.coordinate().altitude() << info.attribute(QGeoPositionInfo::GroundSpeed); +#endif + emit positionUpdated(info); +} + +void QGeoPositionInfoSourceGeoclueMaster::regularUpdateFailed() +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster regular update failed."; +#endif + // Emit timeout and keep on listening in case error condition clears. + // Currently this is emitted each time an error occurs, and thereby it assumes + // that there does not come many erroneous updates from position source. + // This assumption may be invalid. + m_lastVelocityIsFresh = false; + m_lastPositionIsFresh = false; + if (m_updateTimer.isActive()) + emit updateTimeout(); +} + +void QGeoPositionInfoSourceGeoclueMaster::regularUpdateSucceeded(GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy) +{ + m_lastPosition = geoclueToPositionInfo(fields, timestamp, latitude, longitude, altitude, accuracy); + m_lastPositionIsFresh = true; + if (m_lastVelocityIsFresh) { + m_lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity); // assume groundspeed + m_lastVelocityIsFresh = false; + } + // If a non-intervalled startUpdates has been issued, send an update. + if (!m_updateTimer.isActive()) { + m_lastPositionIsFresh = false; + emit positionUpdated(m_lastPosition); + } +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster regular update succeeded: "; + qDebug() << "Lat, lon, alt, speed:" << m_lastPosition.coordinate().latitude() << m_lastPosition.coordinate().longitude() << m_lastPosition.coordinate().altitude() << m_lastPosition.attribute(QGeoPositionInfo::GroundSpeed); +#endif +} + +bool QGeoPositionInfoSourceGeoclueMaster::tryGPS() +{ + // Check if the gconf value is set properly + GConfClient* client; + gchar* device_name; + client = gconf_client_get_default(); + device_name = gconf_client_get_string(client, "/apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice", NULL); + QString deviceName(QString::fromAscii(device_name)); + g_object_unref(client); + g_free(device_name); + + if (deviceName.isEmpty()) { + return false; + } else { + // Check if the device exists (does nothing if a bluetooth address) + if (deviceName.trimmed().at(0) == '/' && QFile::exists(deviceName.trimmed())) { + return true; + } + return false; + } +} + +int QGeoPositionInfoSourceGeoclueMaster::init() +{ + g_type_init (); + // Check if there is sense to try GPS + if (tryGPS()) { + m_preferredResources = GEOCLUE_RESOURCE_GPS; + m_preferredAccuracy = GEOCLUE_ACCURACY_LEVEL_DETAILED; + if (configurePositionSource() != -1) { + return 0; + } else { + // If not successful, try to get any resource + m_preferredResources = GEOCLUE_RESOURCE_ALL; + m_preferredAccuracy = GEOCLUE_ACCURACY_LEVEL_NONE; + return configurePositionSource(); + } + } else { + return configurePositionSource(); + } +} + +int QGeoPositionInfoSourceGeoclueMaster::configurePositionSource() +{ + GeoclueMaster *master(0); + GError *error = 0; + // Free potential previous sources, because new requirements can't be set for the client + // (creating a position object after changing requirements seems to fail). + if (m_client) { + g_object_unref (m_client); + m_client = 0; + } + if (m_pos) { + g_object_unref(m_pos); + m_pos = 0; + } + if (m_vel) { + g_object_unref(m_vel); + m_vel = 0; + } + + master = geoclue_master_get_default (); + if (!master) { + qCritical ("QGeoPositionInfoSourceGeoclueMaster error creating GeoclueMaster"); + return -1; + } + + m_client = geoclue_master_create_client (master, NULL, &error); + g_object_unref (master); + + if (!m_client) { + qCritical ("QGeoPositionInfoSourceGeoclueMaster error creating GeoclueMasterClient."); + if (error) { + qCritical (error->message); + g_error_free (error); + } + return -1; + } + + if (!geoclue_master_client_set_requirements (m_client, + m_preferredAccuracy, // min_accuracy + 0, // min_time + TRUE, // require_updates (signals) + m_preferredResources, + &error)){ + qCritical ("QGeoPositionInfoSourceGeoclueMaster geoclue set_requirements failed."); + if (error) { + qCritical (error->message); + g_error_free (error); + } + g_object_unref (m_client); + m_client = 0; + return -1; + } + m_pos = geoclue_master_client_create_position (m_client, NULL); + if (!m_pos) { + qCritical("QGeoPositionInfoSourceGeoclueMaster failed to get a position object"); + g_object_unref (m_client); + m_client = 0; + return -1; + } + // Succeeding velocity is not mandatory. Master does not provide abstraction + // for velocity provider, hence request Gypsy provider directly. + m_vel = geoclue_velocity_new("org.freedesktop.Geoclue.Providers.Gypsy", + "/org/freedesktop/Geoclue/Providers/Gypsy"); +#ifdef Q_LOCATION_GEOCLUE_DEBUG + if (m_vel == NULL) + qDebug("QGeoPositionInfoSourceGeoclueMaster velocity provider (Gypsy) not available."); +#endif + return 0; +} + +void QGeoPositionInfoSourceGeoclueMaster::setUpdateInterval(int msec) +{ + msec = (((msec > 0) && (msec < minimumUpdateInterval())) || msec < 0)? minimumUpdateInterval() : msec; + QGeoPositionInfoSource::setUpdateInterval(msec); + m_updateInterval = msec; + // If update timer is running, set the new interval + if (m_updateTimer.isActive()) { + m_updateTimer.setInterval(msec); + } +} + +void QGeoPositionInfoSourceGeoclueMaster::setPreferredPositioningMethods(PositioningMethods methods) +{ + if (methods == m_methods) + return; + m_methods = methods; + + switch (methods) { + case SatellitePositioningMethods: + m_preferredResources = GEOCLUE_RESOURCE_GPS; + m_preferredAccuracy = GEOCLUE_ACCURACY_LEVEL_DETAILED; + break; + case NonSatellitePositioningMethods: + m_preferredResources = (GeoclueResourceFlags)(GEOCLUE_RESOURCE_CELL | GEOCLUE_RESOURCE_NETWORK); + m_preferredAccuracy = GEOCLUE_ACCURACY_LEVEL_NONE; + break; + case AllPositioningMethods: + m_preferredResources = GEOCLUE_RESOURCE_ALL; + m_preferredAccuracy = GEOCLUE_ACCURACY_LEVEL_NONE; + break; + default: + qWarning("GeoPositionInfoSourceGeoClueMaster unknown preferred method."); + return; + } + QGeoPositionInfoSource::setPreferredPositioningMethods(methods); +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster requested to set methods to, and set them to: " << methods << m_preferredResources; +#endif + m_lastPositionIsFresh = false; + m_lastVelocityIsFresh = false; + int status = configurePositionSource(); + + // If updates ongoing, connect to the new objects + if (m_updateTimer.isActive()) { + if (status != -1) { + 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 != -1) { + 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 +{ + if (fromSatellitePositioningMethodsOnly) { + if (m_lastPositionFromSatellite) + return m_lastPosition; + else + return QGeoPositionInfo(); + } + return m_lastPosition; +} + +QGeoPositionInfoSourceGeoclueMaster::PositioningMethods QGeoPositionInfoSourceGeoclueMaster::supportedPositioningMethods() const +{ + // There is no really knowing which methods the GeoClue master supports. + return AllPositioningMethods; +} + +void QGeoPositionInfoSourceGeoclueMaster::startUpdates() +{ + if (m_updateTimer.isActive()) { +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster timer was active, ignoring startUpdates: " << m_updateInterval; +#endif + return; + } + if (!m_pos) { + // May happen if source has been changed unsuccesfully + emit updateTimeout(); + return; + } + if (m_updateInterval > 0) { +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster startUpdates with interval: " << m_updateInterval; +#endif + m_updateTimer.start(m_updateInterval); + } + 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); + } +} + +int QGeoPositionInfoSourceGeoclueMaster::minimumUpdateInterval() const { + return MINIMUM_UPDATE_INTERVAL; +} + +void QGeoPositionInfoSourceGeoclueMaster::stopUpdates() +{ + if (m_updateTimer.isActive()) + m_updateTimer.stop(); + if (m_pos) { + g_signal_handlers_disconnect_by_func(G_OBJECT(m_pos), (void*)position_changed, this); + } if (m_vel) { + g_signal_handlers_disconnect_by_func(G_OBJECT(m_vel), (void*)velocity_changed, this); + } +} + +void QGeoPositionInfoSourceGeoclueMaster::requestUpdate(int timeout) +{ + if ((timeout < minimumUpdateInterval() && timeout != 0) || !m_pos) { + emit updateTimeout(); + return; + } + if (m_requestTimer.isActive()) { +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster request timer was active, ignoring startUpdates."; +#endif + return; + } + // Create better logic for timeout value (specs leave it impl dependant). + // Especially if there are active updates ongoing, there is no point of waiting + // for whole cold start time. + if (timeout == 0) + m_requestTimer.start(UPDATE_TIMEOUT_COLD_START); + else + m_requestTimer.start(timeout); + geoclue_position_get_position_async (m_pos, (GeocluePositionCallback)position_callback,this); +} + +void QGeoPositionInfoSourceGeoclueMaster::requestUpdateTimeout() +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster requestUpdate timeout occurred."; +#endif + // If we end up here, there has not been valid position update. + emit updateTimeout(); +} + +void QGeoPositionInfoSourceGeoclueMaster::startUpdatesTimeout() +{ +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster startUpdates timeout occurred."; +#endif + // Check if there are position updates since last positionUpdated(). + // Do not however send timeout, that's reserved for signaling errors. + if (m_lastPositionIsFresh) { + emit positionUpdated(m_lastPosition); + m_lastPositionIsFresh = false; + m_lastVelocityIsFresh = false; + } +} + +// Helper function to convert data into a QGeoPositionInfo +QGeoPositionInfo QGeoPositionInfoSourceGeoclueMaster::geoclueToPositionInfo( + GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy* accuracy) +{ + QGeoCoordinate coordinate(latitude, longitude); + QDateTime dateTime = QDateTime(); + dateTime.setTime_t(timestamp); + if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) { + coordinate.setAltitude(altitude); + } + QGeoPositionInfo info(coordinate, dateTime); + if (accuracy) { + double horizontalAccuracy; + double verticalAccuracy; + GeoclueAccuracyLevel accuracyLevel; + geoclue_accuracy_get_details(accuracy, &accuracyLevel, &horizontalAccuracy, &verticalAccuracy); +#ifdef Q_LOCATION_GEOCLUE_DEBUG + qDebug() << "QGeoPositionInfoSourceGeoclueMaster::accuracy horizontal vertical level: " << horizontalAccuracy << verticalAccuracy << accuracyLevel; +#endif + if (accuracyLevel & GEOCLUE_ACCURACY_LEVEL_DETAILED) + m_lastPositionFromSatellite = true; + else + m_lastPositionFromSatellite = false; + if (accuracyLevel != GEOCLUE_ACCURACY_LEVEL_NONE) { + info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, horizontalAccuracy); + info.setAttribute(QGeoPositionInfo::VerticalAccuracy, verticalAccuracy); + } + } + return info; +} + +#include "moc_qgeopositioninfosource_geocluemaster_p.cpp" +QT_END_NAMESPACE diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h new file mode 100644 index 00000000..8946767a --- /dev/null +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H +#define QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <qgeopositioninfosource.h> +#include <geoclue/geoclue-master.h> +#include <geoclue/geoclue-velocity.h> +#include <QTimer> + +//#define Q_LOCATION_GEOCLUE_DEBUG + +QT_BEGIN_NAMESPACE + +class QGeoPositionInfoSourceGeoclueMaster : public QGeoPositionInfoSource +{ + Q_OBJECT +public: + void positionChanged(GeocluePosition *position, + GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy); + QGeoPositionInfoSourceGeoclueMaster(QObject *parent = 0); + ~QGeoPositionInfoSourceGeoclueMaster(); + + // From QGeoPositionInfoSource + void setUpdateInterval(int msec); + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + PositioningMethods supportedPositioningMethods() const; + void setPreferredPositioningMethods(PositioningMethods methods); + int minimumUpdateInterval() const; + int init(); + + void singleUpdateFailed(); + void singleUpdateSucceeded(GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy); + void regularUpdateFailed(); + void regularUpdateSucceeded(GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy *accuracy); + void velocityUpdateFailed(); + void velocityUpdateSucceeded(double speed); + +public slots: + virtual void startUpdates(); + virtual void stopUpdates(); + virtual void requestUpdate(int timeout = 5000); + +private slots: + void requestUpdateTimeout(); + void startUpdatesTimeout(); + +private: + bool tryGPS(); + int configurePositionSource(); + QGeoPositionInfo geoclueToPositionInfo(GeocluePositionFields fields, + int timestamp, + double latitude, + double longitude, + double altitude, + GeoclueAccuracy* accuracy); +private: + int m_updateInterval; + GeoclueResourceFlags m_preferredResources; + GeoclueAccuracyLevel m_preferredAccuracy; + GeoclueMasterClient *m_client; + GeocluePosition *m_pos; + GeoclueVelocity* m_vel; + QTimer m_updateTimer; + QTimer m_requestTimer; + bool m_lastPositionIsFresh; + bool m_lastVelocityIsFresh; + double m_lastVelocity; + bool m_lastPositionFromSatellite; + QGeoPositionInfo m_lastPosition; + PositioningMethods m_methods; +}; + +QT_END_NAMESPACE + +#endif // QGEOPOSITIONINFOSOURCE_GEOCLUEMASTER_H diff --git a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp new file mode 100644 index 00000000..a4389d3f --- /dev/null +++ b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory_geoclue.h" +#include "qgeopositioninfosource_geocluemaster_p.h" + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryGeoclue::positionInfoSource(QObject *parent) +{ + return new QGeoPositionInfoSourceGeoclueMaster(parent); +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryGeoclue::satelliteInfoSource(QObject *parent) +{ + Q_UNUSED(parent); + return 0; +} diff --git a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h new file mode 100644 index 00000000..bdc896a7 --- /dev/null +++ b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_GEOCLUE_H +#define QGEOPOSITIONINFOSOURCEFACTORY_GEOCLUE_H + +#include <QObject> +#include "qgeopositioninfosource.h" +#include "qgeopositioninfosourcefactory.h" + +class QGeoPositionInfoSourceFactoryGeoclue : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0" + FILE "plugin.json") + Q_INTERFACES(QGeoPositionInfoSourceFactory) + +public: + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +#endif diff --git a/src/plugins/position/gypsy/gypsy.pro b/src/plugins/position/gypsy/gypsy.pro new file mode 100644 index 00000000..bf463379 --- /dev/null +++ b/src/plugins/position/gypsy/gypsy.pro @@ -0,0 +1,30 @@ +load(qt_module) + +TARGET = qtposition_gypsy +QT += location gui + +load(qt_plugin) + +DESTDIR = $$QT.location.plugins/position +#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)" + +HEADERS += \ + qgeosatelliteinfosource_gypsy_p.h \ + qgeopositioninfosourcefactory_gypsy.h + +SOURCES += \ + qgeosatelliteinfosource_gypsy.cpp \ + qgeopositioninfosourcefactory_gypsy.cpp + +INCLUDEPATH += $$QT.location.includes + +CONFIG += qdbus link_pkgconfig +DEFINES += GYPSY_AVAILABLE=1 +PKGCONFIG += gypsy +QMAKE_PKGCONFIG_REQUIRES += gypsy + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target + +OTHER_FILES += \ + plugin.json diff --git a/src/plugins/position/gypsy/plugin.json b/src/plugins/position/gypsy/plugin.json new file mode 100644 index 00000000..faa990cc --- /dev/null +++ b/src/plugins/position/gypsy/plugin.json @@ -0,0 +1,7 @@ +{ + "Keys": ["gypsy"], + "Provider": "gypsy", + "Position": false, + "Satellite": true, + "Priority": 1000 +} diff --git a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp new file mode 100644 index 00000000..6fe417ab --- /dev/null +++ b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory_gypsy.h" +#include "qgeosatelliteinfosource_gypsy_p.h" + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryGypsy::positionInfoSource(QObject *parent) +{ + Q_UNUSED(parent); + return 0; +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryGypsy::satelliteInfoSource(QObject *parent) +{ + return new QGeoSatelliteInfoSourceGypsy(parent); +} diff --git a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h new file mode 100644 index 00000000..effd5164 --- /dev/null +++ b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_GYPSY_H +#define QGEOPOSITIONINFOSOURCEFACTORY_GYPSY_H + +#include <QObject> +#include "qgeopositioninfosource.h" +#include "qgeopositioninfosourcefactory.h" + +class QGeoPositionInfoSourceFactoryGypsy : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0" + FILE "plugin.json") + Q_INTERFACES(QGeoPositionInfoSourceFactory) + +public: + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +#endif diff --git a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp new file mode 100644 index 00000000..9cc3a58c --- /dev/null +++ b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp @@ -0,0 +1,368 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeosatelliteinfosource_gypsy_p.h" + +#ifdef Q_LOCATION_GYPSY_DEBUG +#include <QDebug> +#endif +#include <QFile> + +QT_BEGIN_NAMESPACE + +#define UPDATE_TIMEOUT_COLD_START 120000 + + +// Callback function for 'satellites-changed' -signal +static void satellites_changed (GypsySatellite *satellite, + GPtrArray *satellites, + gpointer userdata) +{ +#ifdef Q_LOCATION_GYPSY_DEBUG + qDebug() << "QGeoSatelliteInfoSourceGypsy Gypsy satellites-changed -signal received."; +#endif + ((QGeoSatelliteInfoSourceGypsy*)userdata)->satellitesChanged(satellite, satellites); +} + +SatelliteGypsyEngine::SatelliteGypsyEngine(QGeoSatelliteInfoSource* parent) : + m_owner(parent) +{ +} +SatelliteGypsyEngine::~SatelliteGypsyEngine() +{ +} + +// Glib symbols +gulong SatelliteGypsyEngine::eng_g_signal_connect(gpointer instance, + const gchar* detailed_signal, + GCallback c_handler, + gpointer data) +{ + return ::g_signal_connect(instance, detailed_signal, c_handler, data); +} +guint SatelliteGypsyEngine::eng_g_signal_handlers_disconnect_by_func (gpointer instance, + gpointer func, + gpointer data) +{ + return ::g_signal_handlers_disconnect_by_func(instance, func, data); +} + +void SatelliteGypsyEngine::eng_g_free(gpointer mem) +{ + return ::g_free(mem); +} +// Gypsy symbols +GypsyControl* SatelliteGypsyEngine::eng_gypsy_control_get_default (void) +{ + return ::gypsy_control_get_default(); +} +char *SatelliteGypsyEngine::eng_gypsy_control_create (GypsyControl *control, const char*device_name, GError **error) +{ + return ::gypsy_control_create(control, device_name, error); +} +GypsyDevice *SatelliteGypsyEngine::eng_gypsy_device_new (const char *object_path) +{ + return ::gypsy_device_new(object_path); +} +GypsySatellite *SatelliteGypsyEngine::eng_gypsy_satellite_new (const char *object_path) +{ + return ::gypsy_satellite_new (object_path); +} +gboolean SatelliteGypsyEngine::eng_gypsy_device_start (GypsyDevice *device, GError **error) +{ + return ::gypsy_device_start(device, error); +} +gboolean SatelliteGypsyEngine::eng_gypsy_device_stop (GypsyDevice *device, GError **error) +{ + // Unfortunately this cannot be done; calling this will stop the GPS device + // (basically makes gypsy-daemon unusable for anyone), regardless of applications + // using it (see bug http://bugs.meego.com/show_bug.cgi?id=11707). + Q_UNUSED(device); + Q_UNUSED(error); + return true; + //return ::gypsy_device_stop (device, error); +} +GypsyDeviceFixStatus SatelliteGypsyEngine::eng_gypsy_device_get_fix_status (GypsyDevice *device, GError **error) +{ + return ::gypsy_device_get_fix_status (device, error); +} +GPtrArray *SatelliteGypsyEngine::eng_gypsy_satellite_get_satellites (GypsySatellite *satellite, GError **error) +{ + return ::gypsy_satellite_get_satellites (satellite, error); +} +void SatelliteGypsyEngine::eng_gypsy_satellite_free_satellite_array (GPtrArray *satellites) +{ + return ::gypsy_satellite_free_satellite_array(satellites); +} +// GConf symbols (mockability due to X11 requirement) +GConfClient* SatelliteGypsyEngine::eng_gconf_client_get_default(void) +{ + return ::gconf_client_get_default(); +} +gchar* SatelliteGypsyEngine::eng_gconf_client_get_string(GConfClient* client, const gchar* key, GError** err) +{ + return ::gconf_client_get_string(client, key, err); +} + +QGeoSatelliteInfoSourceGypsy::QGeoSatelliteInfoSourceGypsy(QObject *parent) : QGeoSatelliteInfoSource(parent), + m_engine(0), m_satellite(0), m_device(0), m_updatesOngoing(false), m_requestOngoing(false) +{ + m_requestTimer.setSingleShot(true); + QObject::connect(&m_requestTimer, SIGNAL(timeout()), this, SLOT(requestUpdateTimeout())); +} + +void QGeoSatelliteInfoSourceGypsy::createEngine() +{ + if (m_engine) + delete m_engine; + m_engine = new SatelliteGypsyEngine(this); +} + +QGeoSatelliteInfoSourceGypsy::~QGeoSatelliteInfoSourceGypsy() +{ + GError* error = NULL; + if (m_device) { + m_engine->eng_gypsy_device_stop (m_device, &error); + g_object_unref(m_device); + } + if (m_satellite) + g_object_unref(m_satellite); + if (error) + g_error_free(error); + if (m_engine) + delete m_engine; +} + +void QGeoSatelliteInfoSourceGypsy::satellitesChanged(GypsySatellite* satellite, + GPtrArray* satellites) +{ + if (!satellite || !satellites) + return; + // We have satellite data and assume it is valid. + // If a single updateRequest was active, send signals right away. + // If a periodic timer was running (meaning that the client wishes + // to have updates at defined intervals), store the data for later sending. + QList<QtMobility::QGeoSatelliteInfo> lastSatellitesInView; + QList<QtMobility::QGeoSatelliteInfo> lastSatellitesInUse; + + unsigned int i; + for (i = 0; i < satellites->len; i++) { + GypsySatelliteDetails *details = (GypsySatelliteDetails*)satellites->pdata[i]; + QGeoSatelliteInfo info; + info.setAttribute(QGeoSatelliteInfo::Elevation, details->elevation); + info.setAttribute(QGeoSatelliteInfo::Azimuth, details->azimuth); + info.setSignalStrength(details->snr); + if (details->in_use) + lastSatellitesInUse.append(info); + lastSatellitesInView.append(info); + } + bool sendUpdates(false); + // If a single updateRequest() has been issued: + if (m_requestOngoing) { + sendUpdates = true; + m_requestTimer.stop(); + m_requestOngoing = false; + // If there is no regular updates ongoing, disconnect now. + if (!m_updatesOngoing) { + m_engine->eng_g_signal_handlers_disconnect_by_func(G_OBJECT(m_satellite), (void*)satellites_changed, this); + } + } + // If regular updates are to be delivered as they come: + if (m_updatesOngoing) + sendUpdates = true; + + if (sendUpdates) { + emit satellitesInUseUpdated(lastSatellitesInUse); + emit satellitesInViewUpdated(lastSatellitesInView); + } +} + +int QGeoSatelliteInfoSourceGypsy::init() +{ + GError *error = NULL; + char *path; + GConfClient* client; + gchar* device_name; + + g_type_init (); + createEngine(); + + client = m_engine->eng_gconf_client_get_default(); + if (!client) { + qWarning ("QGeoSatelliteInfoSourceGypsy client creation failed."); + return -1; + } + device_name = m_engine->eng_gconf_client_get_string(client, "/apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice", NULL); + g_object_unref(client); + QString deviceName(QString::fromAscii(device_name)); + if (deviceName.isEmpty() || + (deviceName.trimmed().at(0) == '/' && !QFile::exists(deviceName.trimmed()))) { + qWarning ("QGeoSatelliteInfoSourceGypsy Empty/nonexistent GPS device name detected."); + qWarning ("Use gconftool-2 to set it, e.g. on terminal: "); + qWarning ("gconftool-2 -t string -s /apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice /dev/ttyUSB0"); + m_engine->eng_g_free(device_name); + return -1; + } + GypsyControl *control = NULL; + control = m_engine->eng_gypsy_control_get_default(); + if (!control) { + qWarning("QGeoSatelliteInfoSourceGypsy unable to create Gypsy control."); + m_engine->eng_g_free(device_name); + return -1; + } + // (path is the DBus path) + path = m_engine->eng_gypsy_control_create (control, device_name, &error); + m_engine->eng_g_free(device_name); + g_object_unref(control); + if (!path) { + qWarning ("QGeoSatelliteInfoSourceGypsy error creating client."); + if (error) { + qWarning ("error message: %s", error->message); + g_error_free (error); + } + return -1; + } + m_device = m_engine->eng_gypsy_device_new (path); + m_satellite = m_engine->eng_gypsy_satellite_new (path); + m_engine->eng_g_free(path); + if (!m_device || !m_satellite) { + qWarning ("QGeoSatelliteInfoSourceGypsy error creating satellite device."); + qWarning ("Is GPS device set correctly? If not, use gconftool-2 to set it, e.g.: "); + qWarning ("gconftool-2 -t string -s /apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice /dev/ttyUSB0"); + if (m_device) + g_object_unref(m_device); + if (m_satellite) + g_object_unref(m_satellite); + return -1; + } + m_engine->eng_gypsy_device_start (m_device, &error); + if (error) { + qWarning ("QGeoSatelliteInfoSourceGypsy error starting device: %s ", + error->message); + g_error_free(error); + g_object_unref(m_device); + g_object_unref(m_satellite); + return -1; + } + return 0; +} + +void QGeoSatelliteInfoSourceGypsy::startUpdates() +{ + if (m_updatesOngoing) + return; + // If there is a request timer ongoing, we've connected to the signal already + if (!m_requestTimer.isActive()) { + m_engine->eng_g_signal_connect (m_satellite, "satellites-changed", + G_CALLBACK (satellites_changed), this); + } + m_updatesOngoing = true; +} + +void QGeoSatelliteInfoSourceGypsy::stopUpdates() +{ + if (!m_updatesOngoing) + return; + m_updatesOngoing = false; + // Disconnect only if there is no single update request ongoing. Once single update request + // is completed and it notices that there is no active update ongoing, it will disconnect + // the signal. + if (!m_requestTimer.isActive()) + m_engine->eng_g_signal_handlers_disconnect_by_func(G_OBJECT(m_satellite), (void*)satellites_changed, this); +} + +void QGeoSatelliteInfoSourceGypsy::requestUpdate(int timeout) +{ + if (m_requestOngoing) + return; + if (timeout < 0) { + emit requestTimeout(); + return; + } + m_requestOngoing = true; + GError *error = 0; + // If GPS has a fix a already, request current data. + GypsyDeviceFixStatus fixStatus = m_engine->eng_gypsy_device_get_fix_status(m_device, &error); + if (!error && (fixStatus != GYPSY_DEVICE_FIX_STATUS_INVALID && + fixStatus != GYPSY_DEVICE_FIX_STATUS_NONE)) { +#ifdef Q_LOCATION_GYPSY_DEBUG + qDebug() << "QGeoSatelliteInfoSourceGypsy fix available, requesting current satellite data"; +#endif + GPtrArray* satelliteData = m_engine->eng_gypsy_satellite_get_satellites(m_satellite, &error); + if (!error) { + // The fix was available and we have satellite data to deliver right away. + satellitesChanged(m_satellite, satelliteData); + m_engine->eng_gypsy_satellite_free_satellite_array(satelliteData); + return; + } + } + // No fix is available. If updates are not ongoing already, start them. + m_requestTimer.setInterval(timeout == 0? UPDATE_TIMEOUT_COLD_START: timeout); + if (!m_updatesOngoing) { + m_engine->eng_g_signal_connect (m_satellite, "satellites-changed", + G_CALLBACK (satellites_changed), this); + } + m_requestTimer.start(); + if (error) { +#ifdef Q_LOCATION_GYPSY_DEBUG + qDebug() << "QGeoSatelliteInfoSourceGypsy error asking fix status or satellite data: " << error->message; +#endif + g_error_free(error); + } +} + +void QGeoSatelliteInfoSourceGypsy::requestUpdateTimeout() +{ +#ifdef Q_LOCATION_GYPSY_DEBUG + qDebug("QGeoSatelliteInfoSourceGypsy request update timeout occurred."); +#endif + // If we end up here, there has not been valid satellite update. + // Emit timeout and disconnect from signal if regular updates are not + // ongoing (as we were listening just for one single requestUpdate). + if (!m_updatesOngoing) { + m_engine->eng_g_signal_handlers_disconnect_by_func(G_OBJECT(m_satellite), (void*)satellites_changed, this); + } + m_requestOngoing = false; + emit requestTimeout(); +} + +#include "moc_qgeosatelliteinfosource_gypsy_p.cpp" +QT_END_NAMESPACE diff --git a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h new file mode 100644 index 00000000..956836ad --- /dev/null +++ b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSATELLITEINFOSOURCE_GYPSY_H +#define QGEOSATELLITEINFOSOURCE_GYPSY_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeosatelliteinfosource.h" +#include "qgeosatelliteinfo.h" +#include <gypsy/gypsy-satellite.h> +#include <gypsy/gypsy-control.h> +#include <gypsy/gypsy-device.h> +#include <gconf/gconf-client.h> +#include <QTimer> + +// #define Q_LOCATION_GYPSY_DEBUG + +QT_BEGIN_NAMESPACE + +// An engine that encapsulates all symbols we want +// to be able to mock (for unit/autotest purposes). +class SatelliteGypsyEngine +{ +public: + SatelliteGypsyEngine(QGeoSatelliteInfoSource* parent = 0); + virtual ~SatelliteGypsyEngine(); + // Glib symbols + virtual gulong eng_g_signal_connect(gpointer instance, + const gchar* detailed_signal, + GCallback c_handler, + gpointer data); + virtual guint eng_g_signal_handlers_disconnect_by_func(gpointer instance, + gpointer func, + gpointer data); + virtual void eng_g_free(gpointer mem); + // Gypsy symbols + virtual GypsyControl* eng_gypsy_control_get_default (void); + virtual char *eng_gypsy_control_create (GypsyControl *control, const char*device_name, GError **error); + virtual GypsyDevice *eng_gypsy_device_new (const char *object_path); + virtual GypsySatellite *eng_gypsy_satellite_new (const char *object_path); + virtual gboolean eng_gypsy_device_start (GypsyDevice *device, GError **error); + virtual gboolean eng_gypsy_device_stop (GypsyDevice *device, GError **error); + virtual GypsyDeviceFixStatus eng_gypsy_device_get_fix_status (GypsyDevice *device, GError **error); + virtual GPtrArray *eng_gypsy_satellite_get_satellites (GypsySatellite *satellite, GError **error); + virtual void eng_gypsy_satellite_free_satellite_array (GPtrArray *satellites); + // GConf symbols (mockability due to X11 requirement) + virtual GConfClient* eng_gconf_client_get_default(void); + virtual gchar* eng_gconf_client_get_string(GConfClient* client, const gchar* key, GError** err); +protected: + QGeoSatelliteInfoSource* m_owner; +}; + +class QGeoSatelliteInfoSourceGypsy : public QGeoSatelliteInfoSource + { + Q_OBJECT + +public: + explicit QGeoSatelliteInfoSourceGypsy(QObject *parent = 0); + ~QGeoSatelliteInfoSourceGypsy(); + int init(); + +public slots: + virtual void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + void satellitesChanged(GypsySatellite* satellite, GPtrArray* satellites); + +signals: + void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites); + void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites); + +private slots: + void requestUpdateTimeout(); + +protected: + // Creates an engine which encapsulates all used symbols + // that we want to be also able to mock. + virtual void createEngine(); + SatelliteGypsyEngine* m_engine; + +private: + Q_DISABLE_COPY(QGeoSatelliteInfoSourceGypsy) + GypsySatellite* m_satellite; + GypsyDevice* m_device; + QTimer m_requestTimer; + bool m_updatesOngoing; + bool m_requestOngoing; + }; + +QT_END_NAMESPACE + +#endif // QGEOSATELLITEINFOSOURCE_GYPSY_H diff --git a/src/plugins/position/maemo/dbuscomm_maemo.cpp b/src/plugins/position/maemo/dbuscomm_maemo.cpp new file mode 100644 index 00000000..5f0d0aa0 --- /dev/null +++ b/src/plugins/position/maemo/dbuscomm_maemo.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dbuscomm_maemo_p.h" + +#include <iostream> +using namespace std; + +QT_BEGIN_NAMESPACE + +const QString DBusComm::positioningdService = QString("com.nokia.positioningd.client"); +const QString DBusComm::positioningdPath = QString("/com/nokia/positioningd/client"); +const QString DBusComm::positioningdInterface = QString("com.nokia.positioningd.client"); + +DBusComm::DBusComm(QObject *parent) : QObject(parent), + minimumUpdateInterval(1000), + availablePositioningMethods(QGeoPositionInfoSource::AllPositioningMethods) +{ +} + + +int DBusComm::init() +{ + if (!QDBusConnection::sessionBus().isConnected()) { + cerr << "Cannot connect to the D-BUS session bus.\n"; + return -1; + } + + // Application auto-start by dbus may take a while, so try + // connecting a few times. + + int cnt = 10; + positioningdProxy = new QDBusInterface(positioningdService, + positioningdPath, + positioningdInterface, + QDBusConnection::sessionBus()); + + while (cnt && (positioningdProxy->isValid() == false)) { + // cout << "Connecting to positioning daemon..." << endl; + usleep(200000); + positioningdProxy = new QDBusInterface(positioningdService, + positioningdPath, + positioningdInterface, + QDBusConnection::sessionBus()); + cnt--; + } + + if (positioningdProxy->isValid() == false) { + cerr << "DBus connection to positioning daemon failed.\n"; + return -1; + } + serviceDisconnectWatcher = new QDBusServiceWatcher (positioningdService, QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForUnregistration, this); + + QObject::connect(serviceDisconnectWatcher, SIGNAL(serviceUnregistered ( const QString &)), + this,SLOT(onServiceDisconnect(const QString &))); + + serviceConnectWatcher = new QDBusServiceWatcher (positioningdService, QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForRegistration, this); + + QObject::connect(serviceConnectWatcher, SIGNAL(serviceRegistered ( const QString &)), + this,SLOT(onServiceConnect(const QString &))); + + + if (createUniqueName() == false) { // set myService, myPath + return -1; + } + + dbusServer = new DBusServer(&serverObj, this); + QDBusConnection::sessionBus().registerObject(myPath, &serverObj); + if (!QDBusConnection::sessionBus().registerService(myService)) { + cerr << qPrintable(QDBusConnection::sessionBus().lastError().message()) << endl; + return -1; + } + + sendDBusRegister(); + + return 0; +} + + +void DBusComm::onServiceDisconnect(const QString &name) +{ + Q_UNUSED(name); + emit serviceDisconnected(); +} + + +void DBusComm::onServiceConnect(const QString &name) +{ + Q_UNUSED(name); + sendDBusRegister(); + emit serviceConnected(); +} + + +void DBusComm::receivePositionUpdate(const QGeoPositionInfo &update) +{ + emit receivedPositionUpdate(update); +} + + +void DBusComm::receiveSatellitesInView(const QList<QGeoSatelliteInfo> &info) +{ + emit receivedSatellitesInView(info); +} + + +void DBusComm::receiveSatellitesInUse(const QList<QGeoSatelliteInfo> &info) +{ + emit receivedSatellitesInUse(info); +} + + +void DBusComm::receiveSettings(QGeoPositionInfoSource::PositioningMethod methods, qint32 interval) +{ + availablePositioningMethods = methods; + minimumUpdateInterval = interval; +} + + +bool DBusComm::sendDBusRegister() +{ + QDBusMessage reply = positioningdProxy->call("registerListener", + myService.toAscii().constData(), + myPath.toAscii().constData()); + if (reply.type() == QDBusMessage::ReplyMessage) { + QList<QVariant> values = reply.arguments(); + clientId = values.takeFirst().toInt(); + quint32 m = values.takeFirst().toUInt(); + availablePositioningMethods = (QGeoPositionInfoSource::PositioningMethod) m; + minimumUpdateInterval = values.takeFirst().toUInt(); + } else { + cerr << endl << "DBus error:\n"; + cerr << reply.errorName().toAscii().constData() << endl; + cerr << reply.errorMessage().toAscii().constData() << endl; + return false; + } + + return true; +} + + +QGeoPositionInfoSource::PositioningMethods DBusComm::availableMethods() const +{ + return availablePositioningMethods; +} + + +int DBusComm::minimumInterval() const +{ + return minimumUpdateInterval; +} + + +bool DBusComm::sendConfigRequest(Command command, QGeoPositionInfoSource::PositioningMethods method, + int interval) const +{ + QDBusReply<int> reply; + reply = positioningdProxy->call("configSession", clientId, command, int(method), interval); + + //cout << "sessionConfigRequest cmd: cmd:" << command << " method: "; + //cout << method << " interval: " << interval << "\n"; + + if (reply.isValid()) { + int n = reply.value(); + } else { + cerr << endl << "DBus error:\n"; + cerr << reply.error().name().toAscii().constData() << endl; + cerr << reply.error().message().toAscii().constData() << endl; + return false; + } + + return true; +} + + +QGeoPositionInfo& DBusComm::requestLastKnownPosition(bool satelliteMethodOnly) +{ + QDBusReply<QByteArray> reply; + reply = positioningdProxy->call("latestPosition", satelliteMethodOnly); + static QGeoPositionInfo update; + + if (reply.isValid()) { + // cout << "requestLastKnownPosition(): received update\n"; + QByteArray message = reply.value(); + QDataStream stream(message); + stream >> update; + } else { + cerr << endl << "DBus error:\n"; + cerr << reply.error().name().toAscii().constData() << endl; + cerr << reply.error().message().toAscii().constData() << endl; + update = QGeoPositionInfo(); + } + + return update; +} + + +bool DBusComm::createUniqueName() +{ + QFile uuidfile("/proc/sys/kernel/random/uuid"); + if (!uuidfile.open(QIODevice::ReadOnly)) { + cerr << "UUID file failed."; + return false; + } + + QTextStream in(&uuidfile); + QString uuid = 'I' + in.readLine(); + uuid.replace('-', 'I'); + myService = "com.nokia.qlocation." + uuid; + myPath = "/com/nokia/qlocation/" + uuid; + + return true; +} + +#include "moc_dbuscomm_maemo_p.cpp" +QT_END_NAMESPACE + diff --git a/src/plugins/position/maemo/dbuscomm_maemo_p.h b/src/plugins/position/maemo/dbuscomm_maemo_p.h new file mode 100644 index 00000000..ca25d7d9 --- /dev/null +++ b/src/plugins/position/maemo/dbuscomm_maemo_p.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DBUSCOMM_MAEMO_H +#define DBUSCOMM_MAEMO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QObject> +#include <QtCore/QTimer> +#include <QtDBus/QtDBus> + +#include "qgeopositioninfo.h" +#include "qgeosatelliteinfo.h" +#include "qgeopositioninfosource.h" +#include "qgeosatelliteinfosource.h" +#include "dbusserver_maemo_p.h" + +QT_BEGIN_NAMESPACE + +class DBusComm: public QObject, DBusServerIF +{ + Q_OBJECT + + +public: + enum Command {CommandStart = 1, CommandStop = 2, CommandOneShot = 3, + CommandSetMethods = 4, CommandSetInterval = 8, + CommandSatStart = 16, CommandSatStop = 32, CommandSatOneShot = 48}; + + DBusComm(QObject *parent = 0); + int init(); + bool sendDBusRegister(); + bool sendConfigRequest(Command command, QGeoPositionInfoSource::PositioningMethods method, + int interval) const; + QGeoPositionInfo& requestLastKnownPosition(bool satelliteMethodOnly); + QGeoPositionInfoSource::PositioningMethods availableMethods() const; + int minimumInterval() const; + +Q_SIGNALS: + void receivedPositionUpdate(const QGeoPositionInfo &update); + void receivedSatellitesInView(const QList<QGeoSatelliteInfo> &update); + void receivedSatellitesInUse(const QList<QGeoSatelliteInfo> &update); + + void serviceDisconnected(); + void serviceConnected(); + +private: + static const QString positioningdService; + static const QString positioningdPath; + static const QString positioningdInterface; + + // from DBusServerIF + void receivePositionUpdate(const QGeoPositionInfo &update); + void receiveSatellitesInView(const QList<QGeoSatelliteInfo> &info); + void receiveSatellitesInUse(const QList<QGeoSatelliteInfo> &info); + void receiveSettings(QGeoPositionInfoSource::PositioningMethod methods, qint32 interval); + + QDBusInterface *positioningdProxy; + DBusServer* dbusServer; + QObject serverObj; + QString myService; + QString myPath; + int clientId; + int minimumUpdateInterval; + QGeoPositionInfoSource::PositioningMethods availablePositioningMethods; + QDBusServiceWatcher *serviceDisconnectWatcher; + QDBusServiceWatcher *serviceConnectWatcher; + bool createUniqueName(); + + Q_DISABLE_COPY(DBusComm) + +private Q_SLOTS: + void onServiceDisconnect(const QString &name); + void onServiceConnect(const QString &name); + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/position/maemo/dbusserver_maemo.cpp b/src/plugins/position/maemo/dbusserver_maemo.cpp new file mode 100644 index 00000000..ca73b85e --- /dev/null +++ b/src/plugins/position/maemo/dbusserver_maemo.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dbusserver_maemo_p.h" + +QT_BEGIN_NAMESPACE + +DBusServer::DBusServer(QObject *obj, DBusServerIF *iface) : QDBusAbstractAdaptor(obj), + interface(iface) +{ +} + + +Q_NOREPLY void DBusServer::positionUpdate(const QByteArray &message) +{ + static QGeoPositionInfo update; + QDataStream stream(message); + stream >> update; + + interface->receivePositionUpdate(update); +} + + +Q_NOREPLY void DBusServer::currentSettings(quint32 methods, quint32 interval) +{ + QGeoPositionInfoSource::PositioningMethod m = (QGeoPositionInfoSource::PositioningMethod) methods; + interface->receiveSettings(m, interval); +} + + +Q_NOREPLY void DBusServer::satellitesInViewUpdate(const QByteArray &message) +{ + static QList<QGeoSatelliteInfo> update; + QDataStream stream(message); + stream >> update; + + interface->receiveSatellitesInView(update); +} + + +Q_NOREPLY void DBusServer::satellitesInUseUpdate(const QByteArray &message) +{ + static QList<QGeoSatelliteInfo> update; + QDataStream stream(message); + stream >> update; + + interface->receiveSatellitesInUse(update); +} + +#include "moc_dbusserver_maemo_p.cpp" +QT_END_NAMESPACE + diff --git a/src/plugins/position/maemo/dbusserver_maemo_p.h b/src/plugins/position/maemo/dbusserver_maemo_p.h new file mode 100644 index 00000000..7118f7e8 --- /dev/null +++ b/src/plugins/position/maemo/dbusserver_maemo_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DBUSSERVER_MAEMO_H +#define DBUSSERVER_MAEMO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtDBus/QDBusAbstractAdaptor> +#include "qgeopositioninfo.h" +#include "qgeopositioninfosource.h" +#include "qgeosatelliteinfo.h" + +QT_BEGIN_NAMESPACE + +class DBusServerIF { +public: + virtual void receivePositionUpdate(const QGeoPositionInfo &update) = 0; + virtual void receiveSettings(QGeoPositionInfoSource::PositioningMethod methods, qint32 interval) = 0; + virtual void receiveSatellitesInView(const QList<QGeoSatelliteInfo> &update) = 0; + virtual void receiveSatellitesInUse(const QList<QGeoSatelliteInfo> &update) = 0; +}; + + +class DBusServer: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.nokia.qlocation.updates") + +public: + DBusServer(QObject *obj, DBusServerIF *interface); + +public Q_SLOTS: + Q_NOREPLY void positionUpdate(const QByteArray &update); + Q_NOREPLY void satellitesInViewUpdate(const QByteArray &update); + Q_NOREPLY void satellitesInUseUpdate(const QByteArray &update); + Q_NOREPLY void currentSettings(quint32 methods, quint32 interval); + +private: + Q_DISABLE_COPY(DBusServer) + DBusServerIF *interface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/position/maemo/maemo.pro b/src/plugins/position/maemo/maemo.pro new file mode 100644 index 00000000..da35fe89 --- /dev/null +++ b/src/plugins/position/maemo/maemo.pro @@ -0,0 +1,29 @@ +load(qt_module) + +TARGET = qtposition_maemo +QT += location gui + +load(qt_plugin) + +DESTDIR = $$QT.location.plugins/position +#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)" + +INCLUDEPATH += $$QT.location.includes + +CONFIG += qdbus link_pkgconfig +SOURCES += qgeopositioninfosource_maemo.cpp \ + qgeosatelliteinfosource_maemo.cpp \ + dbuscomm_maemo.cpp \ + dbusserver_maemo.cpp \ + qgeopositioninfosourcefactory_maemo.cpp +HEADERS += qgeopositioninfosource_maemo_p.h \ + qgeosatelliteinfosource_maemo_p.h \ + dbuscomm_maemo_p.h \ + dbusserver_maemo_p.h \ + qgeopositioninfosourcefactory_maemo.h + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target + +OTHER_FILES += \ + plugin.json diff --git a/src/plugins/position/maemo/plugin.json b/src/plugins/position/maemo/plugin.json new file mode 100644 index 00000000..f6d85747 --- /dev/null +++ b/src/plugins/position/maemo/plugin.json @@ -0,0 +1,7 @@ +{ + "Keys": ["maemo"], + "Provider": "maemo", + "Position": true, + "Satellite": true, + "Priority": 1000 +} diff --git a/src/plugins/position/maemo/qgeopositioninfosource_maemo.cpp b/src/plugins/position/maemo/qgeopositioninfosource_maemo.cpp new file mode 100644 index 00000000..0305c69c --- /dev/null +++ b/src/plugins/position/maemo/qgeopositioninfosource_maemo.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosource_maemo_p.h" +#include <iostream> +#include <QDateTime> + +using namespace std; + +QT_BEGIN_NAMESPACE + +QGeoPositionInfoSourceMaemo::QGeoPositionInfoSourceMaemo(QObject *parent): QGeoPositionInfoSource(parent) +{ + requestTimer = new QTimer(this); + QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired())); + locationOngoing = false; +} + + +int QGeoPositionInfoSourceMaemo::init() +{ + dbusComm = new DBusComm(this); + int status = dbusComm->init(); + + if (status == 0) { + QObject::connect(dbusComm, SIGNAL(receivedPositionUpdate(const QGeoPositionInfo &)), + this, SLOT(newPositionUpdate(const QGeoPositionInfo &))); + QObject::connect(dbusComm, SIGNAL(serviceConnected()), + this, SLOT(onServiceConnect())); + QObject::connect(dbusComm, SIGNAL(serviceDisconnected()), + this, SLOT(onServiceDisconnect())); + } + return status; +} + +void QGeoPositionInfoSourceMaemo::onServiceDisconnect() +{ + // +} + +void QGeoPositionInfoSourceMaemo::onServiceConnect() +{ + DBusComm::Command command = + (DBusComm::Command) + ( DBusComm::CommandSetInterval | + DBusComm::CommandSetMethods ); + + int interval = QGeoPositionInfoSource::updateInterval(); + QGeoPositionInfoSource::PositioningMethods method; + method = QGeoPositionInfoSource::preferredPositioningMethods(); + + if (locationOngoing) { + command = (DBusComm::Command) ( command | DBusComm::CommandStart ); + dbusComm->sendConfigRequest(command, method, interval); + } else { + dbusComm->sendConfigRequest(command, method, interval); + } +} + +void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &update) +{ + if(update.isValid()) { + emit positionUpdated(update); + if ( requestTimer->isActive() ) + shutdownRequestSession(); + } else { + if ( !requestTimer->isActive() ) + emit updateTimeout(); + } +} + + +QGeoPositionInfo QGeoPositionInfoSourceMaemo::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const +{ + QGeoPositionInfo update = dbusComm->requestLastKnownPosition(fromSatellitePositioningMethodsOnly); + + return update; +} + + +QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceMaemo::supportedPositioningMethods() const +{ + return dbusComm->availableMethods(); +} + + +void QGeoPositionInfoSourceMaemo::setUpdateInterval(int msec) +{ + qint32 min = dbusComm->minimumInterval(); + msec = (msec < min) ? min : msec; + QGeoPositionInfoSource::setUpdateInterval(msec); + + dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, msec); +} + + +void QGeoPositionInfoSourceMaemo::setPreferredPositioningMethods(PositioningMethods sources) +{ + QGeoPositionInfoSource::setPreferredPositioningMethods(sources); + dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, sources, 0); +} + + +int QGeoPositionInfoSourceMaemo::minimumUpdateInterval() const +{ + return dbusComm->minimumInterval(); +} + + +void QGeoPositionInfoSourceMaemo::startUpdates() +{ + locationOngoing = true; + if ( !requestTimer->isActive() ) + dbusComm->sendConfigRequest(DBusComm::CommandStart, 0, 0); +} + + +void QGeoPositionInfoSourceMaemo::stopUpdates() +{ + locationOngoing = false; + if ( !requestTimer->isActive() ) + dbusComm->sendConfigRequest(dbusComm->CommandStop, 0, 0); +} + + +void QGeoPositionInfoSourceMaemo::requestUpdate(int timeout) +{ + if ( QGeoPositionInfoSource::updateInterval() != + dbusComm->minimumInterval() ) + dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, + dbusComm->minimumInterval()); + + if ( !QGeoPositionInfoSource::preferredPositioningMethods().testFlag(QGeoPositionInfoSource::AllPositioningMethods) ) + dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, + QGeoPositionInfoSource::AllPositioningMethods, 0); + + if ( !locationOngoing ) + dbusComm->sendConfigRequest(dbusComm->CommandStart, 0, 0); + + requestTimer->start(timeout); +} + +void QGeoPositionInfoSourceMaemo::requestTimerExpired() +{ + emit updateTimeout(); + shutdownRequestSession(); +} + +void QGeoPositionInfoSourceMaemo::shutdownRequestSession() +{ + requestTimer->stop(); + + if ( !locationOngoing ) + dbusComm->sendConfigRequest(dbusComm->CommandStop, 0, 0); + + if ( QGeoPositionInfoSource::updateInterval() != + dbusComm->minimumInterval() ) + dbusComm->sendConfigRequest(dbusComm->CommandSetInterval, 0, + QGeoPositionInfoSource::updateInterval()); + + if ( !QGeoPositionInfoSource::preferredPositioningMethods().testFlag(QGeoPositionInfoSource::AllPositioningMethods) ) + dbusComm->sendConfigRequest(dbusComm->CommandSetMethods, + QGeoPositionInfoSource::preferredPositioningMethods(), 0); +} + +#include "moc_qgeopositioninfosource_maemo_p.cpp" +QT_END_NAMESPACE + diff --git a/src/plugins/position/maemo/qgeopositioninfosource_maemo_p.h b/src/plugins/position/maemo/qgeopositioninfosource_maemo_p.h new file mode 100644 index 00000000..e82ba344 --- /dev/null +++ b/src/plugins/position/maemo/qgeopositioninfosource_maemo_p.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEMAEMO_H +#define QGEOPOSITIONINFOSOURCEMAEMO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeopositioninfosource.h" +#include "dbuscomm_maemo_p.h" + +#ifdef Q_WS_MAEMO_5 +#include "qgeocoordinate.h" + +extern "C" +{ +#include <glib.h> +#include <location/location-gpsd-control.h> +#include <location/location-gps-device.h> +#include <location/location-misc.h> +#include <location/location-distance-utils.h> +} +#endif + +QT_BEGIN_NAMESPACE + +class DBusComm; +class QGeoPositionInfoSourceMaemo : public QGeoPositionInfoSource +{ + Q_OBJECT + +public: + QGeoPositionInfoSourceMaemo(QObject *parent = 0); + int init(); + + virtual void setUpdateInterval(int interval); + virtual void setPreferredPositioningMethods(PositioningMethods sources); + virtual QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + virtual PositioningMethods supportedPositioningMethods() const; + virtual int minimumUpdateInterval() const; + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + +private: + DBusComm* dbusComm; + QTimer* requestTimer; + bool locationOngoing; + + void shutdownRequestSession(); + +private Q_SLOTS: + void newPositionUpdate(const QGeoPositionInfo &update); + void onServiceConnect(); + void onServiceDisconnect(); + void requestTimerExpired(); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.cpp b/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.cpp new file mode 100644 index 00000000..fb1240ca --- /dev/null +++ b/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory_maemo.h" +#include "qgeopositioninfosource_maemo_p.h" +#include "qgeosatelliteinfosource_maemo_p.h" + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryMaemo::positionInfoSource(QObject *parent) +{ + return new QGeoPositionInfoSourceMaemo(parent); +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryMaemo::satelliteInfoSource(QObject *parent) +{ + return new QGeoSatelliteInfoSourceMaemo(parent); +} diff --git a/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.h b/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.h new file mode 100644 index 00000000..83c58599 --- /dev/null +++ b/src/plugins/position/maemo/qgeopositioninfosourcefactory_maemo.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_MAEMO_H +#define QGEOPOSITIONINFOSOURCEFACTORY_MAEMO_H + +#include <QObject> +#include "qgeopositioninfosource.h" +#include "qgeopositioninfosourcefactory.h" + +class QGeoPositionInfoSourceFactoryMaemo : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0" + FILE "plugin.json") + Q_INTERFACES(QGeoPositionInfoSourceFactory) + +public: + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +#endif diff --git a/src/plugins/position/maemo/qgeosatelliteinfosource_maemo.cpp b/src/plugins/position/maemo/qgeosatelliteinfosource_maemo.cpp new file mode 100644 index 00000000..4922549b --- /dev/null +++ b/src/plugins/position/maemo/qgeosatelliteinfosource_maemo.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeosatelliteinfosource_maemo_p.h" + +QT_BEGIN_NAMESPACE + +QGeoSatelliteInfoSourceMaemo::QGeoSatelliteInfoSourceMaemo(QObject *parent) : QGeoSatelliteInfoSource(parent), + running(false), satInViewSeen(false) +{ + requestTimer = new QTimer(this); + QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired())); +} + + +int QGeoSatelliteInfoSourceMaemo::init() +{ + dbusComm = new DBusComm(this); + int status = dbusComm->init(); + + if (status == 0) { + QObject::connect(dbusComm, SIGNAL(receivedSatellitesInView(const QList<QGeoSatelliteInfo> &)), + this, SLOT(newSatellitesInView(const QList<QGeoSatelliteInfo> &))); + QObject::connect(dbusComm, SIGNAL(receivedSatellitesInUse(const QList<QGeoSatelliteInfo> &)), + this, SLOT(newSatellitesInUse(const QList<QGeoSatelliteInfo> &))); + QObject::connect(dbusComm, SIGNAL(serviceConnected()), + this, SLOT(onServiceConnect())); + QObject::connect(dbusComm, SIGNAL(serviceDisconnected()), + this, SLOT(onServiceDisconnect())); + } + + return status; +} + + +void QGeoSatelliteInfoSourceMaemo::startUpdates() +{ + if ( !requestTimer->isActive() ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStart, 0, 0); + running = true; +} + + +void QGeoSatelliteInfoSourceMaemo::stopUpdates() +{ + if ( !requestTimer->isActive() ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStop, 0, 0); + running = false; +} + + +void QGeoSatelliteInfoSourceMaemo::requestUpdate(int timeout) +{ + if ( !running ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStart, 0, 0); + + requestTimer->start(timeout); + satInViewSeen = false; +} + + +void QGeoSatelliteInfoSourceMaemo::newSatellitesInView(const QList<QGeoSatelliteInfo> &update) +{ + if ( requestTimer->isActive() && satInViewSeen ) { + requestTimer->stop(); + if ( !running ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStop, 0, 0); + else + emit satellitesInViewUpdated(update); + } else { + emit satellitesInViewUpdated(update); + } + + satInViewSeen = true; +} + + +void QGeoSatelliteInfoSourceMaemo::newSatellitesInUse(const QList<QGeoSatelliteInfo> &update) +{ + if ( requestTimer->isActive() ) { + requestTimer->stop(); + if ( !running ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStop, 0, 0); + } + + emit satellitesInUseUpdated(update); +} + +void QGeoSatelliteInfoSourceMaemo::requestTimerExpired() +{ + requestTimer->stop(); + + if ( !running ) + dbusComm->sendConfigRequest(DBusComm::CommandSatStop, 0, 0); + + emit requestTimeout(); +} + +void QGeoSatelliteInfoSourceMaemo::onServiceDisconnect() +{ + // +} + + +void QGeoSatelliteInfoSourceMaemo::onServiceConnect() +{ + if (running) { + dbusComm->sendConfigRequest(DBusComm::CommandSatStart, 0, 0); + } +} + + +#include "moc_qgeosatelliteinfosource_maemo_p.cpp" +QT_END_NAMESPACE + diff --git a/src/plugins/position/maemo/qgeosatelliteinfosource_maemo_p.h b/src/plugins/position/maemo/qgeosatelliteinfosource_maemo_p.h new file mode 100644 index 00000000..dfa1494b --- /dev/null +++ b/src/plugins/position/maemo/qgeosatelliteinfosource_maemo_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSATELLITEINFOSOURCE_MAEMO_H +#define QGEOSATELLITEINFOSOURCE_MAEMO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeosatelliteinfosource.h" +#include "qgeosatelliteinfo.h" +#include "dbuscomm_maemo_p.h" + +QT_BEGIN_NAMESPACE + +class QGeoSatelliteInfoSourceMaemo : public QGeoSatelliteInfoSource +{ + Q_OBJECT +public: + explicit QGeoSatelliteInfoSourceMaemo(QObject *parent = 0); + int init(); + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + +Q_SIGNALS: + void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites); + void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites); + void requestTimeout(); + +private Q_SLOTS: + void newSatellitesInView(const QList<QGeoSatelliteInfo> &update); + void newSatellitesInUse(const QList<QGeoSatelliteInfo> &update); + void onServiceDisconnect(); + void onServiceConnect(); + void requestTimerExpired(); + +private: + DBusComm* dbusComm; + bool running; + bool satInViewSeen; + QTimer* requestTimer; + Q_DISABLE_COPY(QGeoSatelliteInfoSourceMaemo) +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/position/npe_backend/npe_backend.pro b/src/plugins/position/npe_backend/npe_backend.pro new file mode 100644 index 00000000..ca2122eb --- /dev/null +++ b/src/plugins/position/npe_backend/npe_backend.pro @@ -0,0 +1,31 @@ +load(qt_module) + +TARGET = qtposition_npe_backend +QT += location gui + +load(qt_plugin) + +DESTDIR = $$QT.location.plugins/position +#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)" + +INCLUDEPATH += $$QT.location.includes + +DEFINES += NPE_BACKEND +INCLUDEPATH += $$[QT_INSTALL_PREFIX]/include/mtlocationd +#unix { +# CONFIG += link_pkgconfig +# PKGCONFIG += mtlocationd +#} +LIBS += -lmtlocationd +SOURCES += qgeopositioninfosource_npe_backend.cpp \ + qgeosatelliteinfosource_npe_backend.cpp \ + qgeopositioninfosourcefactory_npe_backend.cpp +HEADERS += qgeopositioninfosource_npe_backend_p.h \ + qgeosatelliteinfosource_npe_backend_p.h \ + qgeopositioninfosourcefactory_npe_backend.h + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target + +OTHER_FILES += \ + plugin.json diff --git a/src/plugins/position/npe_backend/plugin.json b/src/plugins/position/npe_backend/plugin.json new file mode 100644 index 00000000..4fdc1be6 --- /dev/null +++ b/src/plugins/position/npe_backend/plugin.json @@ -0,0 +1,7 @@ +{ + "Keys": ["npe_backend"], + "Provider": "npe_backend", + "Position": true, + "Satellite": true, + "Priority": 1000 +} diff --git a/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend.cpp b/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend.cpp new file mode 100644 index 00000000..0807f8b2 --- /dev/null +++ b/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosource_npe_backend_p.h" + + +QGeoPositionInfoSourceNpeBackend::QGeoPositionInfoSourceNpeBackend(QObject *parent): + QGeoPositionInfoSource(parent), locationOngoing(false), timeoutSent(false), mPositionError(QGeoPositionInfoSource::UnknownSourceError), m_locationdConn(0) +{ + requestTimer = new QTimer(this); + QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired())); +} + + +bool QGeoPositionInfoSourceNpeBackend::init() +{ + m_locationdConn = new LocationDaemonConnection(this); + //check for Error: Could not connect to socket (locationd not started?) + if (!m_locationdConn->connected()) + return(false); + connect(m_locationdConn, SIGNAL(positionUpdate(PositionData)), this, SLOT(onPositionUpdate(PositionData))); + connect(m_locationdConn, SIGNAL(connectionError(LocationDaemonConnection::SocketError)), this, SLOT(onConnectionError(LocationDaemonConnection::SocketError))); + return(true); +} + + +QGeoPositionInfo QGeoPositionInfoSourceNpeBackend::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const +{ + const PositionData& position = m_locationdConn->lastKnownPosition(fromSatellitePositioningMethodsOnly); + QGeoCoordinate coordinate; + QGeoPositionInfo lastPosition; + coordinate.setLatitude(position.latitude); + coordinate.setLongitude(position.longitude); + coordinate.setAltitude(position.altitude); + if (coordinate.isValid()) { + lastPosition.setCoordinate(coordinate); + lastPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, position.horizontalAccuracy); + lastPosition.setAttribute(QGeoPositionInfo::VerticalAccuracy, position.verticalAccuracy); + lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, position.groundSpeed); + lastPosition.setAttribute(QGeoPositionInfo::VerticalSpeed, position.verticalSpeed); + lastPosition.setAttribute(QGeoPositionInfo::MagneticVariation, position.magneticVariation); + lastPosition.setAttribute(QGeoPositionInfo::Direction, position.bearing); + QDateTime timestamp = QDateTime::fromString(position.dateTime, "yyyy-MM-ddThh:mm:ss"); + lastPosition.setTimestamp(timestamp); + } else { + // return null update as no valid lastKnown Position is available + coordinate.setLatitude(0); + coordinate.setLongitude(0); + coordinate.setAltitude(0); + lastPosition.setCoordinate(coordinate); + lastPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, 0); + lastPosition.setAttribute(QGeoPositionInfo::VerticalAccuracy, 0); + lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, 0); + lastPosition.setAttribute(QGeoPositionInfo::VerticalSpeed, 0); + lastPosition.setAttribute(QGeoPositionInfo::MagneticVariation, 0); + lastPosition.setAttribute(QGeoPositionInfo::Direction, 0); + } + return(lastPosition); +} + + +QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceNpeBackend::supportedPositioningMethods() const +{ + switch (m_locationdConn->supportedMethods()) { + case LocationdStrings::PositionInfo::Satellite: + return(QGeoPositionInfoSource::SatellitePositioningMethods); + case LocationdStrings::PositionInfo::NonSatellite: + return(QGeoPositionInfoSource::NonSatellitePositioningMethods); + default: + return(QGeoPositionInfoSource::AllPositioningMethods); + } +} + + +void QGeoPositionInfoSourceNpeBackend::setPreferredPositioningMethods(PositioningMethods sources) +{ + QGeoPositionInfoSource::setPreferredPositioningMethods(sources); + LocationdStrings::PositionInfo::PositioningMethods positioningMethod; + switch (sources){ + case QGeoPositionInfoSource::SatellitePositioningMethods: + positioningMethod = LocationdStrings::PositionInfo::Satellite; + break; + case QGeoPositionInfoSource::NonSatellitePositioningMethods: + positioningMethod = LocationdStrings::PositionInfo::NonSatellite; + break; + default: + positioningMethod = LocationdStrings::PositionInfo::AllMethods; + } + m_locationdConn->setPreferredMethod(positioningMethod); +} + + +void QGeoPositionInfoSourceNpeBackend::setUpdateInterval(int msec) +{ + int minInterval = m_locationdConn->minimumUpdateInterval(); + if (msec < minInterval && msec != 0) + msec = minInterval; + QGeoPositionInfoSource::setUpdateInterval(msec); + if (!requestTimer->isActive()) + m_locationdConn->setUpdateInterval(msec); +} + + +int QGeoPositionInfoSourceNpeBackend::minimumUpdateInterval() const +{ + return(m_locationdConn->minimumUpdateInterval()); +} + + +void QGeoPositionInfoSourceNpeBackend::startUpdates() +{ + if (!locationOngoing) { + locationOngoing = true; + m_locationdConn->startPositionUpdates(); + } +} + + +void QGeoPositionInfoSourceNpeBackend::stopUpdates() +{ + if ( locationOngoing && !requestTimer->isActive() ) { + locationOngoing = false; + m_locationdConn->stopPositionUpdates(); + } +} + + +void QGeoPositionInfoSourceNpeBackend::requestUpdate(int timeout) +{ + // ignore if another requestUpdate is still pending + if (!requestTimer->isActive()) { + int minimumInterval = minimumUpdateInterval(); + // set reasonable timeout for the source if timeout is 0 + if (timeout == 0) + timeout = 5*minimumInterval; + // do not start request if timeout can not be fulfilled by the source + if (timeout < minimumInterval) { + emit updateTimeout(); + return; + } + // get position as fast as possible in case of ongoing satellite based session + if ( locationOngoing ) { + if ( QGeoPositionInfoSource::updateInterval() != minimumInterval) + m_locationdConn->setUpdateInterval(minimumInterval); + } + // request the update only if no tracking session is active + if ( !locationOngoing) { + m_locationdConn->requestPositionUpdate(); + } + requestTimer->start(timeout); + } +} + + +void QGeoPositionInfoSourceNpeBackend::requestTimerExpired() +{ + emit updateTimeout(); + shutdownRequestSession(); +} + + + +void QGeoPositionInfoSourceNpeBackend::shutdownRequestSession() +{ + requestTimer->stop(); + // Restore updateInterval from before Request Session + if ( locationOngoing ) { + int minimumInterval = minimumUpdateInterval(); + if ( QGeoPositionInfoSource::updateInterval() != minimumInterval) + setUpdateInterval(QGeoPositionInfoSource::updateInterval()); + } +} + + +void QGeoPositionInfoSourceNpeBackend::onPositionUpdate(const PositionData& position) +{ + if (position.valid) { + QGeoPositionInfo update; + QGeoCoordinate coordinate; + coordinate.setLatitude(position.latitude); + coordinate.setLongitude(position.longitude); + coordinate.setAltitude(position.altitude); + if (coordinate.isValid()) { + update.setCoordinate(coordinate); + update.setAttribute(QGeoPositionInfo::HorizontalAccuracy, position.horizontalAccuracy); + update.setAttribute(QGeoPositionInfo::VerticalAccuracy, position.verticalAccuracy); + update.setAttribute(QGeoPositionInfo::GroundSpeed, position.groundSpeed); + update.setAttribute(QGeoPositionInfo::VerticalSpeed, position.verticalSpeed); + update.setAttribute(QGeoPositionInfo::MagneticVariation, position.magneticVariation); + update.setAttribute(QGeoPositionInfo::Direction, position.bearing); + QDateTime timestamp = QDateTime::fromString(position.dateTime, "yyyy-MM-ddThh:mm:ss"); + update.setTimestamp(timestamp); + emit positionUpdated(update); + timeoutSent = false; + if ( requestTimer->isActive() ) + shutdownRequestSession(); + } else { + if (!timeoutSent) { + emit updateTimeout(); + timeoutSent = true; + } + } + } +} + + + +QGeoPositionInfoSource::Error QGeoPositionInfoSourceNpeBackend::error() const +{ + return mPositionError; +} + + +void QGeoPositionInfoSourceNpeBackend::setError(QGeoPositionInfoSource::Error positionError) +{ + mPositionError = positionError; + emit QGeoPositionInfoSource::error(positionError); +} + + +void QGeoPositionInfoSourceNpeBackend::onConnectionError(LocationDaemonConnection::SocketError socketError) +{ + switch (socketError) { + case LocationDaemonConnection::ClosedError: + setError(ClosedError); + break; + case LocationDaemonConnection::AccessError: + setError(AccessError); + break; + default: + setError(UnknownSourceError); + } +} diff --git a/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend_p.h b/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend_p.h new file mode 100644 index 00000000..36d16c7a --- /dev/null +++ b/src/plugins/position/npe_backend/qgeopositioninfosource_npe_backend_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCE_NPE_BACKEND_H +#define QGEOPOSITIONINFOSOURCE_NPE_BACKEND_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeopositioninfosource.h" +#include <qtimer.h> +#include <locationdaemonconnection.h> + + +class QGeoPositionInfoSourceNpeBackend : public QGeoPositionInfoSource +{ + Q_OBJECT + +public: + QGeoPositionInfoSourceNpeBackend(QObject *parent = 0); + bool init(); + void setUpdateInterval(int interval); + void setPreferredPositioningMethods(PositioningMethods sources); + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + PositioningMethods supportedPositioningMethods() const; + int minimumUpdateInterval() const; + QGeoPositionInfoSource::Error error() const; + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + +private: + void setError(QGeoPositionInfoSource::Error positionError); + void shutdownRequestSession(); + LocationDaemonConnection* m_locationdConn; + bool locationOngoing; + bool timeoutSent; + QTimer* requestTimer; + QGeoPositionInfoSource::Error mPositionError; + + +private Q_SLOTS: + void onPositionUpdate(const PositionData &position); + void onConnectionError(LocationDaemonConnection::SocketError socketError); + void requestTimerExpired(); +}; + +#endif // QGEOPOSITIONINFOSOURCE_NPE_BACKEND_H diff --git a/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.cpp b/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.cpp new file mode 100644 index 00000000..422a7a3f --- /dev/null +++ b/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory_npe_backend.h" +#include "qgeopositioninfosource_npe_backend_p.h" +#include "qgeosatelliteinfosource_npe_backend_p.h" + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryNpeBackend::positionInfoSource(QObject *parent) +{ + return new QGeoPositionInfoSourceNpeBackend(parent); +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactoryNpeBackend::satelliteInfoSource(QObject *parent) +{ + return new QGeoSatelliteInfoSourceNpeBackend(parent); +} diff --git a/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.h b/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.h new file mode 100644 index 00000000..bd87062c --- /dev/null +++ b/src/plugins/position/npe_backend/qgeopositioninfosourcefactory_npe_backend.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_NPE_BACKEND_H +#define QGEOPOSITIONINFOSOURCEFACTORY_NPE_BACKEND_H + +#include <QObject> +#include "qgeopositioninfosource.h" +#include "qgeopositioninfosourcefactory.h" + +class QGeoPositionInfoSourceFactoryNpeBackend : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0" + FILE "plugin.json") + Q_INTERFACES(QGeoPositionInfoSourceFactory) + +public: + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +#endif diff --git a/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend.cpp b/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend.cpp new file mode 100644 index 00000000..47b6514e --- /dev/null +++ b/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend.cpp @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeosatelliteinfosource_npe_backend_p.h" +#include <qdebug.h> + + +// Bitmask Table for satStatus +// Satellite is above elevation mask +#define SATELLITES_STATUS_VISIBLE 0x0002 // --------------1- +// Satellite used in position calculation +#define SATELLITES_STATUS_USED_POS 0x0004 // -------------1-- + + +QGeoSatelliteInfoSourceNpeBackend::QGeoSatelliteInfoSourceNpeBackend(QObject *parent): QGeoSatelliteInfoSource(parent), + satOngoing(false), mSatelliteError(QGeoSatelliteInfoSource::UnknownSourceError), m_locationdConn(0) +{ + requestTimer = new QTimer(this); + QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired())); +} + + +bool QGeoSatelliteInfoSourceNpeBackend::init() +{ + m_locationdConn = new LocationDaemonConnection(this); + //check for Error: Could not connect to socket (locationd not started?) + if (!m_locationdConn->connected()) + return(false); + connect(m_locationdConn, SIGNAL(satelliteUpdate(QList<SatelliteData>)), this, SLOT(onSatelliteUpdate(QList<SatelliteData>))); + connect(m_locationdConn, SIGNAL(connectionError(LocationDaemonConnection::SocketError)), this, SLOT(onConnectionError(LocationDaemonConnection::SocketError))); + return(true); +} + + +void QGeoSatelliteInfoSourceNpeBackend::setUpdateInterval(int msec) +{ + int minInterval = m_locationdConn->minimumUpdateInterval(); + if (msec < minInterval && msec != 0) + msec = minInterval; + QGeoSatelliteInfoSource::setUpdateInterval(msec); + if (!requestTimer->isActive()) + m_locationdConn->setUpdateInterval(msec); +} + + +int QGeoSatelliteInfoSourceNpeBackend::minimumUpdateInterval() const +{ + return(m_locationdConn->minimumUpdateInterval()); +} + + +void QGeoSatelliteInfoSourceNpeBackend::startUpdates() +{ + if (!satOngoing) { + satOngoing = true; + m_locationdConn->startSatelliteUpdates(); + } +} + + +void QGeoSatelliteInfoSourceNpeBackend::stopUpdates() +{ + if (satOngoing && !requestTimer->isActive()) { + satOngoing = false; + m_locationdConn->stopSatelliteUpdates(); + } +} + + +void QGeoSatelliteInfoSourceNpeBackend::requestUpdate(int timeout) +{ + // ignore if another requestUpdate is still pending + if (!requestTimer->isActive()) { + 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 fulfilled 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) + m_locationdConn->setUpdateInterval(minimumInterval); + } + // request the update only if no tracking session is active + if ( !satOngoing) + m_locationdConn->requestSatelliteUpdate(); + requestTimer->start(timeout); + } +} + + +void QGeoSatelliteInfoSourceNpeBackend::requestTimerExpired() +{ + 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()); + } +} + + +void QGeoSatelliteInfoSourceNpeBackend::onSatelliteUpdate(const QList<SatelliteData>& satellites) +{ + QList<QGeoSatelliteInfo> inUse; + QList<QGeoSatelliteInfo> inView; + QListIterator<SatelliteData> it(satellites); + + if (!satellites.empty()) { + while (it.hasNext()) + { + QGeoSatelliteInfo satinfo; + const SatelliteData& satellite = it.next(); + satinfo.setAttribute(QGeoSatelliteInfo::Elevation, satellite.elevation); + satinfo.setAttribute(QGeoSatelliteInfo::Azimuth, satellite.azimuth); + satinfo.setSatelliteIdentifier(satellite.id); + satinfo.setSignalStrength(satellite.signalStrength); + if (satellite.satSystem == LocationdStrings::PositionInfo::kGPS) + satinfo.setSatelliteSystem(QGeoSatelliteInfo::GPS); + else if (satellite.satSystem == LocationdStrings::PositionInfo::kGLONASS) + satinfo.setSatelliteSystem(QGeoSatelliteInfo::GLONASS); + else + satinfo.setSatelliteSystem(QGeoSatelliteInfo::Undefined); + if (satellite.status & SATELLITES_STATUS_VISIBLE) { + inView.append(satinfo); + if (satellite.status & SATELLITES_STATUS_USED_POS) + inUse.append(satinfo); + } + } + 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() ) + shutdownRequestSession(); + } +} + + +QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSourceNpeBackend::error() const +{ + return mSatelliteError; +} + + +void QGeoSatelliteInfoSourceNpeBackend::setError(QGeoSatelliteInfoSource::Error satelliteError) +{ + mSatelliteError = satelliteError; + emit QGeoSatelliteInfoSource::error(satelliteError); +} + + +void QGeoSatelliteInfoSourceNpeBackend::onConnectionError(LocationDaemonConnection::SocketError socketError) +{ + switch (socketError) { + case LocationDaemonConnection::ClosedError: + setError(ClosedError); + break; + case LocationDaemonConnection::AccessError: + setError(AccessError); + break; + default: + setError(UnknownSourceError); + } +} diff --git a/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend_p.h b/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend_p.h new file mode 100644 index 00000000..1a8f3568 --- /dev/null +++ b/src/plugins/position/npe_backend/qgeosatelliteinfosource_npe_backend_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSATELLITEINFOSOURCE_NPE_BACKEND_H +#define QGEOSATELLITEINFOSOURCE_NPE_BACKEND_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeosatelliteinfosource.h" +#include <qtimer.h> +#include <locationdaemonconnection.h> + + +class QGeoSatelliteInfoSourceNpeBackend: public QGeoSatelliteInfoSource +{ + Q_OBJECT + +public: + QGeoSatelliteInfoSourceNpeBackend(QObject *parent = 0); + bool init(); + void setUpdateInterval(int interval); + int minimumUpdateInterval() const; + QGeoSatelliteInfoSource::Error error() const; + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + +private: + void setError(QGeoSatelliteInfoSource::Error satelliteError); + void shutdownRequestSession(); + LocationDaemonConnection* m_locationdConn; + bool satOngoing; + QTimer* requestTimer; + QGeoSatelliteInfoSource::Error mSatelliteError; + + +private Q_SLOTS: + void onSatelliteUpdate(const QList<SatelliteData>& satellites); + void onConnectionError(LocationDaemonConnection::SocketError socketError); + void requestTimerExpired(); +}; + +#endif // QGEOSATELLITEINFOSOURCE_NPE_BACKEND_H diff --git a/src/plugins/position/position.pro b/src/plugins/position/position.pro new file mode 100644 index 00000000..cdfc5379 --- /dev/null +++ b/src/plugins/position/position.pro @@ -0,0 +1,9 @@ +TEMPLATE = subdirs + +maemo6|meego:SUBDIRS += maemo +meego { + contains (geoclue-master_enabled, yes):SUBDIRS += geoclue + contains (gypsy_enabled, yes):SUBDIRS += gypsy +} +contains(config_test_locationd, yes):!simulator:SUBDIRS += npe_backend +simulator:SUBDIRS += simulator diff --git a/src/plugins/position/simulator/plugin.json b/src/plugins/position/simulator/plugin.json new file mode 100644 index 00000000..257640e0 --- /dev/null +++ b/src/plugins/position/simulator/plugin.json @@ -0,0 +1,7 @@ +{ + "Keys": ["simulator"], + "Provider": "simulator", + "Position": true, + "Satellite": true, + "Priority": 1000 +} diff --git a/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp new file mode 100644 index 00000000..f1b213d0 --- /dev/null +++ b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosource_simulator_p.h" +#include "qlocationdata_simulator_p.h" +#include "qlocationconnection_simulator_p.h" + +#include <QtCore/QDebug> +#include <QtCore/QTimer> +#include <QtCore/QDataStream> + +#include <QtNetwork/QLocalSocket> + +QT_BEGIN_NAMESPACE + +namespace Simulator +{ + QGeoPositionInfo toPositionInfo(const QGeoPositionInfoData &data) + { + QDateTime timestamp; + if (data.dateTime.isValid()) + timestamp = data.dateTime; + else + timestamp = QDateTime::currentDateTime(); + QGeoCoordinate coord(data.latitude, data.longitude, data.altitude); + QGeoPositionInfo info(coord, timestamp); + info.setAttribute(QGeoPositionInfo::Direction, data.direction); + info.setAttribute(QGeoPositionInfo::GroundSpeed, data.groundSpeed); + info.setAttribute(QGeoPositionInfo::VerticalSpeed, data.verticalSpeed); + info.setAttribute(QGeoPositionInfo::MagneticVariation, data.magneticVariation); + info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, data.horizontalAccuracy); + info.setAttribute(QGeoPositionInfo::VerticalAccuracy, data.verticalAccuracy); + return info; + } +} //namespace + +// Location API + +QGeoPositionInfoSourceSimulator::QGeoPositionInfoSourceSimulator(QObject *parent) + : QGeoPositionInfoSource(parent) + , timer(new QTimer(this)) + , requestTimer(new QTimer(this)) + , m_positionError(QGeoPositionInfoSource::UnknownSourceError) +{ + Simulator::LocationConnection::ensureSimulatorConnection(); + + connect(timer, SIGNAL(timeout()), this, SLOT(updatePosition())); + requestTimer->setSingleShot(true); + connect(requestTimer, SIGNAL(timeout()), this, SLOT(updatePosition())); +} + +QGeoPositionInfoSourceSimulator::~QGeoPositionInfoSourceSimulator() +{ +} + +QGeoPositionInfo QGeoPositionInfoSourceSimulator::lastKnownPosition(bool /*fromSatellitePositioningMethodsOnly*/) const +{ + return lastPosition; +} + +QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceSimulator::supportedPositioningMethods() const +{ + // Is GPS now Satelite or not? Guessing so... + return QGeoPositionInfoSource::SatellitePositioningMethods; +} + +void QGeoPositionInfoSourceSimulator::setUpdateInterval(int msec) +{ + // If msec is 0 we send updates as data becomes available, otherwise we force msec to be equal + // to or larger than the minimum update interval. + if (msec != 0 && msec < minimumUpdateInterval()) + msec = minimumUpdateInterval(); + + QGeoPositionInfoSource::setUpdateInterval(msec); + if (timer->isActive()) { + timer->setInterval(msec); + timer->start(); + } +} + +int QGeoPositionInfoSourceSimulator::minimumUpdateInterval() const +{ + return qtPositionInfo()->minimumInterval; +} + +void QGeoPositionInfoSourceSimulator::startUpdates() +{ + int interval = updateInterval(); + if (interval < minimumUpdateInterval()) + interval = minimumUpdateInterval(); + timer->setInterval(interval); + timer->start(); +} + +void QGeoPositionInfoSourceSimulator::stopUpdates() +{ + timer->stop(); +} + +void QGeoPositionInfoSourceSimulator::requestUpdate(int timeout) +{ + if (!requestTimer->isActive()) { + // Get a single update within timeframe + if (timeout < minimumUpdateInterval() && timeout != 0) + emit updateTimeout(); + else { + requestTimer->start(timeout * qreal(0.75)); + } + } +} + +void QGeoPositionInfoSourceSimulator::updatePosition() +{ + if (qtPositionInfo()->enabled) { + lastPosition = Simulator::toPositionInfo(*qtPositionInfo()); + emit positionUpdated(lastPosition); + } else { + emit updateTimeout(); + } +} + +QGeoPositionInfoSource::Error QGeoPositionInfoSourceSimulator::error() const +{ + return m_positionError; +} + + +void QGeoPositionInfoSourceSimulator::setError(QGeoPositionInfoSource::Error positionError) +{ + m_positionError = positionError; + emit QGeoPositionInfoSource::error(positionError); +} + +#include "moc_qgeopositioninfosource_simulator_p.cpp" + +QT_END_NAMESPACE diff --git a/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h b/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h new file mode 100644 index 00000000..f696ac8a --- /dev/null +++ b/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCESIMULATOR_H +#define QGEOPOSITIONINFOSOURCESIMULATOR_H + +#include "qgeopositioninfosource.h" +#include "qgeopositioninfo.h" +#include "qlocationdata_simulator_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE +class QTimer; + +class QGeoPositionInfoSourceSimulator : public QGeoPositionInfoSource +{ + Q_OBJECT +public: + QGeoPositionInfoSourceSimulator(QObject *parent = 0); + ~QGeoPositionInfoSourceSimulator(); + + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + PositioningMethods supportedPositioningMethods() const; + + void setUpdateInterval(int msec); + int minimumUpdateInterval() const; + Error error() const; + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + + void requestUpdate(int timeout = 0); + +private slots: + void updatePosition(); +private: + Q_DISABLE_COPY(QGeoPositionInfoSourceSimulator); + QTimer *timer; + QTimer *requestTimer; + QGeoPositionInfo lastPosition; + QGeoPositionInfoSource::Error m_positionError; + void setError(QGeoPositionInfoSource::Error positionError); +}; + +QT_END_NAMESPACE + +#endif // QGEOPOSITIONINFOSOURCESIMULATOR_H diff --git a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp new file mode 100644 index 00000000..07256588 --- /dev/null +++ b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory_simulator.h" + +QGeoPositionInfoSource *QGeoPositionInfoSourceFactorySimulator::positionInfoSource(QObject *parent) +{ + return new QGeoPositionInfoSourceSimulator(parent); +} + +QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactorySimulator::satelliteInfoSource(QObject *parent) +{ + return new QGeoSatelliteInfoSourceSimulator(parent); +} diff --git a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h new file mode 100644 index 00000000..846658f2 --- /dev/null +++ b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_SIMULATOR_H +#define QGEOPOSITIONINFOSOURCEFACTORY_SIMULATOR_H + +#include <QObject> +#include <QGeoPositionInfoSourceFactory> + +#include "qgeopositioninfosource_simulator_p.h" +#include "qgeosatelliteinfosource_simulator_p.h" + +class QGeoPositionInfoSourceFactorySimulator : public QObject, public QGeoPositionInfoSourceFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/5.0" + FILE "plugin.json") + Q_INTERFACES(QGeoPositionInfoSourceFactory) +public: + QGeoPositionInfoSource *positionInfoSource(QObject *parent); + QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent); +}; + +#endif // QGEOPOSITIONINFOSOURCEFACTORY_SIMULATOR_H diff --git a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp new file mode 100644 index 00000000..6840f55e --- /dev/null +++ b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeosatelliteinfosource_simulator_p.h" +#include "qlocationconnection_simulator_p.h" +#include "qlocationdata_simulator_p.h" + +QT_BEGIN_NAMESPACE + +QGeoSatelliteInfoSourceSimulator::QGeoSatelliteInfoSourceSimulator(QObject *parent) + : QGeoSatelliteInfoSource(parent) + , timer(new QTimer(this)) + , requestTimer(new QTimer(this)) +{ + Simulator::LocationConnection::ensureSimulatorConnection(); + + connect(timer, SIGNAL(timeout()), this, SLOT(updateData())); + requestTimer->setSingleShot(true); + connect(requestTimer, SIGNAL(timeout()), this, SLOT(updateData())); +} + +void QGeoSatelliteInfoSourceSimulator::startUpdates() +{ + int interval = updateInterval(); + if (interval < minimumUpdateInterval()) + interval = minimumUpdateInterval(); + timer->setInterval(interval); + timer->start(); +} + +void QGeoSatelliteInfoSourceSimulator::stopUpdates() +{ + timer->stop(); +} + +void QGeoSatelliteInfoSourceSimulator::requestUpdate(int timeout) +{ + if (!requestTimer->isActive()) { + // Get a single update within timeframe + if (timeout == 0) + timeout = minimumUpdateInterval(); + + if (timeout < minimumUpdateInterval()) + emit requestTimeout(); + else + requestTimer->start(timeout); + } +} + +void QGeoSatelliteInfoSourceSimulator::setUpdateInterval(int msec) +{ + // msec should be equal to or larger than the minimum update interval; 0 is a special case + // that currently behaves as if the interval is set to the minimum update interval + if (msec != 0 && msec < minimumUpdateInterval()) + msec = minimumUpdateInterval(); + + QGeoSatelliteInfoSource::setUpdateInterval(msec); + if (timer->isActive()) { + timer->setInterval(msec); + timer->start(); + } +} + +int QGeoSatelliteInfoSourceSimulator::minimumUpdateInterval() const +{ + return qtPositionInfo()->minimumInterval; +} + +void QGeoSatelliteInfoSourceSimulator::updateData() +{ + QList<QGeoSatelliteInfo> satellitesInUse; + QList<QGeoSatelliteInfo> satellitesInView; + + QGeoSatelliteInfoData *data = qtSatelliteInfo(); + for(int i = 0; i < data->satellites.count(); i++) { + QGeoSatelliteInfoData::SatelliteInfo info = data->satellites.at(i); + QGeoSatelliteInfo satInfo; + satInfo.setAttribute(QGeoSatelliteInfo::Azimuth, info.azimuth); + satInfo.setAttribute(QGeoSatelliteInfo::Elevation, info.elevation); + satInfo.setSignalStrength(info.signalStrength); + satInfo.setSatelliteSystem(static_cast<QGeoSatelliteInfo::SatelliteSystem>(info.satelliteSystem)); + satInfo.setSatelliteIdentifier(info.satelliteIdentifier); + satellitesInView.append(satInfo); + if (info.inUse) + satellitesInUse.append(satInfo); + } + emit satellitesInViewUpdated(satellitesInView); + emit satellitesInUseUpdated(satellitesInUse); +} + +#include "moc_qgeosatelliteinfosource_simulator_p.cpp" +QT_END_NAMESPACE diff --git a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h new file mode 100644 index 00000000..0d76a375 --- /dev/null +++ b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSATELLITEINFOSOURCE_SIMULATOR_H +#define QGEOSATELLITEINFOSOURCE_SIMULATOR_H + +#include <QTimer> +#include "qgeosatelliteinfosource.h" +#include "qgeosatelliteinfo.h" + +#define MINIMUM_UPDATE_INTERVAL 1000 +#define DEFAULT_UPDATE_INTERVAL 5000 + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QGeoSatelliteInfoSourceSimulator : public QGeoSatelliteInfoSource +{ + Q_OBJECT + +public: + explicit QGeoSatelliteInfoSourceSimulator(QObject *parent = 0); + + virtual void setUpdateInterval(int msec); + virtual int minimumUpdateInterval() const; + + // Default implementation for error() + Error error() const { return QGeoSatelliteInfoSource::UnknownSourceError; } +public slots: + virtual void startUpdates(); + virtual void stopUpdates(); + virtual void requestUpdate(int timeout = 5000); + +private slots: + void updateData(); + +private: + Q_DISABLE_COPY(QGeoSatelliteInfoSourceSimulator) + QTimer *timer; + QTimer *requestTimer; +}; + +QT_END_NAMESPACE + +#endif // QGEOSATELLITEINFOSOURCE_SIMULATOR_H + diff --git a/src/plugins/position/simulator/qlocationconnection_simulator.cpp b/src/plugins/position/simulator/qlocationconnection_simulator.cpp new file mode 100644 index 00000000..a35419e1 --- /dev/null +++ b/src/plugins/position/simulator/qlocationconnection_simulator.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qlocationconnection_simulator_p.h" +#include "qgeopositioninfosource_simulator_p.h" +#include "qlocationdata_simulator_p.h" + +#include <QtCore/QDebug> +#include <QtCore/QTimer> +#include <QtCore/QDataStream> +#include <QtCore/QEventLoop> + +#include <QtNetwork/QLocalSocket> + +#include <QtSimulator/connection.h> +#include <QtSimulator/version.h> +#include <QtSimulator/connectionworker.h> + +QT_BEGIN_NAMESPACE + +const QString simulatorName(QString::fromLatin1("QtSimulator_Mobility_ServerName1.3.0.0")); +const quint16 simulatorPort = 0xbeef + 1; + +namespace Simulator +{ + LocationConnection::LocationConnection() + : mConnection(new Connection(Connection::Client, simulatorName, simulatorPort, Version(1,3,0,0))) + { + qt_registerLocationTypes(); + mWorker = mConnection->connectToServer(Connection::simulatorHostName(true), simulatorPort); + if (!mWorker) + qFatal("Could not connect to server"); + mWorker->addReceiver(this); + + // register for location notifications + mWorker->call("setRequestsLocationInfo"); + + // wait until initial data is received + QEventLoop loop; + connect(this, SIGNAL(initialDataReceived()), &loop, SLOT(quit())); + loop.exec(); + } + + LocationConnection::~LocationConnection() + { + delete mWorker; + delete mConnection; + } + + void LocationConnection::ensureSimulatorConnection() + { + static LocationConnection locationConnection; + } + + void LocationConnection::initialLocationDataSent() + { + emit initialDataReceived(); + } + + void LocationConnection::setLocationData(const QGeoPositionInfoData &data) + { + *qtPositionInfo() = data; + } + + void LocationConnection::setSatelliteData(const QGeoSatelliteInfoData &data) + { + *qtSatelliteInfo() = data; + } + +#include "moc_qlocationconnection_simulator_p.cpp" + +} // namespace + +QGeoPositionInfoData *qtPositionInfo() +{ + static QGeoPositionInfoData *positionInfo = 0; + if (!positionInfo) { + positionInfo = new QGeoPositionInfoData; + } + + return positionInfo; +} + +QGeoSatelliteInfoData *qtSatelliteInfo() +{ + static QGeoSatelliteInfoData *satelliteInfo = 0; + if (!satelliteInfo) { + satelliteInfo = new QGeoSatelliteInfoData; + } + + return satelliteInfo; +} + + +QT_END_NAMESPACE diff --git a/src/plugins/position/simulator/qlocationconnection_simulator_p.h b/src/plugins/position/simulator/qlocationconnection_simulator_p.h new file mode 100644 index 00000000..22cc3b63 --- /dev/null +++ b/src/plugins/position/simulator/qlocationconnection_simulator_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOCATIONCONNECTION_H +#define QLOCATIONCONNECTION_H + +#include "qlocationdata_simulator_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + + +namespace Simulator +{ + class Connection; + class ConnectionWorker; + + class LocationConnection : public QObject + { + Q_OBJECT + public: + static void ensureSimulatorConnection(); + virtual ~LocationConnection(); + + private: + LocationConnection(); + Q_DISABLE_COPY(LocationConnection) + + private slots: + // these will be called by the simulator + void setLocationData(const QGeoPositionInfoData &); + void setSatelliteData(const QGeoSatelliteInfoData &); + void initialLocationDataSent(); + + signals: + void initialDataReceived(); + + private: + Connection *mConnection; + ConnectionWorker *mWorker; + }; +} // end namespace Simulator + +QGeoPositionInfoData *qtPositionInfo(); +QGeoSatelliteInfoData *qtSatelliteInfo(); + +QT_END_NAMESPACE + +#endif // QLOCATIONCONNECTION_H diff --git a/src/plugins/position/simulator/qlocationdata_simulator.cpp b/src/plugins/position/simulator/qlocationdata_simulator.cpp new file mode 100644 index 00000000..85441877 --- /dev/null +++ b/src/plugins/position/simulator/qlocationdata_simulator.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qlocationdata_simulator_p.h" + +#include <QtCore/QDataStream> + +QT_BEGIN_NAMESPACE + +QGeoPositionInfoData::QGeoPositionInfoData() + : latitude(0.0), + longitude(0.0), + altitude(0.0), + direction(0.0), + groundSpeed(0.0), + verticalSpeed(0.0), + magneticVariation(0.0), + horizontalAccuracy(0.0), + verticalAccuracy(0.0), + dateTime(), + minimumInterval(0), + enabled(false) {} + +QGeoSatelliteInfoData::SatelliteInfo::SatelliteInfo() + : azimuth(0.0), + elevation(0.0), + signalStrength(0), + inUse(false), + satelliteSystem(Undefined), + satelliteIdentifier(0) {} + +void qt_registerLocationTypes() +{ + qRegisterMetaTypeStreamOperators<QGeoPositionInfoData>("QGeoPositionInfoData"); + qRegisterMetaTypeStreamOperators<QGeoSatelliteInfoData>("QGeoSatelliteInfoData"); + qRegisterMetaTypeStreamOperators<QGeoSatelliteInfoData::SatelliteInfo>("QGeoSatelliteInfoData::SatelliteInfo"); +} + +QDataStream &operator<<(QDataStream &out, const QGeoPositionInfoData &s) +{ + out << s.latitude << s.longitude << s.altitude; + out << s.direction << s.groundSpeed << s.verticalSpeed << s.magneticVariation << s.horizontalAccuracy << s.verticalAccuracy; + out << s.dateTime; + out << s.minimumInterval << s.enabled; + return out; +} + +QDataStream &operator>>(QDataStream &in, QGeoPositionInfoData &s) +{ + in >> s.latitude >> s.longitude >> s.altitude; + in >> s.direction >> s.groundSpeed >> s.verticalSpeed >> s.magneticVariation >> s.horizontalAccuracy >> s.verticalAccuracy; + in >> s.dateTime; + in >> s.minimumInterval >> s.enabled; + return in; +} + +QDataStream &operator<<(QDataStream &out, const QGeoSatelliteInfoData &s) +{ + out << s.satellites; + return out; +} + +QDataStream &operator>>(QDataStream &in, QGeoSatelliteInfoData &s) +{ + in >> s.satellites; + return in; +} + +QDataStream &operator<<(QDataStream &out, const QGeoSatelliteInfoData::SatelliteInfo &s) +{ + out << s.azimuth << s.elevation << s.signalStrength << s.inUse << static_cast<qint32>(s.satelliteSystem) << s.satelliteIdentifier; + return out; +} + +QDataStream &operator>>(QDataStream &in, QGeoSatelliteInfoData::SatelliteInfo &s) +{ + qint32 satelliteSystem; + in >> s.azimuth >> s.elevation >> s.signalStrength >> s.inUse >> satelliteSystem >> s.satelliteIdentifier; + s.satelliteSystem = static_cast<QGeoSatelliteInfoData::SatelliteInfo::SatelliteSystem>(satelliteSystem); + return in; +} + +QT_END_NAMESPACE diff --git a/src/plugins/position/simulator/qlocationdata_simulator_p.h b/src/plugins/position/simulator/qlocationdata_simulator_p.h new file mode 100644 index 00000000..200f46c6 --- /dev/null +++ b/src/plugins/position/simulator/qlocationdata_simulator_p.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFODATA_SIMULATOR_P_H +#define QGEOPOSITIONINFODATA_SIMULATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QMetaType> +#include <QtCore/QDateTime> +#include <QtCore/QList> + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +struct QGeoPositionInfoData +{ + QGeoPositionInfoData(); + + // Coordinate information + double latitude; + double longitude; + double altitude; + + // Attributes + // ### transmit whether attributes are set or not + qreal direction; + qreal groundSpeed; + qreal verticalSpeed; + qreal magneticVariation; + qreal horizontalAccuracy; + qreal verticalAccuracy; + + // DateTime info + QDateTime dateTime; + + int minimumInterval; + bool enabled; +}; + +struct QGeoSatelliteInfoData +{ + struct SatelliteInfo + { + SatelliteInfo(); + + // This enum duplicates the SatelliteSystem enum defined in qgeosatelliteinfo.h, which cannot be + // included as this file must compile with Qt4 (it is used by Qt Simulator) + enum SatelliteSystem + { + Undefined = 0x00, + GPS = 0x01, + GLONASS = 0x02 + }; + + qreal azimuth; + qreal elevation; + int signalStrength; + bool inUse; + SatelliteSystem satelliteSystem; + int satelliteIdentifier; + }; + + QList<SatelliteInfo> satellites; +}; + +void qt_registerLocationTypes(); + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoPositionInfoData) +Q_DECLARE_METATYPE(QGeoSatelliteInfoData) +Q_DECLARE_METATYPE(QGeoSatelliteInfoData::SatelliteInfo) + +QT_END_HEADER + +#endif // QGEOPOSITIONINFODATA_SIMULATOR_P_H diff --git a/src/plugins/position/simulator/simulator.pro b/src/plugins/position/simulator/simulator.pro new file mode 100644 index 00000000..f2c59635 --- /dev/null +++ b/src/plugins/position/simulator/simulator.pro @@ -0,0 +1,30 @@ +load(qt_module) + +TARGET = qtposition_simulator +QT += location gui + +load(qt_plugin) + +DESTDIR = $$QT.location.plugins/position +#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)" + +INCLUDEPATH += $$QT.location.includes + +QT += simulator +DEFINES += QT_SIMULATOR +SOURCES += qgeopositioninfosource_simulator.cpp \ + qlocationdata_simulator.cpp \ + qgeosatelliteinfosource_simulator.cpp \ + qlocationconnection_simulator.cpp \ + qgeopositioninfosourcefactory_simulator.cpp +HEADERS += qgeopositioninfosource_simulator_p.h \ + qlocationdata_simulator_p.h \ + qgeosatelliteinfosource_simulator_p.h \ + qlocationconnection_simulator_p.h \ + qgeopositioninfosourcefactory_simulator.h + +target.path += $$[QT_INSTALL_PLUGINS]/position +INSTALLS += target + +OTHER_FILES += \ + plugin.json |