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
76 qgsConnectionPool_ConnectionDestroy( item.
c );
89 if ( !
conns.isEmpty() )
92 if ( !qgsConnectionPool_ConnectionIsValid( i.
c ) )
94 qgsConnectionPool_ConnectionDestroy( i.
c );
95 qgsConnectionPool_ConnectionCreate(
connInfo, i.
c );
99 if (
conns.isEmpty() )
112 qgsConnectionPool_ConnectionCreate(
connInfo, c );
151 qgsConnectionPool_InvalidateConnection( i.
c );
154 qgsConnectionPool_InvalidateConnection( c );
179 for (
int i = 0; i <
conns.count(); ++i )
186 for (
int j = toDelete.
count() - 1; j >= 0; --j )
188 int index = toDelete[j];
189 qgsConnectionPool_ConnectionDestroy(
conns[index].c );
190 conns.remove( index );
193 if (
conns.isEmpty() )
225 template <
typename T,
typename T_Group>
235 Q_FOREACH ( T_Group* group,
mGroups )
248 typename T_Groups::iterator it =
mGroups.
find( connInfo );
253 T_Group* group = *it;
256 return group->acquire();
263 typename T_Groups::iterator it =
mGroups.
find( qgsConnectionPool_ConnectionToName( conn ) );
265 T_Group* group = *it;
268 group->release( conn );
291 #endif // QGSCONNECTIONPOOL_H
void setInterval(int msec)
#define CONN_POOL_MAX_CONCURRENT_CONNS
virtual ~QgsConnectionPool()
bool contains(const Key &key) const
#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
iterator insert(const Key &key, const T &value)
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)
iterator find(const Key &key)
void invalidateConnections()