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
4#include <QDebug>
5
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
35 AndroidPositioning::unregisterPositionInfoSource(androidClassKeyForUpdate);
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
48 QGeoSatelliteInfoSource::setUpdateInterval(msec);
49
50 if (updatesRunning)
51 reconfigureRunningSystem();
52}
53
55{
56 return 50;
57}
58
63
65{
66 if (updatesRunning)
67 return;
68
69 updatesRunning = true;
70
71 m_error = QGeoSatelliteInfoSource::NoError;
72
73 QGeoSatelliteInfoSource::Error error = AndroidPositioning::startSatelliteUpdates(
74 androidClassKeyForUpdate, false, updateInterval());
75 if (error != QGeoSatelliteInfoSource::NoError) {
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
95 m_error = QGeoSatelliteInfoSource::NoError;
96
97 if (timeout != 0 && timeout < minimumUpdateInterval()) {
98 setError(QGeoSatelliteInfoSource::UpdateTimeoutError);
99 return;
100 }
101
102 if (timeout == 0)
103 timeout = UPDATE_FROM_COLD_START;
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
113 QGeoSatelliteInfoSource::Error error = AndroidPositioning::startSatelliteUpdates(
114 androidClassKeyForSingleRequest, true, timeout);
115 if (error != QGeoSatelliteInfoSource::NoError) {
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();
130 emit QGeoSatelliteInfoSource::satellitesInViewUpdated(satsInView);
131 emit QGeoSatelliteInfoSource::satellitesInUseUpdated(satsInUse);
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()) {
149 setError(QGeoSatelliteInfoSource::UpdateTimeoutError);
150 return;
151 }
152
153 emit QGeoSatelliteInfoSource::satellitesInViewUpdated(m_satsInView);
154 emit QGeoSatelliteInfoSource::satellitesInUseUpdated(m_satsInUse);
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
170 startUpdates();
171}
172
173void QGeoSatelliteInfoSourceAndroid::setError(QGeoSatelliteInfoSource::Error error)
174{
175 m_error = error;
176 if (m_error != QGeoSatelliteInfoSource::NoError)
177 emit QGeoSatelliteInfoSource::errorOccurred(m_error);
178}
179
181{
182 setError(QGeoSatelliteInfoSource::ClosedError);
183}
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:73
\inmodule QtCore
Definition qobject.h:103
void stopUpdates(int androidClassKey)
#define UPDATE_FROM_COLD_START