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/position/simulator | |
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/position/simulator')
12 files changed, 1093 insertions, 0 deletions
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 |