summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.tests/locationd/locationd.pro8
-rw-r--r--config.tests/locationd/main.cpp49
-rw-r--r--src/location/location.pro9
-rw-r--r--src/location/qgeopositioninfosource_npe_backend.cpp311
-rw-r--r--src/location/qgeopositioninfosource_npe_backend_p.h34
-rw-r--r--src/location/qgeosatelliteinfosource_npe_backend.cpp198
-rw-r--r--src/location/qgeosatelliteinfosource_npe_backend_p.h38
-rw-r--r--sync.profile1
8 files changed, 235 insertions, 413 deletions
diff --git a/config.tests/locationd/locationd.pro b/config.tests/locationd/locationd.pro
new file mode 100644
index 00000000..3b1793f9
--- /dev/null
+++ b/config.tests/locationd/locationd.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+INCLUDEPATH += $$[QT_INSTALL_PREFIX]/include/mtlocationd
+#unix{
+# CONFIG += link_pkgconfig
+# PKGCONFIG += locationd
+# }
+LIBS += -lmtlocationd
+SOURCES += main.cpp
diff --git a/config.tests/locationd/main.cpp b/config.tests/locationd/main.cpp
new file mode 100644
index 00000000..ea2ec31f
--- /dev/null
+++ b/config.tests/locationd/main.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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 <locationdaemonconnection.h>
+
+int main()
+{
+ LocationDaemonConnection* m_locationdConn = new LocationDaemonConnection(0);
+ delete (m_locationdConn);
+ return 0;
+}
diff --git a/src/location/location.pro b/src/location/location.pro
index f3ea2d49..a67962e8 100644
--- a/src/location/location.pro
+++ b/src/location/location.pro
@@ -88,9 +88,14 @@ meego {
}
}
-!isEmpty(QT.jsondb.name):!isEmpty(QT.jsonstream.name):!simulator {
+contains(config_test_locationd, yes):!simulator {
DEFINES += NPE_BACKEND
- QT += jsondbcompat-private jsonstream
+ INCLUDEPATH += $$[QT_INSTALL_PREFIX]/include/mtlocationd
+#unix {
+# CONFIG += link_pkgconfig
+# PKGCONFIG += mtlocationd
+#}
+ LIBS += -lmtlocationd
SOURCES += qgeopositioninfosource_npe_backend.cpp\
qgeosatelliteinfosource_npe_backend.cpp
PRIVATE_HEADERS += qgeopositioninfosource_npe_backend_p.h\
diff --git a/src/location/qgeopositioninfosource_npe_backend.cpp b/src/location/qgeopositioninfosource_npe_backend.cpp
index 278ace1e..0807f8b2 100644
--- a/src/location/qgeopositioninfosource_npe_backend.cpp
+++ b/src/location/qgeopositioninfosource_npe_backend.cpp
@@ -40,100 +40,69 @@
****************************************************************************/
#include "qgeopositioninfosource_npe_backend_p.h"
-#include <sys/stat.h>
-
-QT_USE_NAMESPACE_JSONSTREAM
-
-// API for socket communication towards locationd
-const QString kstartUpdates = QLatin1String("startUpdates");
-const QString krequestUpdate = QLatin1String("requestUpdate");
-const QString kstopUpdates = QLatin1String("stopUpdates");
-const QString ksetUpdateInterval = QLatin1String("setUpdateInterval");
-const QString ksetPreferredMethod = QLatin1String("setPreferredMethod");
-const QString kgetMinimumUpdateInterval = QLatin1String("getMinimumUpdateInterval"); // Request
-const QString kgetMinimumUpdateIntervalReply = QLatin1String("getMinimumUpdateIntervalReply"); // Response
-const QString kgetSupportedMethods = QLatin1String("getSupportedMethods");
-const QString kgetSupportedMethodsReply = QLatin1String("getSupportedMethodsReply");
-const QString kgetLastKnownPosition = QLatin1String("getLastKnownPosition");
-const QString kgetLastKnownPositionReply = QLatin1String("getLastKnownPositionReply");
-const QString kpositionUpdate = QLatin1String("positionUpdate"); // Notification
-
-// Attributes for socket communication towards locationd
-const QString kinterval = QLatin1String("interval");
-const QString ksatelliteOnly = QLatin1String("satelliteOnly");
-const QString klatitude = QLatin1String("latitude");
-const QString klongitude = QLatin1String("longitude");
-const QString khorizontalAccuracy = QLatin1String("horizontalAccuracy");
-const QString kaltitude = QLatin1String("altitude");
-const QString kverticalAccuracy = QLatin1String("verticalAccuracy");
-const QString kgroundSpeed = QLatin1String("groundSpeed");
-const QString kverticalSpeed = QLatin1String("verticalSpeed");
-const QString kbearing = QLatin1String("bearing");
-const QString kmagneticVariation = QLatin1String("magneticVariation");
-const QString ktimestamp = QLatin1String("timestamp");
-const QString kmethod = QLatin1String("method");
-const QString kvalid = QLatin1String("valid");
-
-// socket to locationd
-const char* klocationdSocketName = "/var/run/locationd/locationd.socket";
+
QGeoPositionInfoSourceNpeBackend::QGeoPositionInfoSourceNpeBackend(QObject *parent):
- QGeoPositionInfoSource(parent), locationOngoing(false), timeoutSent(false), mPositionError(QGeoPositionInfoSource::UnknownSourceError)
+ QGeoPositionInfoSource(parent), locationOngoing(false), timeoutSent(false), mPositionError(QGeoPositionInfoSource::UnknownSourceError), m_locationdConn(0)
{
requestTimer = new QTimer(this);
QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired()));
- qRegisterMetaType<QJsonObject>("QJsonObject");
}
bool QGeoPositionInfoSourceNpeBackend::init()
{
- struct stat buf;
- if (stat(klocationdSocketName, &buf) == 0) {
- mSocket = new QLocalSocket(this);
- if (mSocket) {
- connect(mSocket, SIGNAL(connected()), this, SLOT(onSocketConnected()));
- connect(mSocket, SIGNAL(disconnected()), this, SLOT(onSocketDisconnected()));
- connect(mSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));
- mStream = new JsonStream(mSocket);
- if (mStream) {
- connect(mStream, SIGNAL(messageReceived(const QJsonObject&)), this, SLOT(onStreamReceived(const QJsonObject&)), Qt::QueuedConnection);
- }
- mSocket->connectToServer((QLatin1String)klocationdSocketName);
- return(mSocket->waitForConnected(500)); // wait up to 0.5 seconds to get connected, otherwise return false
- }
- }
- return(false);
+ 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
{
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(lastKnownPositionReceived()), &loop, SLOT(quit()));
- QJsonObject action;
- QJsonObject object;
- action[JsonDbString::kActionStr] = kgetLastKnownPosition;
- object[ksatelliteOnly] = fromSatellitePositioningMethodsOnly;
- action[JsonDbString::kDataStr] = object;
- mStream->send(action);
- loop.exec(); // wait for signal lastKnownPositionReceived()sent by slot onStreamReceived
+ 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
{
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(supportedPositioningMethodsReceived()), &loop, SLOT(quit()));
- QJsonObject action;
- action[JsonDbString::kActionStr] = kgetSupportedMethods;
- mStream->send(action);
- loop.exec(); // wait for supportedPositioningMethodsReceived() signal sent by slot onStreamReceived
- switch (supportedMethods){
- case QGeoPositionInfoSource::SatellitePositioningMethods:
+ switch (m_locationdConn->supportedMethods()) {
+ case LocationdStrings::PositionInfo::Satellite:
return(QGeoPositionInfoSource::SatellitePositioningMethods);
- case QGeoPositionInfoSource::NonSatellitePositioningMethods:
+ case LocationdStrings::PositionInfo::NonSatellite:
return(QGeoPositionInfoSource::NonSatellitePositioningMethods);
default:
return(QGeoPositionInfoSource::AllPositioningMethods);
@@ -141,49 +110,38 @@ QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceNpeBackend::sup
}
-void QGeoPositionInfoSourceNpeBackend::setUpdateInterval(int msec)
+void QGeoPositionInfoSourceNpeBackend::setPreferredPositioningMethods(PositioningMethods sources)
{
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
- QJsonObject action;
- action[JsonDbString::kActionStr] = kgetMinimumUpdateInterval;
- mStream->send(action);
- loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
- if (msec < minInterval && msec != 0)
- msec = minInterval;
- QGeoPositionInfoSource::setUpdateInterval(msec);
- if (!requestTimer->isActive()) {
- QJsonObject actionUpdate;
- QJsonObject object;
- actionUpdate[JsonDbString::kActionStr] = ksetUpdateInterval;
- object[kinterval] = msec;
- actionUpdate[JsonDbString::kDataStr] = object;
- mStream->send(actionUpdate);
+ 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::setPreferredPositioningMethods(PositioningMethods sources)
+void QGeoPositionInfoSourceNpeBackend::setUpdateInterval(int msec)
{
- QGeoPositionInfoSource::setPreferredPositioningMethods(sources);
- QJsonObject action;
- QJsonObject object;
- action[JsonDbString::kActionStr] = ksetPreferredMethod;
- object[kmethod] = int(sources);
- action[JsonDbString::kDataStr] = object;
- mStream->send(action);
+ 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
{
- QJsonObject action;
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
- action[JsonDbString::kActionStr] = kgetMinimumUpdateInterval;
- mStream->send(action);
- loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
- return(minInterval);
+ return(m_locationdConn->minimumUpdateInterval());
}
@@ -191,9 +149,7 @@ void QGeoPositionInfoSourceNpeBackend::startUpdates()
{
if (!locationOngoing) {
locationOngoing = true;
- QJsonObject action;
- action[JsonDbString::kActionStr] = kstartUpdates;
- mStream->send(action);
+ m_locationdConn->startPositionUpdates();
}
}
@@ -202,9 +158,7 @@ void QGeoPositionInfoSourceNpeBackend::stopUpdates()
{
if ( locationOngoing && !requestTimer->isActive() ) {
locationOngoing = false;
- QJsonObject action;
- action[JsonDbString::kActionStr] = kstopUpdates;
- mStream->send(action);
+ m_locationdConn->stopPositionUpdates();
}
}
@@ -224,20 +178,12 @@ void QGeoPositionInfoSourceNpeBackend::requestUpdate(int timeout)
}
// get position as fast as possible in case of ongoing satellite based session
if ( locationOngoing ) {
- if ( QGeoPositionInfoSource::updateInterval() != minimumInterval) {
- QJsonObject actionUpdate;
- QJsonObject object;
- actionUpdate[JsonDbString::kActionStr] = ksetUpdateInterval;
- object[kinterval] = minimumInterval;
- actionUpdate[JsonDbString::kDataStr] = object;
- mStream->send(actionUpdate);
- }
+ if ( QGeoPositionInfoSource::updateInterval() != minimumInterval)
+ m_locationdConn->setUpdateInterval(minimumInterval);
}
// request the update only if no tracking session is active
if ( !locationOngoing) {
- QJsonObject action;
- action[JsonDbString::kActionStr] = krequestUpdate;
- mStream->send(action);
+ m_locationdConn->requestPositionUpdate();
}
requestTimer->start(timeout);
}
@@ -264,92 +210,39 @@ void QGeoPositionInfoSourceNpeBackend::shutdownRequestSession()
}
-void QGeoPositionInfoSourceNpeBackend::onStreamReceived(const QJsonObject& jsonObject)
+void QGeoPositionInfoSourceNpeBackend::onPositionUpdate(const PositionData& position)
{
- // this slot handles the communication received from locationd socket
- QVariantMap map = jsonObject.toVariantMap();
- if (map.contains(JsonDbString::kActionStr)) {
- QString action = map.value(JsonDbString::kActionStr).toString();
-
- if (action == kgetMinimumUpdateIntervalReply) {
- QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
- minInterval = tmp.value(kinterval).toInt();
- emit minimumUpdateIntervalReceived();
- }
-
- else if (action == kgetSupportedMethodsReply) {
- QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
- supportedMethods = tmp.value(kmethod).toUInt();
- emit supportedPositioningMethodsReceived();
- }
-
- else if (action == kgetLastKnownPositionReply) {
- QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
- QGeoCoordinate coordinate;
- coordinate.setLatitude(tmp.value(klatitude).toDouble());
- coordinate.setLongitude(tmp.value(klongitude).toDouble());
- coordinate.setAltitude(tmp.value(kaltitude).toDouble());
- if (coordinate.isValid()) {
- lastPosition.setCoordinate(coordinate);
- lastPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, tmp.value(khorizontalAccuracy).toReal());
- lastPosition.setAttribute(QGeoPositionInfo::VerticalAccuracy, tmp.value(kverticalAccuracy).toReal());
- lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, tmp.value(kgroundSpeed).toReal());
- lastPosition.setAttribute(QGeoPositionInfo::VerticalSpeed, tmp.value(kverticalSpeed).toReal());
- lastPosition.setAttribute(QGeoPositionInfo::MagneticVariation, tmp.value(kmagneticVariation).toReal());
- lastPosition.setAttribute(QGeoPositionInfo::Direction, tmp.value(kbearing).toReal());
- QDateTime timestamp = tmp.value(ktimestamp).toDateTime();
- 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);
- }
- emit lastKnownPositionReceived();
- }
-
- else if (action == kpositionUpdate) {
- QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
- bool valid = tmp.value(kvalid).toBool();
- if (valid) {
- QGeoPositionInfo update;
- QGeoCoordinate coordinate;
- coordinate.setLatitude(tmp.value(klatitude).toDouble());
- coordinate.setLongitude(tmp.value(klongitude).toDouble());
- coordinate.setAltitude(tmp.value(kaltitude).toDouble());
- if (coordinate.isValid()) {
- update.setCoordinate(coordinate);
- update.setAttribute(QGeoPositionInfo::HorizontalAccuracy, tmp.value(khorizontalAccuracy).toReal());
- update.setAttribute(QGeoPositionInfo::VerticalAccuracy, tmp.value(kverticalAccuracy).toReal());
- update.setAttribute(QGeoPositionInfo::GroundSpeed, tmp.value(kgroundSpeed).toReal());
- update.setAttribute(QGeoPositionInfo::VerticalSpeed, tmp.value(kverticalSpeed).toReal());
- update.setAttribute(QGeoPositionInfo::MagneticVariation, tmp.value(kmagneticVariation).toReal());
- update.setAttribute(QGeoPositionInfo::Direction, tmp.value(kbearing).toReal());
- QDateTime timestamp = tmp.value(ktimestamp).toDateTime();
- update.setTimestamp(timestamp);
- emit positionUpdated(update);
- timeoutSent = false;
- if ( requestTimer->isActive() )
- shutdownRequestSession();
- } else {
- if (!timeoutSent) {
- emit updateTimeout();
- timeoutSent = true;
- }
- }
+ 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;
@@ -363,26 +256,16 @@ void QGeoPositionInfoSourceNpeBackend::setError(QGeoPositionInfoSource::Error po
}
-void QGeoPositionInfoSourceNpeBackend::onSocketError(QLocalSocket::LocalSocketError mError)
+void QGeoPositionInfoSourceNpeBackend::onConnectionError(LocationDaemonConnection::SocketError socketError)
{
- switch (mError) {
- case QLocalSocket::PeerClosedError:
+ switch (socketError) {
+ case LocationDaemonConnection::ClosedError:
setError(ClosedError);
break;
- case QLocalSocket::SocketAccessError:
+ case LocationDaemonConnection::AccessError:
setError(AccessError);
break;
default:
setError(UnknownSourceError);
}
}
-
-
-void QGeoPositionInfoSourceNpeBackend::onSocketConnected()
-{
-}
-
-
-void QGeoPositionInfoSourceNpeBackend::onSocketDisconnected()
-{
-}
diff --git a/src/location/qgeopositioninfosource_npe_backend_p.h b/src/location/qgeopositioninfosource_npe_backend_p.h
index 5b72fedb..36d16c7a 100644
--- a/src/location/qgeopositioninfosource_npe_backend_p.h
+++ b/src/location/qgeopositioninfosource_npe_backend_p.h
@@ -53,18 +53,10 @@
// We mean it.
//
-#include <qgeopositioninfosource.h>
-#include <private/jsondb-strings_p.h>
-#include <qlocalsocket.h>
-#include <qeventloop.h>
+#include "qgeopositioninfosource.h"
#include <qtimer.h>
-#include <QtAddOnJsonStream/jsonstream.h>
+#include <locationdaemonconnection.h>
-QT_BEGIN_NAMESPACE_JSONSTREAM
-class JsonStream;
-QT_END_NAMESPACE_JSONSTREAM
-
-Q_USE_JSONDB_NAMESPACE
class QGeoPositionInfoSourceNpeBackend : public QGeoPositionInfoSource
{
@@ -78,7 +70,7 @@ public:
QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const;
PositioningMethods supportedPositioningMethods() const;
int minimumUpdateInterval() const;
- Error error() const;
+ QGeoPositionInfoSource::Error error() const;
public Q_SLOTS:
void startUpdates();
@@ -86,28 +78,18 @@ public Q_SLOTS:
void requestUpdate(int timeout = 5000);
private:
- QLocalSocket* mSocket;
- QtAddOn::JsonStream::JsonStream* mStream;
- int minInterval;
- uint supportedMethods;
- QGeoPositionInfo lastPosition;
+ void setError(QGeoPositionInfoSource::Error positionError);
+ void shutdownRequestSession();
+ LocationDaemonConnection* m_locationdConn;
bool locationOngoing;
bool timeoutSent;
QTimer* requestTimer;
QGeoPositionInfoSource::Error mPositionError;
- void setError(QGeoPositionInfoSource::Error positionError);
- void shutdownRequestSession();
-Q_SIGNALS:
- void minimumUpdateIntervalReceived();
- void supportedPositioningMethodsReceived();
- void lastKnownPositionReceived();
private Q_SLOTS:
- void onStreamReceived(const QJsonObject &jsonObject);
- void onSocketConnected();
- void onSocketDisconnected();
- void onSocketError(QLocalSocket::LocalSocketError);
+ void onPositionUpdate(const PositionData &position);
+ void onConnectionError(LocationDaemonConnection::SocketError socketError);
void requestTimerExpired();
};
diff --git a/src/location/qgeosatelliteinfosource_npe_backend.cpp b/src/location/qgeosatelliteinfosource_npe_backend.cpp
index dfac72c6..47b6514e 100644
--- a/src/location/qgeosatelliteinfosource_npe_backend.cpp
+++ b/src/location/qgeosatelliteinfosource_npe_backend.cpp
@@ -40,30 +40,7 @@
****************************************************************************/
#include "qgeosatelliteinfosource_npe_backend_p.h"
-#include <sys/stat.h>
-
-QT_USE_NAMESPACE_JSONSTREAM
-
-
-// API for socket communication towards locationd
-const QString ksatelliteStartUpdates = QLatin1String("satelliteStartUpdates");
-const QString ksatelliteRequestUpdate = QLatin1String("satelliteRequestUpdate");
-const QString ksatelliteStopUpdates = QLatin1String("satelliteStopUpdates");
-const QString ksatelliteInfoUpdate = QLatin1String("satelliteInfoUpdate");
-const QString ksetUpdateInterval = QLatin1String("setUpdateInterval");
-const QString kgetMinimumUpdateInterval = QLatin1String("getMinimumUpdateInterval");
-const QString kgetMinimumUpdateIntervalReply = QLatin1String("getMinimumUpdateIntervalReply");
-// Attributes for socket communication towards locationd
-const QString ksatId = QLatin1String("satId");
-const QString kazimuth = QLatin1String("azimuth");
-const QString kelevation = QLatin1String("elevation");
-const QString ksignalStrength = QLatin1String("signalStrength");
-const QString ksatList = QLatin1String("satList");
-const QString ksystem = QLatin1String("system"); // {"GPS", "SBASS", "GLONASS", "QZSS", "IMES"}
-const QString kGPS = QLatin1String("GPS");
-const QString kGLONASS = QLatin1String("GLONASS");
-const QString ksatStatus = QLatin1String("satStatus");
-const QString kinterval = QLatin1String("interval");
+#include <qdebug.h>
// Bitmask Table for satStatus
@@ -74,66 +51,39 @@ const QString kinterval = QLatin1String("interval");
QGeoSatelliteInfoSourceNpeBackend::QGeoSatelliteInfoSourceNpeBackend(QObject *parent): QGeoSatelliteInfoSource(parent),
- satOngoing(false), mSatelliteError(QGeoSatelliteInfoSource::UnknownSourceError)
+ satOngoing(false), mSatelliteError(QGeoSatelliteInfoSource::UnknownSourceError), m_locationdConn(0)
{
requestTimer = new QTimer(this);
QObject::connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimerExpired()));
- qRegisterMetaType<QJsonObject>("QJsonObject");
}
bool QGeoSatelliteInfoSourceNpeBackend::init()
{
- struct stat buf;
- if (stat("/var/run/locationd/locationd.socket", &buf) == 0) {
- mSocket = new QLocalSocket(this);
- if (mSocket) {
- connect(mSocket, SIGNAL(connected()), this, SLOT(onSocketConnected()));
- connect(mSocket, SIGNAL(disconnected()), this, SLOT(onSocketDisconnected()));
- connect(mSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));
- mStream = new JsonStream(mSocket);
- if (mStream) {
- connect(mStream, SIGNAL(messageReceived(const QJsonObject&)), this, SLOT(onStreamReceived(const QJsonObject&)), Qt::QueuedConnection);
- }
- mSocket->connectToServer((QLatin1String)"/var/run/locationd/locationd.socket");
- return(mSocket->waitForConnected(500)); // wait up to 0.5 seconds to get connected, otherwise return false
- }
- }
- return(false);
+ 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)
{
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
- QJsonObject action;
- action[JsonDbString::kActionStr] = kgetMinimumUpdateInterval;
- mStream->send(action);
- loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
+ int minInterval = m_locationdConn->minimumUpdateInterval();
if (msec < minInterval && msec != 0)
msec = minInterval;
QGeoSatelliteInfoSource::setUpdateInterval(msec);
- if (!requestTimer->isActive()) {
- QJsonObject actionUpdate;
- QJsonObject object;
- actionUpdate[JsonDbString::kActionStr] = ksetUpdateInterval;
- object[kinterval] = msec;
- actionUpdate[JsonDbString::kDataStr] = object;
- mStream->send(actionUpdate);
- }
+ if (!requestTimer->isActive())
+ m_locationdConn->setUpdateInterval(msec);
}
int QGeoSatelliteInfoSourceNpeBackend::minimumUpdateInterval() const
{
- QEventLoop loop; // loop to wait for response from locationd (asynchronous socket connection)
- connect( this, SIGNAL(minimumUpdateIntervalReceived()), &loop, SLOT(quit()));
- QJsonObject action;
- action[JsonDbString::kActionStr] = kgetMinimumUpdateInterval;
- mStream->send(action);
- loop.exec(); // wait for minimumUpdateIntervalReceived() signal sent by slot onStreamReceived
- return(minInterval);
+ return(m_locationdConn->minimumUpdateInterval());
}
@@ -141,9 +91,7 @@ void QGeoSatelliteInfoSourceNpeBackend::startUpdates()
{
if (!satOngoing) {
satOngoing = true;
- QJsonObject action;
- action[JsonDbString::kActionStr] = ksatelliteStartUpdates;
- mStream->send(action);
+ m_locationdConn->startSatelliteUpdates();
}
}
@@ -152,9 +100,7 @@ void QGeoSatelliteInfoSourceNpeBackend::stopUpdates()
{
if (satOngoing && !requestTimer->isActive()) {
satOngoing = false;
- QJsonObject action;
- action[JsonDbString::kActionStr] = ksatelliteStopUpdates;
- mStream->send(action);
+ m_locationdConn->stopSatelliteUpdates();
}
}
@@ -173,21 +119,12 @@ void QGeoSatelliteInfoSourceNpeBackend::requestUpdate(int timeout)
}
// get satellite update as fast as possible in case of ongoing tracking session
if ( satOngoing ) {
- if ( QGeoSatelliteInfoSource::updateInterval() != minimumInterval) {
- QJsonObject actionUpdate;
- QJsonObject object;
- actionUpdate[JsonDbString::kActionStr] = ksetUpdateInterval;
- object[kinterval] = minimumInterval;
- actionUpdate[JsonDbString::kDataStr] = object;
- mStream->send(actionUpdate);
- }
+ if ( QGeoSatelliteInfoSource::updateInterval() != minimumInterval)
+ m_locationdConn->setUpdateInterval(minimumInterval);
}
// request the update only if no tracking session is active
- if ( !satOngoing) {
- QJsonObject action;
- action[JsonDbString::kActionStr] = ksatelliteRequestUpdate;
- mStream->send(action);
- }
+ if ( !satOngoing)
+ m_locationdConn->requestSatelliteUpdate();
requestTimer->start(timeout);
}
}
@@ -212,57 +149,40 @@ void QGeoSatelliteInfoSourceNpeBackend::shutdownRequestSession()
}
-void QGeoSatelliteInfoSourceNpeBackend::onStreamReceived(const QJsonObject& jsonObject)
+void QGeoSatelliteInfoSourceNpeBackend::onSatelliteUpdate(const QList<SatelliteData>& satellites)
{
- // this slot handles the communication received from locationd socket
- QVariantMap map = jsonObject.toVariantMap();
- if (map.contains(JsonDbString::kActionStr)) {
- QString action = map.value(JsonDbString::kActionStr).toString();
-
- if (action == kgetMinimumUpdateIntervalReply) {
- QVariantMap tmp = map.value(JsonDbString::kDataStr).toMap();
- minInterval = tmp.value(kinterval).toInt();
- emit minimumUpdateIntervalReceived();
- }
-
- if (action == ksatelliteInfoUpdate) {
- QVariantMap sat_info = map.value(JsonDbString::kDataStr).toMap();
- if (sat_info.contains(ksatList))
- {
- QVariantList sat_list = sat_info.value(ksatList).toList();
- QList<QGeoSatelliteInfo> inUse;
- QList<QGeoSatelliteInfo> inView;
- if (!sat_list.isEmpty()) {
- while (!sat_list.isEmpty())
- {
- QVariantMap sat_elem = sat_list.takeFirst().toMap();
- QGeoSatelliteInfo satinfo;
- satinfo.setAttribute(QGeoSatelliteInfo::Elevation, sat_elem.value(kelevation).toReal());
- satinfo.setAttribute(QGeoSatelliteInfo::Azimuth, sat_elem.value(kazimuth).toReal());
- satinfo.setSatelliteIdentifier(sat_elem.value(ksatId).toInt());
- satinfo.setSignalStrength(sat_elem.value(ksignalStrength).toInt());
- if (sat_elem.value(ksystem).toString() == kGPS)
- satinfo.setSatelliteSystem(QGeoSatelliteInfo::GPS);
- else if (sat_elem.value(ksystem).toString() == kGLONASS)
- satinfo.setSatelliteSystem(QGeoSatelliteInfo::GLONASS);
- else
- satinfo.setSatelliteSystem(QGeoSatelliteInfo::Undefined);
- if (sat_elem.value(ksatStatus).toUInt() & SATELLITES_STATUS_VISIBLE) {
- inView.append(satinfo);
- if (sat_elem.value(ksatStatus).toUInt() & 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();
- }
+ 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();
}
}
@@ -280,26 +200,16 @@ void QGeoSatelliteInfoSourceNpeBackend::setError(QGeoSatelliteInfoSource::Error
}
-void QGeoSatelliteInfoSourceNpeBackend::onSocketError(QLocalSocket::LocalSocketError mError)
+void QGeoSatelliteInfoSourceNpeBackend::onConnectionError(LocationDaemonConnection::SocketError socketError)
{
- switch (mError) {
- case QLocalSocket::PeerClosedError:
+ switch (socketError) {
+ case LocationDaemonConnection::ClosedError:
setError(ClosedError);
break;
- case QLocalSocket::SocketAccessError:
+ case LocationDaemonConnection::AccessError:
setError(AccessError);
break;
default:
setError(UnknownSourceError);
}
}
-
-
-void QGeoSatelliteInfoSourceNpeBackend::onSocketConnected()
-{
-}
-
-
-void QGeoSatelliteInfoSourceNpeBackend::onSocketDisconnected()
-{
-}
diff --git a/src/location/qgeosatelliteinfosource_npe_backend_p.h b/src/location/qgeosatelliteinfosource_npe_backend_p.h
index a5e9b4c5..1a8f3568 100644
--- a/src/location/qgeosatelliteinfosource_npe_backend_p.h
+++ b/src/location/qgeosatelliteinfosource_npe_backend_p.h
@@ -54,18 +54,9 @@
//
#include "qgeosatelliteinfosource.h"
-#include "qgeosatelliteinfo.h"
-#include <private/jsondb-strings_p.h>
-#include <qlocalsocket.h>
-#include <qeventloop.h>
#include <qtimer.h>
-#include <QtAddOnJsonStream/jsonstream.h>
+#include <locationdaemonconnection.h>
-QT_BEGIN_NAMESPACE_JSONSTREAM
-class JsonStream;
-QT_END_NAMESPACE_JSONSTREAM
-
-Q_USE_JSONDB_NAMESPACE
class QGeoSatelliteInfoSourceNpeBackend: public QGeoSatelliteInfoSource
{
@@ -76,33 +67,26 @@ public:
bool init();
void setUpdateInterval(int interval);
int minimumUpdateInterval() const;
- Error error() const;
+ QGeoSatelliteInfoSource::Error error() const;
public Q_SLOTS:
void startUpdates();
void stopUpdates();
void requestUpdate(int timeout = 5000);
-Q_SIGNALS:
- void requestTimeout();
- void minimumUpdateIntervalReceived();
-
-private Q_SLOTS:
- void onStreamReceived(const QJsonObject &jsonObject);
- void onSocketConnected();
- void onSocketDisconnected();
- void requestTimerExpired();
- void shutdownRequestSession();
- void onSocketError(QLocalSocket::LocalSocketError);
-
private:
- QLocalSocket* mSocket;
- QtAddOn::JsonStream::JsonStream* mStream;
+ void setError(QGeoSatelliteInfoSource::Error satelliteError);
+ void shutdownRequestSession();
+ LocationDaemonConnection* m_locationdConn;
bool satOngoing;
QTimer* requestTimer;
- int minInterval;
QGeoSatelliteInfoSource::Error mSatelliteError;
- void setError(QGeoSatelliteInfoSource::Error satelliteError);
+
+
+private Q_SLOTS:
+ void onSatelliteUpdate(const QList<SatelliteData>& satellites);
+ void onConnectionError(LocationDaemonConnection::SocketError socketError);
+ void requestTimerExpired();
};
#endif // QGEOSATELLITEINFOSOURCE_NPE_BACKEND_H
diff --git a/sync.profile b/sync.profile
index f775132e..c57b51b8 100644
--- a/sync.profile
+++ b/sync.profile
@@ -32,4 +32,5 @@
# compile tests
%configtests = (
+ "locationd" => {},
);