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 78 qgsConnectionPool_ConnectionDestroy( item.
c );
91 if ( !
conns.isEmpty() )
94 if ( !qgsConnectionPool_ConnectionIsValid( i.
c ) )
96 qgsConnectionPool_ConnectionDestroy( i.
c );
97 qgsConnectionPool_ConnectionCreate(
connInfo, i.
c );
101 if (
conns.isEmpty() )
114 qgsConnectionPool_ConnectionCreate(
connInfo, c );
132 if ( !qgsConnectionPool_ConnectionIsValid( conn ) )
134 qgsConnectionPool_ConnectionDestroy( conn );
160 qgsConnectionPool_ConnectionDestroy( i.
c );
164 qgsConnectionPool_InvalidateConnection( c );
189 for (
int i = 0; i <
conns.count(); ++i )
196 for (
int j = toDelete.
count() - 1; j >= 0; --j )
198 int index = toDelete[j];
199 qgsConnectionPool_ConnectionDestroy(
conns[index].
c );
200 conns.remove( index );
203 if (
conns.isEmpty() )
235 template <
typename T,
typename T_Group>
245 Q_FOREACH ( T_Group* group, mGroups )
259 if ( it == mGroups.end() )
261 it = mGroups.insert( connInfo,
new T_Group( connInfo ) );
263 T_Group* group = *it;
266 return group->acquire();
273 typename T_Groups::iterator it = mGroups.find( qgsConnectionPool_ConnectionToName( conn ) );
274 Q_ASSERT( it != mGroups.end() );
275 T_Group* group = *it;
278 group->release( conn );
289 if ( mGroups.contains( connInfo ) )
301 #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()