Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add connection pool for OGR provider
- Loading branch information
1 parent
5910adf
commit a64ffc4
Showing
5 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.cpp | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsogrconnpool.h" | ||
|
||
|
||
QgsOgrConnPool* QgsOgrConnPool::instance() | ||
{ | ||
static QgsOgrConnPool sInstance; | ||
return &sInstance; | ||
} | ||
|
||
QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup>() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
QgsOgrConnPool::~QgsOgrConnPool() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.h | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSOGRCONNPOOL_H | ||
#define QGSOGRCONNPOOL_H | ||
|
||
#include "qgsconnectionpool.h" | ||
#include <ogr_api.h> | ||
|
||
|
||
struct QgsOgrConn | ||
{ | ||
QString path; | ||
OGRDataSourceH ds; | ||
}; | ||
|
||
inline QString qgsConnectionPool_ConnectionToName( QgsOgrConn* c ) | ||
{ | ||
return c->path; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionCreate( QString connInfo, QgsOgrConn*& c ) | ||
{ | ||
c = new QgsOgrConn; | ||
c->ds = OGROpen( connInfo.toUtf8().constData(), false, NULL ); | ||
c->path = connInfo; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionDestroy( QgsOgrConn* c ) | ||
{ | ||
OGR_DS_Destroy( c->ds ); | ||
delete c; | ||
} | ||
|
||
|
||
class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgrConn*> | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsOgrConnPoolGroup( QString name ) : QgsConnectionPoolGroup<QgsOgrConn*>( name ) { initTimer( this ); } | ||
|
||
protected slots: | ||
void handleConnectionExpired() { onConnectionExpired(); } | ||
void startExpirationTimer() { expirationTimer->start(); } | ||
void stopExpirationTimer() { expirationTimer->stop(); } | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPoolGroup ) | ||
|
||
}; | ||
|
||
/** Ogr connection pool - singleton */ | ||
class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup> | ||
{ | ||
public: | ||
static QgsOgrConnPool* instance(); | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPool ) | ||
|
||
private: | ||
QgsOgrConnPool(); | ||
~QgsOgrConnPool(); | ||
}; | ||
|
||
|
||
#endif // QGSOGRCONNPOOL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters