16 #ifndef QGSCONNECTIONPOOL_H 17 #define QGSCONNECTIONPOOL_H 19 #include <QCoreApplication> 30 #define CONN_POOL_MAX_CONCURRENT_CONNS 4 31 #define CONN_POOL_EXPIRATION_TIME 60 // in seconds 77 qgsConnectionPool_ConnectionDestroy( item.
c );
90 if ( !
conns.isEmpty() )
93 if ( !qgsConnectionPool_ConnectionIsValid( i.
c ) )
95 qgsConnectionPool_ConnectionDestroy( i.
c );
96 qgsConnectionPool_ConnectionCreate(
connInfo, i.
c );
100 if (
conns.isEmpty() )
113 qgsConnectionPool_ConnectionCreate(
connInfo, c );
131 if ( !qgsConnectionPool_ConnectionIsValid( conn ) )
133 qgsConnectionPool_ConnectionDestroy( conn );
159 qgsConnectionPool_ConnectionDestroy( i.
c );
163 qgsConnectionPool_InvalidateConnection( c );
188 for (
int i = 0; i <
conns.count(); ++i )
195 for (
int j = toDelete.
count() - 1; j >= 0; --j )
197 int index = toDelete[j];
198 qgsConnectionPool_ConnectionDestroy(
conns[index].
c );
199 conns.remove( index );
202 if (
conns.isEmpty() )
234 template <
typename T,
typename T_Group>
244 Q_FOREACH ( T_Group* group, mGroups )
257 typename T_Groups::iterator it = mGroups.find( connInfo );
258 if ( it == mGroups.end() )
260 it = mGroups.insert( connInfo,
new T_Group( connInfo ) );
262 T_Group* group = *it;
265 return group->acquire();
272 typename T_Groups::iterator it = mGroups.find( qgsConnectionPool_ConnectionToName( conn ) );
273 Q_ASSERT( it != mGroups.end() );
274 T_Group* group = *it;
277 group->release( conn );
288 if ( mGroups.contains( connInfo ) )
300 #endif // QGSCONNECTIONPOOL_H void setInterval(int msec)
#define CONN_POOL_MAX_CONCURRENT_CONNS
virtual ~QgsConnectionPool()
#define CONN_POOL_EXPIRATION_TIME
void moveToThread(QThread *targetThread)
void invalidateConnections(const QString &connInfo)
Invalidates all connections to the specified resource.
QMap< QString, T_Group * > T_Groups
void initTimer(QObject *parent)
int count(const T &value) const
void append(const T &value)
void releaseConnection(T conn)
Release an existing connection so it will get back into the pool and can be reused.
int removeAll(const T &value)
void onConnectionExpired()
~QgsConnectionPoolGroup()
static const int maxConcurrentConnections
T acquireConnection(const QString &connInfo)
Try to acquire a connection: if no connections are available, the thread will get blocked...
Template class responsible for keeping a pool of open connections.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Template that stores data related to one server.
QgsConnectionPoolGroup(const QString &ci)
void invalidateConnections()