From fe9caad391ea0c839fe551525228d310461b2a84 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 3 Mar 2013 23:03:09 +0000 Subject: [PATCH] Max catalog age configurable per-catalog. Allows for short-validity catalogs for development use. --- simgear/package/Catalog.cxx | 6 ++++++ simgear/package/Catalog.hxx | 6 ++++++ simgear/package/Root.cxx | 9 +++++++-- simgear/package/Root.hxx | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index 67b4eb19..eede6066 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -290,6 +290,12 @@ unsigned int Catalog::ageInSeconds() const return (diff < 0) ? 0 : diff; } +bool Catalog::needsRefresh() const +{ + unsigned int maxAge = m_props->getIntValue("max-age-sec", m_root->maxAgeSeconds()); + return (ageInSeconds() > maxAge); +} + std::string Catalog::getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const { if (aRoot->hasChild(m_root->getLocale())) { diff --git a/simgear/package/Catalog.hxx b/simgear/package/Catalog.hxx index bd561a44..3ea3d846 100644 --- a/simgear/package/Catalog.hxx +++ b/simgear/package/Catalog.hxx @@ -83,6 +83,12 @@ public: Package* getPackageById(const std::string& aId) const; + /** + * test if the catalog data was retrieved longer ago than the + * maximum permitted age for this catalog. + */ + bool needsRefresh() const; + unsigned int ageInSeconds() const; /** diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index 75eef3bb..d5f275d1 100644 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -68,10 +68,15 @@ SGPath Root::path() const return d->path; } -void Root::setMaxAgeSeconds(int seconds) +void Root::setMaxAgeSeconds(unsigned int seconds) { d->maxAgeSeconds = seconds; } + +unsigned int Root::maxAgeSeconds() const +{ + return d->maxAgeSeconds; +} void Root::setHTTPClient(HTTP::Client* aHTTP) { @@ -207,7 +212,7 @@ void Root::refresh(bool aForce) { CatalogDict::iterator it = d->catalogs.begin(); for (; it != d->catalogs.end(); ++it) { - if (aForce || (it->second->ageInSeconds() > d->maxAgeSeconds)) { + if (aForce || it->second->needsRefresh()) { it->second->refresh(); } } diff --git a/simgear/package/Root.hxx b/simgear/package/Root.hxx index cc38df77..17665109 100644 --- a/simgear/package/Root.hxx +++ b/simgear/package/Root.hxx @@ -61,8 +61,9 @@ public: CatalogList catalogs() const; - void setMaxAgeSeconds(int seconds); - + void setMaxAgeSeconds(unsigned int seconds); + unsigned int maxAgeSeconds() const; + void setHTTPClient(HTTP::Client* aHTTP); /** -- 2.39.5