]> git.mxchange.org Git - simgear.git/commitdiff
Avoid duplicate refresh of Catalogs
authorJames Turner <zakalawe@mac.com>
Mon, 28 Sep 2015 04:14:50 +0000 (23:14 -0500)
committerJames Turner <zakalawe@mac.com>
Mon, 28 Sep 2015 04:14:50 +0000 (23:14 -0500)
- also fix duplicate reporting of successful refresh

simgear/package/Catalog.cxx
simgear/package/Catalog.hxx
simgear/package/Root.cxx

index 1a810af8a7c00b76782b5728e0363e7c1a7c498d..87e2a3921369391c5dde2d082fe1c7b42bd3a2d3 100644 (file)
@@ -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)
index 65e3f992ec06d544d7b66d7382b10a144a6de08c..0113e9f849256e686b46902477e6c02fc285a96c 100644 (file)
@@ -30,6 +30,7 @@
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/structure/function_list.hxx>
+#include <simgear/io/HTTPRequest.hxx>
 
 #include <simgear/package/Delegate.hxx>
 
@@ -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;
index 2fca504fdc380a7a41428217527562b3fbc1666a..8d3b52a86a8b8ec9f8f26234597b2ccfa66787f1 100644 (file)
@@ -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);