1
0
Fork 0

Add public method to get the list of apt.dat files used by the NavCache

- The 'DatFilesGroupInfo' struct and 'DatFileType' enum are now public
  members of 'NavDataCache'.

- New public method NavDataCache::getDatFilesInfo() returning the
  'DatFilesGroupInfo' struct for a given type of dat files. For
  instance, this allows one to retrieve the ordered list of apt.dat
  files the NavCache would use if it were rebuilt at that time, as well
  as their total size.
This commit is contained in:
Florent Rougon 2016-11-01 01:27:17 +01:00
parent fc81258d13
commit 1b0a76943f
2 changed files with 50 additions and 30 deletions

View file

@ -235,12 +235,6 @@ public:
}
};
struct DatFilesGroupInfo {
NavDataCache::DatFileType datFileType; // for instance, DATFILETYPE_APT
PathList paths; // SGPath instances
std::size_t totalSize; // total size of all these files, in bytes
};
class NavDataCache::NavDataCachePrivate
{
public:
@ -340,10 +334,11 @@ public:
}
bool isCachedFileModified(const SGPath& path, bool verbose);
DatFilesGroupInfo findDatFiles(NavDataCache::DatFileType datFileType)
const;
bool areDatFilesModified(const DatFilesGroupInfo& datFilesGroupInfo,
bool verbose);
NavDataCache::DatFilesGroupInfo findDatFiles(
NavDataCache::DatFileType datFileType) const;
bool areDatFilesModified(
const NavDataCache::DatFilesGroupInfo& datFilesGroupInfo,
bool verbose);
void callSqlite(int result, const string& sql)
{
@ -860,7 +855,7 @@ public:
bool transactionAborted;
sqlite3_stmt_ptr beginTransactionStmt, commitTransactionStmt, rollbackTransactionStmt;
DatFilesGroupInfo aptDatFilesInfo;
NavDataCache::DatFilesGroupInfo aptDatFilesInfo;
SGPath metarDatPath, navDatPath, fixDatPath, poiDatPath,
carrierDatPath, airwayDatPath;
@ -1027,10 +1022,10 @@ bool NavDataCache::NavDataCachePrivate::isCachedFileModified(const SGPath& path,
// $FG_ROOT/Airports/apt.dat.gz for the 'apt' type).
// Also compute the total size of all these files (in bytes), which is useful
// for progress information.
DatFilesGroupInfo NavDataCache::NavDataCachePrivate::findDatFiles(
NavDataCache::DatFilesGroupInfo NavDataCache::NavDataCachePrivate::findDatFiles(
NavDataCache::DatFileType datFileType) const
{
DatFilesGroupInfo result;
NavDataCache::DatFilesGroupInfo result;
SGPath visitedPath; // to avoid duplicates and time wasting
const string datFilesSubDir = "NavData/" +
NavDataCache::datTypeStr[datFileType];
@ -1093,7 +1088,7 @@ DatFilesGroupInfo NavDataCache::NavDataCachePrivate::findDatFiles(
// This comparison is sensitive to the number and order of the files,
// their respective SGPath::realpath() and SGPath::modTime().
bool NavDataCache::NavDataCachePrivate::areDatFilesModified(
const DatFilesGroupInfo& datFilesGroupInfo,
const NavDataCache::DatFilesGroupInfo& datFilesGroupInfo,
bool verbose)
{
// 'apt' or 'metar' or 'fix' or...
@ -1280,6 +1275,22 @@ void NavDataCache::updateListsOfDatFiles() {
d->airwayDatPath.append("Navaids/awy.dat.gz");
}
NavDataCache::DatFilesGroupInfo
NavDataCache::getDatFilesInfo(DatFileType datFileType) const
{
switch (datFileType) {
case DATFILETYPE_APT:
return d->aptDatFilesInfo;
default:
SG_LOG(SG_NAVCACHE, SG_ALERT,
"NavCache: requesting info about the list of " <<
datTypeStr[datFileType] << " dat files, however this is not "
"implemented yet!");
assert(false);
return DatFilesGroupInfo();
}
}
bool NavDataCache::isRebuildRequired()
{
if (d->readOnly) {

View file

@ -25,9 +25,11 @@
#define FG_NAVDATACACHE_HXX
#include <memory>
#include <cstddef> // for std::size_t
#include <simgear/misc/strutils.hxx> // for string_list
#include <Navaids/positioned.hxx>
#include <Main/globals.hxx> // for PathList
class SGPath;
class FGRunway;
@ -63,10 +65,30 @@ public:
SGPath path() const;
// Update d->aptDatPaths, d->metarDatPath, d->navDatPath, d->fixDatPath,
// d->poiDatPath, etc. by looking into $scenery_path/NavData for each
// scenery path.
enum DatFileType {
DATFILETYPE_APT = 0,
DATFILETYPE_METAR,
DATFILETYPE_AWY,
DATFILETYPE_NAV,
DATFILETYPE_FIX,
DATFILETYPE_POI,
DATFILETYPE_CARRIER,
DATFILETYPE_TACAN_FREQ
};
struct DatFilesGroupInfo {
DatFileType datFileType; // for instance, DATFILETYPE_APT
PathList paths; // SGPath instances
std::size_t totalSize; // total size of all these files, in bytes
};
// Update d->aptDatFilesInfo, d->metarDatPath, d->navDatPath,
// d->fixDatPath, d->poiDatPath, etc. by looking into
// $scenery_path/NavData for each scenery path.
void updateListsOfDatFiles();
// Return d->aptDatFilesInfo if datFileType == DATFILETYPE_APT, etc.
DatFilesGroupInfo getDatFilesInfo(DatFileType datFileType) const;
/**
* predicate - check if the cache needs to be rebuilt.
* This can happen is the cache file is missing or damaged, or one of the
@ -299,19 +321,6 @@ private:
void commitTransaction();
void abortTransaction();
friend class DatFilesGroupInfo;
enum DatFileType {
DATFILETYPE_APT = 0,
DATFILETYPE_METAR,
DATFILETYPE_AWY,
DATFILETYPE_NAV,
DATFILETYPE_FIX,
DATFILETYPE_POI,
DATFILETYPE_CARRIER,
DATFILETYPE_TACAN_FREQ
};
// datTypeStr[DATFILETYPE_APT] = std::string("apt"), etc. This gives, among
// other things, the subdirectory of $scenery_path/NavData where each type
// of dat file is looked for.