Skip to content

Commit

Permalink
Update WFS request to accomodate changes in QgsNetworkAccessManager
Browse files Browse the repository at this point in the history
Because the manager now handles waking up worker threads after
an authentication request, the WFS request handler no longer needs
to do this itself.
  • Loading branch information
nyalldawson committed Feb 1, 2019
1 parent 4908ef1 commit 630cd02
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/providers/wfs/qgswfsrequest.cpp
Expand Up @@ -131,6 +131,7 @@ bool QgsWfsRequest::sendGET( const QUrl &url, bool synchronous, bool forceRefres

QWaitCondition waitCondition;
QMutex waitConditionMutex;

bool threadFinished = false;
bool success = false;

Expand Down Expand Up @@ -163,20 +164,20 @@ bool QgsWfsRequest::sendGET( const QUrl &url, bool synchronous, bool forceRefres
{
auto resumeMainThread = [&waitConditionMutex, &waitCondition]()
{
// when this method is called we have "produced" a single authentication request -- so the buffer is now full
// and it's time for the "consumer" (main thread) to do its part
waitConditionMutex.lock();
waitCondition.wakeAll();
waitConditionMutex.unlock();

waitConditionMutex.lock();
waitCondition.wait( &waitConditionMutex );
waitConditionMutex.unlock();
// note that we don't need to handle waking this thread back up - that's done automatically by QgsNetworkAccessManager
};

connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authenticationRequired, this, resumeMainThread, Qt::DirectConnection );
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection );
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection );

#ifndef QT_NO_SSL
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrors, this, resumeMainThread, Qt::DirectConnection );
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection );
#endif
QEventLoop loop;
connect( this, &QgsWfsRequest::downloadFinished, &loop, &QEventLoop::quit, Qt::DirectConnection );
Expand Down Expand Up @@ -205,17 +206,16 @@ bool QgsWfsRequest::sendGET( const QUrl &url, bool synchronous, bool forceRefres
waitCondition.wait( &waitConditionMutex );

// If the downloader thread wakes us (the main thread) up and is not yet finished
// he needs the authentication to run.
// then it has "produced" an authentication request which we need to now "consume".
// The processEvents() call gives the auth manager the chance to show a dialog and
// once done with that, we can wake the downloaderThread again and continue the download.
if ( !threadFinished )
{
waitConditionMutex.unlock();

QgsApplication::instance()->processEvents();
waitConditionMutex.lock();
waitCondition.wakeAll();
waitConditionMutex.unlock();
// we don't need to wake up the worker thread - it will automatically be woken when
// the auth request has been dealt with by QgsNetworkAccessManager
}
else
{
Expand Down

0 comments on commit 630cd02

Please sign in to comment.