From 3bfd0c872a7807c2a648e4435047fed4a52e555b Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 27 Sep 2015 23:14:50 -0500 Subject: [PATCH] Avoid duplicate refresh of Catalogs - also fix duplicate reporting of successful refresh --- simgear/package/Catalog.cxx | 21 ++++++++++++--------- simgear/package/Catalog.hxx | 2 ++ simgear/package/Root.cxx | 1 - 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index 1a810af8..87e2a392 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -78,7 +78,6 @@ public: { // refreshing m_owner->changeStatus(Delegate::STATUS_IN_PROGRESS); - SG_LOG(SG_GENERAL, SG_WARN, "downloading " << aUrl); } protected: @@ -177,9 +176,7 @@ CatalogRef Catalog::createFromUrl(Root* aRoot, const std::string& aUrl) { CatalogRef c = new Catalog(aRoot); c->m_url = aUrl; - Downloader* dl = new Downloader(c, aUrl); - aRoot->makeHTTPRequest(dl); - + c->refresh(); return c; } @@ -219,9 +216,12 @@ CatalogRef Catalog::createFromPath(Root* aRoot, const SGPath& aPath) CatalogRef c = new Catalog(aRoot); c->m_installRoot = aPath; - c->parseProps(props); // will set status + c->parseProps(props); c->parseTimestamp(); + // parsed XML ok, mark status as valid + c->changeStatus(Delegate::STATUS_SUCCESS); + return c; } @@ -300,7 +300,13 @@ Catalog::installedPackages() const void Catalog::refresh() { + if (m_refreshRequest.valid()) { + // refresh in progress + return; + } + Downloader* dl = new Downloader(this, url()); + m_refreshRequest = dl; // will update status to IN_PROGRESS m_root->makeHTTPRequest(dl); } @@ -387,9 +393,6 @@ void Catalog::parseProps(const SGPropertyNode* aProps) Dir d(m_installRoot); d.create(0755); } - - // parsed XML ok, mark status as valid - changeStatus(Delegate::STATUS_SUCCESS); } PackageRef Catalog::getPackageById(const std::string& aId) const @@ -483,8 +486,8 @@ std::string Catalog::getLocalisedString(const SGPropertyNode* aRoot, const char* void Catalog::refreshComplete(Delegate::StatusCode aReason) { - m_root->catalogRefreshStatus(this, aReason); changeStatus(aReason); + m_refreshRequest.reset(); } void Catalog::changeStatus(Delegate::StatusCode newStatus) diff --git a/simgear/package/Catalog.hxx b/simgear/package/Catalog.hxx index 65e3f992..0113e9f8 100644 --- a/simgear/package/Catalog.hxx +++ b/simgear/package/Catalog.hxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -157,6 +158,7 @@ private: SGPath m_installRoot; std::string m_url; Delegate::StatusCode m_status; + HTTP::Request_ptr m_refreshRequest; PackageList m_packages; time_t m_retrievedTime; diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index 2fca504f..8d3b52a8 100644 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -111,7 +111,6 @@ public: Delegate::StatusCode status, const std::string& bytes) { std::string u(request->url()); - SG_LOG(SG_IO, SG_INFO, "downloaded thumbnail:" << u); if (status == Delegate::STATUS_SUCCESS) { thumbnailCache[u] = bytes; fireDataForThumbnail(u, bytes); -- 2.39.5