QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
QgsConnectionPoolGroup< T > Class Template Reference

Template that stores data related to a connection to a single server or datasource. More...

#include <qgsconnectionpool.h>

Classes

struct  Item

Public Member Functions

 QgsConnectionPoolGroup (const QgsConnectionPoolGroup &other)=delete
 QgsConnectionPoolGroup (const QString &ci)
 Constructor for QgsConnectionPoolGroup, with the specified connection info.
 ~QgsConnectionPoolGroup ()
acquire (int timeout, bool requestMayBeNested)
 Try to acquire a connection for a maximum of timeout milliseconds.
void invalidateConnections ()
QgsConnectionPoolGroupoperator= (const QgsConnectionPoolGroup &other)=delete
void release (T conn)

Protected Member Functions

template<typename U>
void initTimer (U *parent)
 Initializes the connection timeout handling.
void onConnectionExpired ()

Protected Attributes

QList< T > acquiredConns
QString connInfo
QMutex connMutex
QStack< Itemconns
QTimer * expirationTimer = nullptr
QSemaphore sem

Detailed Description

template<typename T>
class QgsConnectionPoolGroup< T >

Template that stores data related to a connection to a single server or datasource.

It is assumed that following functions exist:

  • void qgsConnectionPool_ConnectionCreate(QString name, T& c) ... create a new connection
  • void qgsConnectionPool_ConnectionDestroy(T c) ... destroy the connection
  • QString qgsConnectionPool_ConnectionToName(T c) ... lookup connection's name (path)
  • void qgsConnectionPool_InvalidateConnection(T c) ... flag a connection as invalid
  • bool qgsConnectionPool_ConnectionIsValid(T c) ... return whether a connection is valid

Because of issues with templates and QObject's signals and slots, this class only provides helper functions for QObject-related functionality - the place which uses the template is resonsible for:

  • being derived from QObject
  • calling initTimer( this ) in constructor
  • having handleConnectionExpired() slot that calls onConnectionExpired()
  • having startExpirationTimer(), stopExpirationTimer() slots to start/stop the expiration timer

For an example on how to use the template class, have a look at the implementation in Postgres/SpatiaLite providers.

Note
not available in Python bindings

Definition at line 64 of file qgsconnectionpool.h.

Constructor & Destructor Documentation

◆ QgsConnectionPoolGroup() [1/2]

template<typename T>
QgsConnectionPoolGroup< T >::QgsConnectionPoolGroup ( const QString & ci)
inline

Constructor for QgsConnectionPoolGroup, with the specified connection info.

Definition at line 77 of file qgsconnectionpool.h.

◆ ~QgsConnectionPoolGroup()

template<typename T>
QgsConnectionPoolGroup< T >::~QgsConnectionPoolGroup ( )
inline

Definition at line 83 of file qgsconnectionpool.h.

◆ QgsConnectionPoolGroup() [2/2]

template<typename T>
QgsConnectionPoolGroup< T >::QgsConnectionPoolGroup ( const QgsConnectionPoolGroup< T > & other)
delete

Member Function Documentation

◆ acquire()

template<typename T>
T QgsConnectionPoolGroup< T >::acquire ( int timeout,
bool requestMayBeNested )
inline

Try to acquire a connection for a maximum of timeout milliseconds.

If timeout is a negative value the calling thread will be blocked until a connection becomes available. This is the default behavior.

Returns
initialized connection or nullptr if unsuccessful

Definition at line 102 of file qgsconnectionpool.h.

◆ initTimer()

template<typename T>
template<typename U>
void QgsConnectionPoolGroup< T >::initTimer ( U * parent)
inlineprotected

Initializes the connection timeout handling.

Should be called from subclasses within their constructors, passing themselves as the parent.

Definition at line 226 of file qgsconnectionpool.h.

◆ invalidateConnections()

template<typename T>
void QgsConnectionPoolGroup< T >::invalidateConnections ( )
inline

Definition at line 203 of file qgsconnectionpool.h.

◆ onConnectionExpired()

template<typename T>
void QgsConnectionPoolGroup< T >::onConnectionExpired ( )
inlineprotected

Definition at line 237 of file qgsconnectionpool.h.

◆ operator=()

template<typename T>
QgsConnectionPoolGroup & QgsConnectionPoolGroup< T >::operator= ( const QgsConnectionPoolGroup< T > & other)
delete

◆ release()

template<typename T>
void QgsConnectionPoolGroup< T >::release ( T conn)
inline

Definition at line 174 of file qgsconnectionpool.h.

Member Data Documentation

◆ acquiredConns

template<typename T>
QList<T> QgsConnectionPoolGroup< T >::acquiredConns
protected

Definition at line 269 of file qgsconnectionpool.h.

◆ connInfo

template<typename T>
QString QgsConnectionPoolGroup< T >::connInfo
protected

Definition at line 267 of file qgsconnectionpool.h.

◆ connMutex

template<typename T>
QMutex QgsConnectionPoolGroup< T >::connMutex
protected

Definition at line 270 of file qgsconnectionpool.h.

◆ conns

template<typename T>
QStack<Item> QgsConnectionPoolGroup< T >::conns
protected

Definition at line 268 of file qgsconnectionpool.h.

◆ expirationTimer

template<typename T>
QTimer* QgsConnectionPoolGroup< T >::expirationTimer = nullptr
protected

Definition at line 272 of file qgsconnectionpool.h.

◆ sem

template<typename T>
QSemaphore QgsConnectionPoolGroup< T >::sem
protected

Definition at line 271 of file qgsconnectionpool.h.


The documentation for this class was generated from the following file: