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

OP-37 GCS/MapPlugin cleaning and bug hunting

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@705 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-06-02 20:26:48 +00:00 committed by zedamota
parent f31cd81a8d
commit 570bbb4353
11 changed files with 242 additions and 220 deletions

View File

@ -28,7 +28,8 @@
#ifndef ACCESSMODE_H
#define ACCESSMODE_H
#include "debugheader.h"
namespace core {
struct AccessMode
{

View File

@ -29,7 +29,7 @@
#define CACHE_H
#include "pureimagecache.h"
#include "debugheader.h"
namespace core {
class Cache

View File

@ -33,4 +33,5 @@ HEADERS += opmaps.h \
geodecoderstatus.h \
placemark.h \
point.h \
kibertilecache.h
kibertilecache.h \
debugheader.h

View File

@ -0,0 +1,13 @@
#ifndef DEBUGHEADER_H
#define DEBUGHEADER_H
//#define DEBUG_MEMORY_CACHE
//#define DEBUG_CACHE
//#define DEBUG_GMAPS
//#define DEBUG_PUREIMAGECACHE
//#define DEBUG_TILECACHEQUEUE
//#define DEBUG_URLFACTORY
//#define DEBUG_MEMORY_CACHE
//#define DEBUG_GetGeocoderFromCache
#endif // DEBUGHEADER_H

View File

@ -51,14 +51,20 @@ int KiberTileCache::MemoryCacheCapacity()
void KiberTileCache::RemoveMemoryOverload()
{
while(memoryCacheSize>MemoryCacheCapacity())
while(MemoryCacheSize()>MemoryCacheCapacity())
{
if(cachequeue.count()>0 && list.count()>0)
{
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Cleaning Memory cache="<<" started with "<<cachequeue.count()<<" tile "<<"ocupying "<<memoryCacheSize<<" bytes";
#endif
RawTile first=list.dequeue();
memoryCacheSize-=cachequeue.value(first).length();
memoryCacheSize-=cachequeue.value(first).size();
cachequeue.remove(first);
}
}
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Cleaning Memory cache="<<" ended with "<<cachequeue.count()<<" tile "<<"ocupying "<<memoryCacheSize<<" bytes";
#endif
}
}

View File

@ -28,13 +28,12 @@
#ifndef KIBERTILECACHE_H
#define KIBERTILECACHE_H
#include <QPixmapCache>
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include <QDebug>
#include "debugheader.h"
namespace core {
class KiberTileCache
{
@ -52,9 +51,6 @@ public:
private:
int _MemoryCacheCapacity;
// QPixmapCache TilesInMemory;
};

View File

@ -48,7 +48,10 @@ void MemoryCache::AddTileToMemoryCache(const RawTile &tile, const QByteArray &pi
{
kiberCacheLock.lockForWrite();
// QPixmapCache::Key key=TilesInMemory.insert(pic);
TilesInMemory.memoryCacheSize +=pic.count();
TilesInMemory.memoryCacheSize +=pic.size();
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Current memory="<<TilesInMemory.memoryCacheSize<<" in "<<TilesInMemory.cachequeue.count()<<" tiles";
#endif
TilesInMemory.cachequeue.insert(tile,pic);
TilesInMemory.list.enqueue(tile);

View File

@ -28,13 +28,13 @@
#ifndef MEMORYCACHE_H
#define MEMORYCACHE_H
#include <QPixmapCache>
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include "kibertilecache.h"
#include <QDebug>
#include "debugheader.h"
namespace core {
class MemoryCache
{
@ -45,7 +45,6 @@ public:
QByteArray GetTileFromMemoryCache(const RawTile &tile);
void AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic);
QReadWriteLock kiberCacheLock;
};

View File

@ -27,220 +27,233 @@
*/
#include "opmaps.h"
namespace core {
OPMaps* OPMaps::m_pInstance=0;
OPMaps* OPMaps::m_pInstance=0;
OPMaps* OPMaps::Instance()
{
if(!m_pInstance)
m_pInstance=new OPMaps;
return m_pInstance;
}
OPMaps::OPMaps():useMemoryCache(true),MaxZoom(19),RetryLoadTile(2)
{
accessmode=AccessMode::ServerAndCache;
Language=LanguageType::PortuguesePortugal;
LanguageStr=LanguageType().toString(Language);
// Cache::Instance()->ImageCache=PureImageCache();
}
OPMaps::~OPMaps()
{
//delete Proxy;
}
QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
QByteArray ret;
if(useMemoryCache)
OPMaps* OPMaps::Instance()
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
#endif //DEBUG_GMAPS
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
if(!m_pInstance)
m_pInstance=new OPMaps;
return m_pInstance;
}
OPMaps::OPMaps():useMemoryCache(true),MaxZoom(19),RetryLoadTile(2)
{
accessmode=AccessMode::ServerAndCache;
Language=LanguageType::PortuguesePortugal;
LanguageStr=LanguageType().toString(Language);
// Cache::Instance()->ImageCache=PureImageCache();
}
if(ret.isEmpty())
OPMaps::~OPMaps()
{
//delete Proxy;
}
QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom)
{
#ifdef DEBUG_TIMINGS
QTime time;
time.restart();
#endif
#ifdef DEBUG_GMAPS
qDebug()<<"Tile not in memory";
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
if(accessmode != (AccessMode::ServerOnly))
QByteArray ret;
if(useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try tile from DataBase";
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
#endif //DEBUG_GMAPS
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
if(!ret.isEmpty())
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
}
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Tile not in memory";
#endif //DEBUG_GMAPS
if(accessmode != (AccessMode::ServerOnly))
{
#ifdef DEBUG_GMAPS
qDebug()<<"Tile found in Database";
qDebug()<<"Try tile from DataBase";
#endif //DEBUG_GMAPS
if(useMemoryCache)
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
if(!ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory";
qDebug()<<"Tile found in Database";
#endif //DEBUG_GMAPS
if(useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory";
#endif //DEBUG_GMAPS
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
}
return ret;
}
}
if(accessmode!=AccessMode::CacheOnly)
{
QNetworkReply *reply;
QNetworkRequest qheader;
QNetworkAccessManager network;
network.setProxy(Proxy);
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from the Internet";
#endif //DEBUG_GMAPS
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps before make image url"<<time.elapsed();
#endif
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps after make image url"<<time.elapsed();
#endif
qheader.setUrl(QUrl(url));
qheader.setRawHeader("User-Agent",UserAgent);
qheader.setRawHeader("Accept","*/*");
switch(type)
{
case MapType::GoogleMap:
case MapType::GoogleSatellite:
case MapType::GoogleLabels:
case MapType::GoogleTerrain:
case MapType::GoogleHybrid:
{
qheader.setRawHeader("Referrer", "http://maps.google.com/");
}
break;
case MapType::GoogleMapChina:
case MapType::GoogleSatelliteChina:
case MapType::GoogleLabelsChina:
case MapType::GoogleTerrainChina:
case MapType::GoogleHybridChina:
{
qheader.setRawHeader("Referrer", "http://ditu.google.cn/");
}
break;
case MapType::BingHybrid:
case MapType::BingMap:
case MapType::BingSatellite:
{
qheader.setRawHeader("Referrer", "http://www.bing.com/maps/");
}
break;
case MapType::YahooHybrid:
case MapType::YahooLabels:
case MapType::YahooMap:
case MapType::YahooSatellite:
{
qheader.setRawHeader("Referrer", "http://maps.yahoo.com/");
}
break;
case MapType::ArcGIS_MapsLT_Map_Labels:
case MapType::ArcGIS_MapsLT_Map:
case MapType::ArcGIS_MapsLT_OrtoFoto:
case MapType::ArcGIS_MapsLT_Map_Hybrid:
{
qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/");
}
break;
case MapType::OpenStreetMapSurfer:
case MapType::OpenStreetMapSurferTerrain:
{
qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/");
}
break;
case MapType::OpenStreetMap:
case MapType::OpenStreetOsm:
{
qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/");
}
break;
case MapType::YandexMapRu:
{
qheader.setRawHeader("Referrer", "http://maps.yandex.ru/");
}
break;
default:
break;
}
reply=network.get(qheader);
#ifdef DEBUG_GMAPS
qDebug()<<"Starting get response ";//<<pos.X()+","+pos.Y();
#endif //DEBUG_GMAPS
QTime time;
time.start();
while( !(reply->isFinished() | time.elapsed()>(6*Timeout)) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
#ifdef DEBUG_TIMINGS
qDebug()<<"Network time:"<<time.elapsed();
#endif
#ifdef DEBUG_GMAPS
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
#endif //DEBUG_GMAPS
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
{
#ifdef DEBUG_GMAPS
qDebug()<<"Request timed out ";//<<pos.x+","+pos.y;
#endif //DEBUG_GMAPS
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Response OK ";//<<pos.x+","+pos.y;
#endif //DEBUG_GMAPS
ret=reply->readAll();
reply->deleteLater();//TODO can't this be global??
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Invalid Tile";
#endif //DEBUG_GMAPS
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Received Tile from the Internet";
#endif //DEBUG_GMAPS
if (useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory cache";
#endif //DEBUG_GMAPS
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
}
return ret;
if(accessmode!=AccessMode::ServerOnly)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add tile to DataBase";
#endif //DEBUG_GMAPS
CacheItemQueue item(type,pos,ret,zoom);
TileDBcacheQueue.EnqueueCacheTask(item);
}
}
}
if(accessmode!=AccessMode::CacheOnly)
{
QNetworkReply *reply;
QNetworkRequest qheader;
QNetworkAccessManager network;
network.setProxy(Proxy);
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from the Internet";
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
qheader.setUrl(QUrl(url));
qheader.setRawHeader("User-Agent",UserAgent);
qheader.setRawHeader("Accept","*/*");
switch(type)
{
case MapType::GoogleMap:
case MapType::GoogleSatellite:
case MapType::GoogleLabels:
case MapType::GoogleTerrain:
case MapType::GoogleHybrid:
{
qheader.setRawHeader("Referrer", "http://maps.google.com/");
}
break;
case MapType::GoogleMapChina:
case MapType::GoogleSatelliteChina:
case MapType::GoogleLabelsChina:
case MapType::GoogleTerrainChina:
case MapType::GoogleHybridChina:
{
qheader.setRawHeader("Referrer", "http://ditu.google.cn/");
}
break;
case MapType::BingHybrid:
case MapType::BingMap:
case MapType::BingSatellite:
{
qheader.setRawHeader("Referrer", "http://www.bing.com/maps/");
}
break;
case MapType::YahooHybrid:
case MapType::YahooLabels:
case MapType::YahooMap:
case MapType::YahooSatellite:
{
qheader.setRawHeader("Referrer", "http://maps.yahoo.com/");
}
break;
case MapType::ArcGIS_MapsLT_Map_Labels:
case MapType::ArcGIS_MapsLT_Map:
case MapType::ArcGIS_MapsLT_OrtoFoto:
case MapType::ArcGIS_MapsLT_Map_Hybrid:
{
qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/");
}
break;
case MapType::OpenStreetMapSurfer:
case MapType::OpenStreetMapSurferTerrain:
{
qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/");
}
break;
case MapType::OpenStreetMap:
case MapType::OpenStreetOsm:
{
qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/");
}
break;
case MapType::YandexMapRu:
{
qheader.setRawHeader("Referrer", "http://maps.yandex.ru/");
}
break;
default:
break;
}
reply=network.get(qheader);
#ifdef DEBUG_GMAPS
qDebug()<<"Starting get response ";//<<pos.X()+","+pos.Y();
#endif //DEBUG_GMAPS
QTime time;
time.start();
while( !(reply->isFinished() | time.elapsed()>(6*Timeout)) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
#ifdef DEBUG_GMAPS
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
#endif //DEBUG_GMAPS
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
{
#ifdef DEBUG_GMAPS
qDebug()<<"Request timed out ";//<<pos.x+","+pos.y;
#endif //DEBUG_GMAPS
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Response OK ";//<<pos.x+","+pos.y;
#endif //DEBUG_GMAPS
ret=reply->readAll();
reply->deleteLater();//TODO can't this be global??
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Invalid Tile";
#endif //DEBUG_GMAPS
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Received Tile from the Internet";
#endif //DEBUG_GMAPS
if (useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory cache";
#endif //DEBUG_GMAPS
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
}
if(accessmode!=AccessMode::ServerOnly)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add tile to DataBase";
#endif //DEBUG_GMAPS
CacheItemQueue item(type,pos,ret,zoom);
TileDBcacheQueue.EnqueueCacheTask(item);
}
}
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
return ret;
}
bool OPMaps::ExportToGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file);
}
bool OPMaps::ImportFromGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb");
}
bool OPMaps::ExportToGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file);
}
bool OPMaps::ImportFromGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb");
}
}

