X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2FNavDataCache.cxx;h=f6756613bd6c19130d5c308b44c36282add9852f;hb=5c659b3970e9a4542519e0d528016c08f7ecb6c1;hp=dd6ea80e8432939e619a3192e6edb66baceeefc7;hpb=c00ab21fada99442db931b6f8bcaf1faf17cd365;p=flightgear.git diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index dd6ea80e8..f6756613b 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -300,6 +300,8 @@ public: SG_LOG(SG_NAVCACHE, SG_INFO, "NavDataCache integrity check took:" << st.elapsedMSec()); finalize(stmt); } + + bool isCachedFileModified(const SGPath& path, bool verbose); void callSqlite(int result, const string& sql) { @@ -939,7 +941,7 @@ public: std::auto_ptr rebuilder; }; - ////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// FGPositioned* NavDataCache::NavDataCachePrivate::loadById(sqlite3_int64 rowid, sqlite3_int64& aptId) @@ -1022,7 +1024,37 @@ FGPositioned* NavDataCache::NavDataCachePrivate::loadById(sqlite3_int64 rowid, return NULL; } } - + +bool NavDataCache::NavDataCachePrivate::isCachedFileModified(const SGPath& path, bool verbose) +{ + if (!path.exists()) { + throw sg_io_exception("isCachedFileModified: Missing file:" + path.str()); + } + + sqlite_bind_temp_stdstring(statCacheCheck, 1, path.str()); + bool isModified = true; + sgDebugPriority logLevel = verbose ? SG_WARN : SG_DEBUG; + if (execSelect(statCacheCheck)) { + time_t modtime = sqlite3_column_int64(statCacheCheck, 0); + time_t delta = std::labs(modtime - path.modTime()); + if (delta != 0) + { + SG_LOG(SG_NAVCACHE, logLevel, "NavCache: rebuild required for " << path << + ". Timestamps: " << modtime << " != " << path.modTime()); + } + else + { + SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: no rebuild required for " << path); + } + + isModified = (delta != 0); + } else { + SG_LOG(SG_NAVCACHE, logLevel, "NavCache: initial build required for " << path); + } + + reset(statCacheCheck); + return isModified; +} static NavDataCache* static_instance = NULL; @@ -1114,31 +1146,40 @@ bool NavDataCache::isRebuildRequired() return true; } - if (isCachedFileModified(d->aptDatPath) || - isCachedFileModified(d->metarDatPath) || - isCachedFileModified(d->navDatPath) || - isCachedFileModified(d->carrierDatPath) || - isCachedFileModified(d->fixDatPath) || + if (d->isCachedFileModified(d->aptDatPath, true) || + d->isCachedFileModified(d->metarDatPath, true) || + d->isCachedFileModified(d->navDatPath, true) || + d->isCachedFileModified(d->fixDatPath, true) || + d->isCachedFileModified(d->carrierDatPath, true) || // since POI loading is disabled on Windows, don't check for it // this caused: https://code.google.com/p/flightgear-bugs/issues/detail?id=1227 #ifndef SG_WINDOWS - isCachedFileModified(d->poiDatPath) || + d->isCachedFileModified(d->poiDatPath, true) || #endif - isCachedFileModified(d->airwayDatPath)) + d->isCachedFileModified(d->airwayDatPath, true)) { SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: main cache rebuild required"); return true; } - string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";"); - if (readStringProperty("scenery_paths") != sceneryPaths) { - SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: scenery paths changed, main cache rebuild required"); - return true; - } - + dropGroundnetsIfRequired(); + SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: no main cache rebuild required"); return false; } + +bool NavDataCache::dropGroundnetsIfRequired() +{ + string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";"); + if (readStringProperty("scenery_paths") != sceneryPaths) { + SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: scenery paths changed, dropping ground nets"); + dropAllGroundnets(); + writeStringProperty("scenery_paths", sceneryPaths); + return true; + } + + return false; +} bool NavDataCache::rebuild() { @@ -1329,32 +1370,7 @@ void NavDataCache::writeStringListProperty(const string& key, const string_list& bool NavDataCache::isCachedFileModified(const SGPath& path) const { - if (!path.exists()) { - throw sg_io_exception("isCachedFileModified: Missing file:" + path.str()); - } - - sqlite_bind_temp_stdstring(d->statCacheCheck, 1, path.str()); - bool isModified = true; - - if (d->execSelect(d->statCacheCheck)) { - time_t modtime = sqlite3_column_int64(d->statCacheCheck, 0); - time_t delta = std::labs(modtime - path.modTime()); - if (delta != 0) - { - SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: rebuild required for " << path << ". Timestamps: " << modtime << " != " << path.modTime()); - } - else - { - SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: no rebuild required for " << path); - } - - isModified = (delta != 0); - } else { - SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: initial build required for " << path); - } - - d->reset(d->statCacheCheck); - return isModified; + return d->isCachedFileModified(path, false); } void NavDataCache::stampCacheFile(const SGPath& path) @@ -1445,7 +1461,7 @@ FGPositionedRef NavDataCache::loadById(PositionedID rowid) return it->second; // cache it } - PositionedID aptId; + sqlite3_int64 aptId; FGPositioned* pos = d->loadById(rowid, aptId); d->cache.insert(it, PositionedCache::value_type(rowid, pos)); d->cacheMisses++; @@ -1742,13 +1758,13 @@ char** NavDataCache::searchAirportNamesAndIdents(const std::string& aFilter) { sqlite3_stmt_ptr stmt; unsigned int numMatches = 0, numAllocated = 16; + string searchTerm("%" + aFilter + "%"); if (aFilter.empty()) { stmt = d->getAllAirports; numAllocated = 4096; // start much larger for all airports } else { stmt = d->searchAirports; - string s = "%" + aFilter + "%"; - sqlite_bind_stdstring(stmt, 1, s); + sqlite_bind_stdstring(stmt, 1, searchTerm); } char** result = (char**) malloc(sizeof(char*) * numAllocated); @@ -1908,7 +1924,7 @@ NavDataCache::findAirportRunway(const std::string& aName) AirportRunwayPair result; sqlite_bind_stdstring(d->findAirportRunway, 1, parts[0]); - sqlite_bind_stdstring(d->findAirportRunway, 2, parts[1]); + sqlite_bind_stdstring(d->findAirportRunway, 2, cleanRunwayNo(parts[1])); if (d->execSelect(d->findAirportRunway)) { result = AirportRunwayPair(sqlite3_column_int64(d->findAirportRunway, 0), @@ -1923,8 +1939,10 @@ NavDataCache::findAirportRunway(const std::string& aName) } PositionedID -NavDataCache::findILS(PositionedID airport, const string& runway, const string& navIdent) +NavDataCache::findILS(PositionedID airport, const string& aRunway, const string& navIdent) { + string runway(cleanRunwayNo(aRunway)); + sqlite_bind_stdstring(d->findILS, 1, navIdent); sqlite3_bind_int64(d->findILS, 2, airport); sqlite_bind_stdstring(d->findILS, 3, runway); @@ -2151,6 +2169,21 @@ void NavDataCache::dropGroundnetFor(PositionedID aAirport) sqlite3_bind_int64(q, 1, aAirport); d->execUpdate(q); } + +void NavDataCache::dropAllGroundnets() +{ + SG_LOG(SG_NAVCACHE, SG_INFO, "dropping ground-net data"); + beginTransaction(); + d->runSQL("DELETE FROM groundnet_edge"); + d->runSQL("DELETE FROM parking"); + d->runSQL("DELETE FROM taxi_node"); + + sqlite3_stmt_ptr q = d->prepare("DELETE FROM positioned WHERE (type=?1 OR type=?2)"); + sqlite3_bind_int(q, 1, FGPositioned::TAXI_NODE); + sqlite3_bind_int(q, 2, FGPositioned::PARKING); + d->execUpdate(q); + commitTransaction(); +} bool NavDataCache::isReadOnly() const {