changeset 468:70b333085952

* complete switching the code to use CachedFile -- now to tidy & fix the remaining flaws...
author Chris Cannam
date Mon, 27 Oct 2008 20:29:55 +0000
parents c9b055f84326
children a8a7b8f698c8
files data/fileio/CachedFile.cpp data/fileio/CachedFile.h data/fileio/FileSource.cpp rdf/PluginRDFDescription.cpp rdf/PluginRDFDescription.h transform/TransformFactory.cpp
diffstat 6 files changed, 44 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CachedFile.cpp	Mon Oct 27 18:15:20 2008 +0000
+++ b/data/fileio/CachedFile.cpp	Mon Oct 27 20:29:55 2008 +0000
@@ -61,20 +61,20 @@
     return fi.filePath();
 }
 
-CachedFile::CachedFile(QString url, ProgressReporter *reporter) :
-    m_url(url),
-    m_localFilename(getLocalFilenameFor(m_url)),
+CachedFile::CachedFile(QString origin, ProgressReporter *reporter) :
+    m_origin(origin),
+    m_localFilename(getLocalFilenameFor(m_origin)),
     m_reporter(reporter),
     m_ok(false)
 {
-    std::cerr << "CachedFile::CachedFile: url is \""
-              << url.toStdString() << "\"" << std::endl;
+    std::cerr << "CachedFile::CachedFile: origin is \""
+              << origin.toStdString() << "\"" << std::endl;
     check();
 }
 
 CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) :
-    m_url(url),
-    m_localFilename(getLocalFilenameFor(m_url)),
+    m_origin(url.toString()),
+    m_localFilename(getLocalFilenameFor(m_origin)),
     m_reporter(reporter),
     m_ok(false)
 {
@@ -160,15 +160,17 @@
     //!!! using Qt classes, but a plain delete then copy is probably
     //!!! good enough)
 
-    FileSource fs(m_url, m_reporter);
+    FileSource fs(m_origin, m_reporter);
 
     if (!fs.isOK() || !fs.isAvailable()) {
+        std::cerr << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << std::endl;
         return false;
     }
 
     fs.waitForData();
 
     if (!fs.isOK()) {
+        std::cerr << "CachedFile::retrieve: ERROR: FileSource reported failure during receive" << std::endl;
         return false;
     }
 
@@ -196,6 +198,8 @@
         return false;
     }
 
+    std::cerr << "CachedFile::retrieve: Successfully copied newly retrieved file \"" << tempName.toStdString() << "\" to its home at \"" << m_localFilename.toStdString() << "\"" << std::endl;
+
     return true;
 }
 
--- a/data/fileio/CachedFile.h	Mon Oct 27 18:15:20 2008 +0000
+++ b/data/fileio/CachedFile.h	Mon Oct 27 20:29:55 2008 +0000
@@ -35,7 +35,7 @@
     QString getLocalFilename() const;
 
 protected:
-    QUrl m_url;
+    QString m_origin;
     QString m_localFilename;
     ProgressReporter *m_reporter;
     bool m_ok;
--- a/data/fileio/FileSource.cpp	Mon Oct 27 18:15:20 2008 +0000
+++ b/data/fileio/FileSource.cpp	Mon Oct 27 20:29:55 2008 +0000
@@ -62,6 +62,12 @@
     m_reporter(reporter),
     m_refCounted(false)
 {
+
+    if (cacheMode == PersistentCache) {
+        std::cerr << "FileSource::FileSource: Persistent cache mode used for \"" << fileOrUrl.toStdString() << "\"" << std::endl;
+        exit(1);
+    }
+
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource::FileSource(" << fileOrUrl.toStdString() << ", " << cacheMode << ")" << std::endl;
 #endif
@@ -128,6 +134,12 @@
     m_reporter(reporter),
     m_refCounted(false)
 {
+
+    if (cacheMode == PersistentCache) {
+        std::cerr << "FileSource::FileSource: Persistent cache mode used for \"" << url.toString().toStdString() << "\"" << std::endl;
+        exit(1);
+    }
+
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource::FileSource(" << url.toString().toStdString() << ") [as url]" << std::endl;
 #endif
--- a/rdf/PluginRDFDescription.cpp	Mon Oct 27 18:15:20 2008 +0000
+++ b/rdf/PluginRDFDescription.cpp	Mon Oct 27 20:29:55 2008 +0000
@@ -19,6 +19,7 @@
 #include "SimpleSPARQLQuery.h"
 
 #include "data/fileio/FileSource.h"
+#include "data/fileio/CachedFile.h"
 
 #include "base/Profiler.h"
 
@@ -29,7 +30,7 @@
 using std::endl;
 
 PluginRDFDescription::PluginRDFDescription(QString pluginId) :
-    m_source(0),
+//!!!    m_source(0),
     m_pluginId(pluginId),
     m_haveDescription(false)
 {
@@ -50,7 +51,7 @@
 
 PluginRDFDescription::~PluginRDFDescription()
 {
-    delete m_source;
+//!!!    delete m_source;
 }
 
 bool
@@ -168,6 +169,13 @@
         
         //!!! persistent with expiry
 
+        CachedFile cf(url);
+        if (!cf.isOK()) {
+            return false;
+        }
+
+        local = QUrl::fromLocalFile(cf.getLocalFilename()).toString();
+/*!!!
         m_source = new FileSource(url, 0, FileSource::PersistentCache);
 
         if (!m_source->isAvailable()) {
@@ -177,6 +185,7 @@
         }
         m_source->waitForData();
         local = QUrl::fromLocalFile(m_source->getLocalFilename()).toString();
+*/
     }
     
     if (!indexMetadata(local, label)) success = false;
--- a/rdf/PluginRDFDescription.h	Mon Oct 27 18:15:20 2008 +0000
+++ b/rdf/PluginRDFDescription.h	Mon Oct 27 20:29:55 2008 +0000
@@ -20,7 +20,7 @@
 #include <QStringList>
 #include <map>
 
-class FileSource;
+//!!!class FileSource;
 
 class PluginRDFDescription
 {
@@ -56,7 +56,7 @@
     typedef std::map<QString, OutputDisposition> OutputDispositionMap;
     typedef std::map<QString, QString> OutputStringMap;
 
-    FileSource *m_source;
+//!!!    FileSource *m_source;
     QString m_pluginId;
     bool m_haveDescription;
     QString m_pluginName;
--- a/transform/TransformFactory.cpp	Mon Oct 27 18:15:20 2008 +0000
+++ b/transform/TransformFactory.cpp	Mon Oct 27 20:29:55 2008 +0000
@@ -561,7 +561,12 @@
             
             if (m_transforms.find(tid) != m_transforms.end()) {
                 std::cerr << "TransformFactory::populateUninstalledTransforms: "
-                          << tid.toStdString() << " is installed, skipping" << std::endl;
+                          << tid.toStdString() << " is installed; adding info url if appropriate, skipping rest" << std::endl;
+                if (infoUrl != "") {
+                    if (m_transforms[tid].infoUrl == "") {
+                        m_transforms[tid].infoUrl = infoUrl;
+                    }
+                }
                 continue;
             }
 
@@ -611,14 +616,6 @@
             td.configurable = false;
 
             m_uninstalledTransforms[tid] = td;
-
-            if (td.infoUrl != "") {
-                if (m_transforms.find(tid) != m_transforms.end()) {
-                    if (m_transforms[tid].infoUrl == "") {
-                        m_transforms[tid].infoUrl = td.infoUrl;
-                    }
-                }
-            }
         }
     }