View File

@ -28,12 +28,8 @@
#ifndef OPMaps_H
#define OPMaps_H
//#define DEBUG_CACHE
//#define DEBUG_GMAPS
//#define DEBUG_PUREIMAGECACHE
//#define DEBUG_TILECACHEQUEUE
//#define DEBUG_URLFACTORY
#include "debugheader.h"
#include "memorycache.h"
#include "rawtile.h"
#include "cache.h"
@ -66,22 +62,17 @@ public:
QByteArray GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom);
bool UseMemoryCache();//TODO
void setUseMemoryCache(const bool& value);//TODO
void setUseMemoryCache(const bool& value){useMemoryCache=value;}
void setLanguage(const LanguageType::Types& language);//TODO
LanguageType::Types GetLanguage();//TODO
AccessMode GetAccessMode();
void setAccessMode(const AccessMode& mode);
AccessMode::Types GetAccessMode()const{return accessmode;};
void setAccessMode(const AccessMode::Types& mode){accessmode=mode;};
int MaxZoom;
int RetryLoadTile;
private:
bool useMemoryCache;
LanguageType::Types Language;
AccessMode::Types accessmode;
// PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set
TileCacheQueue TileDBcacheQueue;
OPMaps();

View File

@ -30,7 +30,6 @@
#include <QString>
//#include "size.h"
namespace core {
struct Size;