summaryrefslogtreecommitdiff
path: root/src/plugins/position/gypsy
diff options
context:
space:
mode:
authorAlex Wilson <alex.wilson@nokia.com>2012-03-07 16:38:50 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-12 03:25:51 +0100
commit369fa99b132f8c1425da8a41f1436b8d86aaa50e (patch)
treea13d675390d1590df27c70a4ee47b6490cc58800 /src/plugins/position/gypsy
parentc435861528161ee931287034f41023c11dfb7ba3 (diff)
downloadqtlocation-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/position/gypsy')
-rw-r--r--src/plugins/position/gypsy/gypsy.pro30
-rw-r--r--src/plugins/position/gypsy/plugin.json7
-rw-r--r--src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp54
-rw-r--r--src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h61
-rw-r--r--src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp368
-rw-r--r--src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h140
6 files changed, 660 insertions, 0 deletions
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