Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeosatelliteinfosource_android.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QDebug>
5
7#include "jnipositioning.h"
8
9Q_DECLARE_METATYPE(QList<QGeoSatelliteInfo>)
10
11#define UPDATE_FROM_COLD_START 2*60*1000
12
14 QGeoSatelliteInfoSource(parent), m_error(NoError), updatesRunning(false)
15{
16 qRegisterMetaType< QGeoSatelliteInfo >();
17 qRegisterMetaType< QList<QGeoSatelliteInfo> >();
18 androidClassKeyForUpdate = AndroidPositioning::registerPositionInfoSource(this);
19 androidClassKeyForSingleRequest = AndroidPositioning::registerPositionInfoSource(this);
20
21 requestTimer.setSingleShot(true);
22 QObject::connect(&requestTimer, SIGNAL(timeout()),
23 this, SLOT(requestTimeout()));
24}
25
27{
29
30 if (requestTimer.isActive()) {
31 requestTimer.stop();
32 AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest);
33 }
34
36 AndroidPositioning::unregisterPositionInfoSource(androidClassKeyForSingleRequest);
37}
38
39
41{
42 int previousInterval = updateInterval();
43 msec = (((msec > 0) && (msec < minimumUpdateInterval())) || msec < 0)? minimumUpdateInterval() : msec;
44
45 if (msec == previousInterval)
46 return;
47
49
50 if (updatesRunning)
51 reconfigureRunningSystem();
52}
53
58
63
65{
66 if (updatesRunning)
67 return;
68
69 updatesRunning = true;
70
72
74 androidClassKeyForUpdate, false, updateInterval());
76 updatesRunning = false;
77 setError(error);
78 }
79}
80
82{
83 if (!updatesRunning)
84 return;
85
86 updatesRunning = false;
87 AndroidPositioning::stopUpdates(androidClassKeyForUpdate);
88}
89
91{
92 if (requestTimer.isActive())
93 return;
94
96
97 if (timeout != 0 && timeout < minimumUpdateInterval()) {
99 return;
100 }
101
102 if (timeout == 0)
104
105 requestTimer.start(timeout);
106
107 // if updates already running with interval equal or less then timeout
108 // then we wait for next update coming through
109 // assume that a single update will not be quicker than regular updates anyway
110 if (updatesRunning && updateInterval() <= timeout)
111 return;
112
114 androidClassKeyForSingleRequest, true, timeout);
116 requestTimer.stop();
117 setError(error);
118 }
119}
120
121void
122QGeoSatelliteInfoSourceAndroid::processSatelliteUpdate(const QList<QGeoSatelliteInfo> &satsInView,
123 const QList<QGeoSatelliteInfo> &satsInUse,
124 bool isSingleUpdate)
125{
126 if (!isSingleUpdate) {
127 //if single update is requested while regular updates are running
128 if (requestTimer.isActive())
129 requestTimer.stop();
132 return;
133 }
134
135 m_satsInView = satsInView;
136 m_satsInUse = satsInUse;
137
138 if (!m_satsInView.isEmpty() || !m_satsInUse.isEmpty()) {
139 requestTimer.stop();
140 requestTimeout();
141 }
142}
143
144void QGeoSatelliteInfoSourceAndroid::requestTimeout()
145{
146 AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest);
147
148 if (m_satsInView.isEmpty() && m_satsInUse.isEmpty()) {
150 return;
151 }
152
155
156 m_satsInUse.clear();
157 m_satsInView.clear();
158}
159
160/*
161 Updates the system assuming that updateInterval
162 and/or preferredPositioningMethod have changed.
163 */
164void QGeoSatelliteInfoSourceAndroid::reconfigureRunningSystem()
165{
166 if (!updatesRunning)
167 return;
168
169 stopUpdates();
170 startUpdates();
171}
172
173void QGeoSatelliteInfoSourceAndroid::setError(QGeoSatelliteInfoSource::Error error)
174{
175 m_error = error;
178}
179
void processSatelliteUpdate(const QList< QGeoSatelliteInfo > &satsInView, const QList< QGeoSatelliteInfo > &satsInUse, bool isSingleUpdate)
Error error() const override
Returns the last error that occurred.
\inmodule QtPositioning
virtual void setUpdateInterval(int msec)
Error
The Error enumeration represents the errors which can occur.
int updateInterval
This property holds the requested interval in milliseconds between each update.
void satellitesInViewUpdated(const QList< QGeoSatelliteInfo > &satellites)
If startUpdates() or requestUpdate() is called, this signal is emitted when an update is available on...
void satellitesInUseUpdated(const QList< QGeoSatelliteInfo > &satellites)
If startUpdates() or requestUpdate() is called, this signal is emitted when an update is available on...
void errorOccurred(QGeoSatelliteInfoSource::Error)
This signal is emitted after an error occurred.
bool isEmpty() const noexcept
Definition qlist.h:401
void clear()
Definition qlist.h:434
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void setSingleShot(bool singleShot)
Definition qtimer.cpp:552
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition qtimer.cpp:241
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition qtimer.cpp:167
void stop()
Stops the timer.
Definition qtimer.cpp:267
void unregisterPositionInfoSource(int key)
QGeoSatelliteInfoSource::Error startSatelliteUpdates(int androidClassKey, bool isSingleRequest, int requestTimeout)
int registerPositionInfoSource(QObject *obj)
void stopUpdates(int androidClassKey)
DBusConnection const char DBusError * error
#define UPDATE_FROM_COLD_START
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLbitfield GLuint64 timeout
[4]
@ NoError
Definition main.cpp:34
#define emit