Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#include <QDebug>
6
9
10Q_DECLARE_METATYPE(QList<QGeoSatelliteInfo>)
11
12#define UPDATE_FROM_COLD_START 2*60*1000
13
15 QGeoSatelliteInfoSource(parent), m_error(NoError), updatesRunning(false)
16{
17 qRegisterMetaType< QGeoSatelliteInfo >();
18 qRegisterMetaType< QList<QGeoSatelliteInfo> >();
19 androidClassKeyForUpdate = AndroidPositioning::registerPositionInfoSource(this);
20 androidClassKeyForSingleRequest = AndroidPositioning::registerPositionInfoSource(this);
21
22 requestTimer.setSingleShot(true);
23 QObject::connect(&requestTimer, SIGNAL(timeout()),
24 this, SLOT(requestTimeout()));
25}
26
28{
30
31 if (requestTimer.isActive()) {
32 requestTimer.stop();
33 AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest);
34 }
35
36 AndroidPositioning::unregisterPositionInfoSource(androidClassKeyForUpdate);
37 AndroidPositioning::unregisterPositionInfoSource(androidClassKeyForSingleRequest);
38}
39
40
42{
43 int previousInterval = updateInterval();
44 msec = (((msec > 0) && (msec < minimumUpdateInterval())) || msec < 0)? minimumUpdateInterval() : msec;
45
46 if (msec == previousInterval)
47 return;
48
49 QGeoSatelliteInfoSource::setUpdateInterval(msec);
50
51 if (updatesRunning)
52 reconfigureRunningSystem();
53}
54
56{
57 return 50;
58}
59
64
66{
67 if (updatesRunning)
68 return;
69
70 updatesRunning = true;
71
72 m_error = QGeoSatelliteInfoSource::NoError;
73
74 QGeoSatelliteInfoSource::Error error = AndroidPositioning::startSatelliteUpdates(
75 androidClassKeyForUpdate, false, updateInterval());
76 if (error != QGeoSatelliteInfoSource::NoError) {
77 updatesRunning = false;
78 setError(error);
79 }
80}
81
83{
84 if (!updatesRunning)
85 return;
86
87 updatesRunning = false;
88 AndroidPositioning::stopUpdates(androidClassKeyForUpdate);
89}
90
92{
93 if (requestTimer.isActive())
94 return;
95
96 m_error = QGeoSatelliteInfoSource::NoError;
97
98 if (timeout != 0 && timeout < minimumUpdateInterval()) {
99 setError(QGeoSatelliteInfoSource::UpdateTimeoutError);
100 return;
101 }
102
103 if (timeout == 0)
104 timeout = UPDATE_FROM_COLD_START;
105
106 requestTimer.start(timeout);
107
108 // if updates already running with interval equal or less then timeout
109 // then we wait for next update coming through
110 // assume that a single update will not be quicker than regular updates anyway
111 if (updatesRunning && updateInterval() <= timeout)
112 return;
113
114 QGeoSatelliteInfoSource::Error error = AndroidPositioning::startSatelliteUpdates(
115 androidClassKeyForSingleRequest, true, timeout);
116 if (error != QGeoSatelliteInfoSource::NoError) {
117 requestTimer.stop();
118 setError(error);
119 }
120}
121
122void
123QGeoSatelliteInfoSourceAndroid::processSatelliteUpdate(const QList<QGeoSatelliteInfo> &satsInView,
124 const QList<QGeoSatelliteInfo> &satsInUse,
125 bool isSingleUpdate)
126{
127 if (!isSingleUpdate) {
128 //if single update is requested while regular updates are running
129 if (requestTimer.isActive())
130 requestTimer.stop();
131 emit QGeoSatelliteInfoSource::satellitesInViewUpdated(satsInView);
132 emit QGeoSatelliteInfoSource::satellitesInUseUpdated(satsInUse);
133 return;
134 }
135
136 m_satsInView = satsInView;
137 m_satsInUse = satsInUse;
138
139 if (!m_satsInView.isEmpty() || !m_satsInUse.isEmpty()) {
140 requestTimer.stop();
141 requestTimeout();
142 }
143}
144
145void QGeoSatelliteInfoSourceAndroid::requestTimeout()
146{
147 AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest);
148
149 if (m_satsInView.isEmpty() && m_satsInUse.isEmpty()) {
150 setError(QGeoSatelliteInfoSource::UpdateTimeoutError);
151 return;
152 }
153
154 emit QGeoSatelliteInfoSource::satellitesInViewUpdated(m_satsInView);
155 emit QGeoSatelliteInfoSource::satellitesInUseUpdated(m_satsInUse);
156
157 m_satsInUse.clear();
158 m_satsInView.clear();
159}
160
161/*
162 Updates the system assuming that updateInterval
163 and/or preferredPositioningMethod have changed.
164 */
165void QGeoSatelliteInfoSourceAndroid::reconfigureRunningSystem()
166{
167 if (!updatesRunning)
168 return;
169
171 startUpdates();
172}
173
174void QGeoSatelliteInfoSourceAndroid::setError(QGeoSatelliteInfoSource::Error error)
175{
176 m_error = error;
177 if (m_error != QGeoSatelliteInfoSource::NoError)
178 emit QGeoSatelliteInfoSource::errorOccurred(m_error);
179}
180
182{
183 setError(QGeoSatelliteInfoSource::ClosedError);
184}
void processSatelliteUpdate(const QList< QGeoSatelliteInfo > &satsInView, const QList< QGeoSatelliteInfo > &satsInUse, bool isSingleUpdate)
Error error() const override
Returns the last error that occurred.
QObject * parent
Definition qobject.h:74
\inmodule QtCore
Definition qobject.h:106
void stopUpdates(int androidClassKey)
#define UPDATE_FROM_COLD_START