1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP37/GCS MapLib - Fixes small bug on the SQL caching

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2638 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2011-01-31 17:22:49 +00:00 committed by zedamota
parent 57c7633476
commit 94c1f9793d
2 changed files with 491 additions and 491 deletions

View File

@ -29,26 +29,61 @@
//#define DEBUG_PUREIMAGECACHE
namespace core {
qlonglong PureImageCache::ConnCounter=0;
qlonglong PureImageCache::ConnCounter=0;
PureImageCache::PureImageCache()
{
PureImageCache::PureImageCache()
{
gtilecache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator();
}
QDir d;
if(!d.exists(gtilecache))
{
d.mkdir(gtilecache);
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create Cache directory";
#endif //DEBUG_PUREIMAGECACHE
}
{
QString db=gtilecache+"Data.qmdb";
if(!QFileInfo(db).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
CreateEmptyDB(db);
}
}
}
void PureImageCache::setGtileCache(const QString &value)
{
void PureImageCache::setGtileCache(const QString &value)
{
gtilecache=value;
}
QString PureImageCache::GtileCache()
{
QDir d;
if(!d.exists(gtilecache))
{
d.mkdir(gtilecache);
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create Cache directory";
#endif //DEBUG_PUREIMAGECACHE
}
{
QString db=gtilecache+"Data.qmdb";
if(!QFileInfo(db).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
CreateEmptyDB(db);
}
}
}
QString PureImageCache::GtileCache()
{
return gtilecache;
}
}
bool PureImageCache::CreateEmptyDB(const QString &file)
{
bool PureImageCache::CreateEmptyDB(const QString &file)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create database at!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:"<<file;
#endif //DEBUG_PUREIMAGECACHE
@ -56,7 +91,8 @@ bool PureImageCache::CreateEmptyDB(const QString &file)
QDir dir=File.absoluteDir();
QString path=dir.absolutePath();
QString filename=File.fileName();
if(File.exists()) QFile(filename).remove();
if(File.exists())
QFile(filename).remove();
if(!dir.exists())
{
#ifdef DEBUG_PUREIMAGECACHE
@ -148,44 +184,19 @@ bool PureImageCache::CreateEmptyDB(const QString &file)
db.close();
QSqlDatabase::removeDatabase(QLatin1String("CreateConn"));
return true;
}
bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Types &type,const Point &pos,const int &zoom)
{
}
bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Types &type,const Point &pos,const int &zoom)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"PutImageToCache Start:";//<<pos;
#endif //DEBUG_PUREIMAGECACHE
bool ret=true;
QDir d;
QString dir=gtilecache;
Mcounter.lock();
qlonglong id=++ConnCounter;
Mcounter.unlock();
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"PutImageToCache Cache dir="<<dir;
qDebug()<<"PutImageToCache Cache dir="<<dir<<" Try to PUT:"<<pos.ToString();
#endif //DEBUG_PUREIMAGECACHE
if(!d.exists(dir))
{
d.mkdir(dir);
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create Cache directory";
#endif //DEBUG_PUREIMAGECACHE
}
{
QString db=dir+"Data.qmdb";
if(!QFileInfo(db).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
ret=CreateEmptyDB(db);
}
if(ret)
{
QSqlDatabase cn;
cn = QSqlDatabase::addDatabase("QSQLITE",QString::number(id));
QString db=gtilecache+"Data.qmdb";
cn.setDatabaseName(db);
if(cn.open())
{
@ -207,23 +218,13 @@ bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Type
query.exec();
}
cn.close();
}
else return false;
}
else
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"PutImageToCache Could not create DB";
#endif //DEBUG_PUREIMAGECACHE
return false;
}
}
QSqlDatabase::removeDatabase(QString::number(id));
return true;
}
QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom)
{
}
QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom)
{
bool ret=true;
QByteArray ar;
QString dir=gtilecache;
@ -264,13 +265,12 @@ QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int
}
QSqlDatabase::removeDatabase(QString::number(id));
return ar;
}
void PureImageCache::deleteOlderTiles(int const& days)
{
}
void PureImageCache::deleteOlderTiles(int const& days)
{
QList<long> add;
bool ret=true;
QString dir=gtilecache;
{
QString db=dir+"Data.qmdb";
ret=QFileInfo(db).exists();
@ -303,10 +303,10 @@ void PureImageCache::deleteOlderTiles(int const& days)
QSqlDatabase::removeDatabase(QString::number(id));
}
}
}
// PureImageCache::ExportMapDataToDB("C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data.qmdb","C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data2.qmdb");
bool PureImageCache::ExportMapDataToDB(QString sourceFile, QString destFile)
{
}
// PureImageCache::ExportMapDataToDB("C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data.qmdb","C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data2.qmdb");
bool PureImageCache::ExportMapDataToDB(QString sourceFile, QString destFile)
{
bool ret=true;
QList<long> add;
if(!QFileInfo(destFile).exists())
@ -358,6 +358,6 @@ bool PureImageCache::ExportMapDataToDB(QString sourceFile, QString destFile)
QSqlDatabase::removeDatabase("cb");
return true;
}
}
}

View File

@ -57,7 +57,7 @@ void TileCacheQueue::EnqueueCacheTask(CacheItemQueue *task)
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Wake Thread";
#endif //DEBUG_TILECACHEQUEUE
this->start(QThread::NormalPriority);
//this->start(QThread::NormalPriority);
//waitmutex.lock();
waitc.wakeAll();
//waitmutex.unlock();