Commit 8230f01f authored by Vyacheslav Koscheev's avatar Vyacheslav Koscheev

GMS: simplificating code

parent 82811c5c
......@@ -94,12 +94,7 @@ QAndroidGmsLocationProvider::QAndroidGmsLocationProvider(QObject * parent)
, minimumInterval_(1000)
, priority_(PRIORITY_NO_POWER)
, regularUpdadesId_(0)
, requestUpdadesId_(0)
, requestTimer_(this) // should be set due to parent's move to moveToThread operation
{
QObject::connect(&requestTimer_, &QTimer::timeout,
this, &QAndroidGmsLocationProvider::onRequestTimeout);
QObject::connect(qApp, &QGuiApplication::applicationStateChanged,
this, &QAndroidGmsLocationProvider::onApplicationStateChanged);
......@@ -218,15 +213,22 @@ void QAndroidGmsLocationProvider::startUpdates()
void QAndroidGmsLocationProvider::stopUpdates()
{
jlong id = 0;
RequestsColl requests;
{
QMutexLocker lock(&lastLocationSync_);
id = regularUpdadesId_;
requests.push_back(regularUpdadesId_);
requests.insert(requests.end(), requestUpdadesIds_.cbegin(), requestUpdadesIds_.cend());
regularUpdadesId_ = 0;
requestUpdadesIds_.clear();
}
stopUpdates(id);
for (RequestsColl::const_iterator it = requests.cbegin(); it != requests.cend(); ++it)
{
stopUpdates(*it);
}
}
......@@ -237,18 +239,6 @@ void QAndroidGmsLocationProvider::stopUpdates(jlong requestId)
if (isJniReady())
{
jni()->callParamVoid("stopLocationUpdates", "J", requestId);
bool bStopTimer = false;
{
QMutexLocker lock(&lastLocationSync_);
bStopTimer = (requestId == requestUpdadesId_);
}
if (bStopTimer)
{
requestTimer_.stop();
}
}
}
......@@ -289,37 +279,15 @@ void QAndroidGmsLocationProvider::onCheckRequest(jlong requestId)
}
void QAndroidGmsLocationProvider::onRequestTimeout()
{
jlong id = 0;
{
QMutexLocker lock(&lastLocationSync_);
id = requestUpdadesId_;
requestUpdadesId_ = 0;
}
stopUpdates(id);
}
void QAndroidGmsLocationProvider::requestUpdate(int timeout /*= 0*/)
{
qDebug() << __FUNCTION__;
if (requestTimer_.isActive() || timeout < 0)
{
return;
}
if (0 == timeout)
{
timeout = std::max(1000, 2 * reqiredInterval_);
}
requestTimer_.setSingleShot(true);
requestTimer_.start(timeout);
if (isJniReady())
{
jlong maxWaitTime = 0;
......@@ -338,7 +306,7 @@ void QAndroidGmsLocationProvider::requestUpdate(int timeout /*= 0*/)
{
QMutexLocker lock(&lastLocationSync_);
requestUpdadesId_ = id;
requestUpdadesIds_.push_back(id);
}
qDebug() << "request id =" << id;
......
......@@ -78,7 +78,6 @@ public slots:
virtual void requestUpdate(int timeout = 0);
private slots:
void onRequestTimeout();
void onApplicationStateChanged(Qt::ApplicationState state);
void onCheckRequest(jlong requestId);
......@@ -115,10 +114,9 @@ private:
int minimumInterval_;
enPriority priority_;
typedef std::list<jlong> RequestsColl;
jlong regularUpdadesId_;
jlong requestUpdadesId_;
QTimer requestTimer_;
RequestsColl requestUpdadesIds_;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment