|
| 1 | +/*************************************************************************** |
| 2 | + qgsogrconnpool.h |
| 3 | + --------------------- |
| 4 | + begin : May 2015 |
| 5 | + copyright : (C) 2015 by Sandro Mani |
| 6 | + email : smani at sourcepole dot ch |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#ifndef QGSOGRCONNPOOL_H |
| 17 | +#define QGSOGRCONNPOOL_H |
| 18 | + |
| 19 | +#include "qgsconnectionpool.h" |
| 20 | +#include <ogr_api.h> |
| 21 | + |
| 22 | + |
| 23 | +struct QgsOgrConn |
| 24 | +{ |
| 25 | + QString path; |
| 26 | + OGRDataSourceH ds; |
| 27 | +}; |
| 28 | + |
| 29 | +inline QString qgsConnectionPool_ConnectionToName( QgsOgrConn* c ) |
| 30 | +{ |
| 31 | + return c->path; |
| 32 | +} |
| 33 | + |
| 34 | +inline void qgsConnectionPool_ConnectionCreate( QString connInfo, QgsOgrConn*& c ) |
| 35 | +{ |
| 36 | + c = new QgsOgrConn; |
| 37 | + c->ds = OGROpen( connInfo.toUtf8().constData(), false, NULL ); |
| 38 | + c->path = connInfo; |
| 39 | +} |
| 40 | + |
| 41 | +inline void qgsConnectionPool_ConnectionDestroy( QgsOgrConn* c ) |
| 42 | +{ |
| 43 | + OGR_DS_Destroy( c->ds ); |
| 44 | + delete c; |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgrConn*> |
| 49 | +{ |
| 50 | + Q_OBJECT |
| 51 | + |
| 52 | + public: |
| 53 | + QgsOgrConnPoolGroup( QString name ) : QgsConnectionPoolGroup<QgsOgrConn*>( name ) { initTimer( this ); } |
| 54 | + |
| 55 | + protected slots: |
| 56 | + void handleConnectionExpired() { onConnectionExpired(); } |
| 57 | + void startExpirationTimer() { expirationTimer->start(); } |
| 58 | + void stopExpirationTimer() { expirationTimer->stop(); } |
| 59 | + |
| 60 | + protected: |
| 61 | + Q_DISABLE_COPY( QgsOgrConnPoolGroup ) |
| 62 | + |
| 63 | +}; |
| 64 | + |
| 65 | +/** Ogr connection pool - singleton */ |
| 66 | +class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup> |
| 67 | +{ |
| 68 | + public: |
| 69 | + static QgsOgrConnPool* instance(); |
| 70 | + |
| 71 | + protected: |
| 72 | + Q_DISABLE_COPY( QgsOgrConnPool ) |
| 73 | + |
| 74 | + private: |
| 75 | + QgsOgrConnPool(); |
| 76 | + ~QgsOgrConnPool(); |
| 77 | +}; |
| 78 | + |
| 79 | + |
| 80 | +#endif // QGSOGRCONNPOOL_H |
0 commit comments