Skip to content

Commit

Permalink
Add thread safe QgsNetworkAccessManager::requestTimedOut signal
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 23, 2019
1 parent 1190000 commit 5824faf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
19 changes: 19 additions & 0 deletions python/core/auto_generated/qgsnetworkaccessmanager.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ created in any thread.

.. seealso:: :py:func:`finished`

.. seealso:: :py:func:`requestTimedOut`

.. versionadded:: 3.6
%End

Expand All @@ -189,6 +191,23 @@ created in any thread.

.. seealso:: :py:func:`requestAboutToBeCreated`

.. seealso:: :py:func:`requestTimedOut`

.. versionadded:: 3.6
%End

void requestTimedOut( QgsNetworkRequestParameters request );
%Docstring
Emitted when a network request has timed out.

This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary
only to connect to the main thread's signal in order to receive notifications about requests
created in any thread.

.. seealso:: :py:func:`requestAboutToBeCreated`

.. seealso:: :py:func:`finished`

.. versionadded:: 3.6
%End

Expand Down
9 changes: 6 additions & 3 deletions src/core/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ void QgsNetworkAccessManager::abortRequest()
QgsDebugMsgLevel( QStringLiteral( "Abort [reply:%1] %2" ).arg( reinterpret_cast< qint64 >( reply ), 0, 16 ).arg( reply->url().toString() ), 3 );
QgsMessageLog::logMessage( tr( "Network request %1 timed out" ).arg( reply->url().toString() ), tr( "Network" ) );
// Notify the application
emit requestTimedOut( QgsNetworkRequestParameters( reply->operation(), reply->request(), reply->property( "requestId" ).toInt() ) );
emit requestTimedOut( reply );

}

void QgsNetworkAccessManager::onReplyFinished( QNetworkReply *reply )
Expand Down Expand Up @@ -308,8 +308,11 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn
sMainNAM, &QNetworkAccessManager::proxyAuthenticationRequired,
connectionType );

connect( this, &QgsNetworkAccessManager::requestTimedOut,
sMainNAM, &QgsNetworkAccessManager::requestTimedOut );
connect( this, qgis::overload< QNetworkReply *>::of( &QgsNetworkAccessManager::requestTimedOut ),
sMainNAM, qgis::overload< QNetworkReply *>::of( &QgsNetworkAccessManager::requestTimedOut ) );

connect( this, qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestTimedOut ),
sMainNAM, qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestTimedOut ) );

connect( this, qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ),
sMainNAM, qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ) );
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsnetworkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
* created in any thread.
*
* \see finished( QgsNetworkReplyContent )
* \see requestTimedOut( QgsNetworkRequestParameters )
* \since QGIS 3.6
*/
void requestAboutToBeCreated( QgsNetworkRequestParameters request );
Expand All @@ -189,10 +190,24 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
* created in any thread.
*
* \see requestAboutToBeCreated( QgsNetworkRequestParameters )
* \see requestTimedOut( QgsNetworkRequestParameters )
* \since QGIS 3.6
*/
void finished( QgsNetworkReplyContent reply );

/**
* Emitted when a network request has timed out.
*
* This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary
* only to connect to the main thread's signal in order to receive notifications about requests
* created in any thread.
*
* \see requestAboutToBeCreated( QgsNetworkRequestParameters )
* \see finished( QgsNetworkReplyContent )
* \since QGIS 3.6
*/
void requestTimedOut( QgsNetworkRequestParameters request );

void requestCreated( QNetworkReply * );
void requestTimedOut( QNetworkReply * );

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ QgsWfsRequest::QgsWfsRequest( const QgsWFSDataSourceURI &uri )
, mGotNonEmptyResponse( false )
{
QgsDebugMsgLevel( QStringLiteral( "theUri = " ) + uri.uri( ), 4 );
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::requestTimedOut, this, &QgsWfsRequest::requestTimedOut );
connect( QgsNetworkAccessManager::instance(), qgis::overload< QNetworkReply *>::of( &QgsNetworkAccessManager::requestTimedOut ), this, &QgsWfsRequest::requestTimedOut );
}

QgsWfsRequest::~QgsWfsRequest()
Expand Down

0 comments on commit 5824faf

Please sign in to comment.