[Sv1-commits] SF.net SVN: sv1:[1254] sonic-visualiser/trunk
Brought to you by:
cannam
From: <ca...@us...> - 2008-10-27 18:18:10
|
Revision: 1254 http://sv1.svn.sourceforge.net/sv1/?rev=1254&view=rev Author: cannam Date: 2008-10-27 18:15:20 +0000 (Mon, 27 Oct 2008) Log Message: ----------- * make use of CachedFile (untested) Modified Paths: -------------- sonic-visualiser/trunk/data/fileio/CachedFile.cpp sonic-visualiser/trunk/data/fileio/CachedFile.h sonic-visualiser/trunk/rdf/PluginRDFIndexer.cpp sonic-visualiser/trunk/rdf/PluginRDFIndexer.h Modified: sonic-visualiser/trunk/data/fileio/CachedFile.cpp =================================================================== --- sonic-visualiser/trunk/data/fileio/CachedFile.cpp 2008-10-27 15:07:35 UTC (rev 1253) +++ sonic-visualiser/trunk/data/fileio/CachedFile.cpp 2008-10-27 18:15:20 UTC (rev 1254) @@ -61,15 +61,32 @@ return fi.filePath(); } +CachedFile::CachedFile(QString url, ProgressReporter *reporter) : + m_url(url), + m_localFilename(getLocalFilenameFor(m_url)), + m_reporter(reporter), + m_ok(false) +{ + std::cerr << "CachedFile::CachedFile: url is \"" + << url.toStdString() << "\"" << std::endl; + check(); +} + CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) : m_url(url), - m_localFilename(getLocalFilenameFor(url)), + m_localFilename(getLocalFilenameFor(m_url)), m_reporter(reporter), m_ok(false) { - refresh(); + std::cerr << "CachedFile::CachedFile: url is \"" + << url.toString().toStdString() << "\"" << std::endl; + check(); } +CachedFile::~CachedFile() +{ +} + bool CachedFile::isOK() const { @@ -83,7 +100,7 @@ } void -CachedFile::refresh() +CachedFile::check() { //!!! n.b. obvious race condition here if different CachedFile // objects for same url used in more than one thread -- need to @@ -91,16 +108,20 @@ // separate instances of the program if (!QFileInfo(m_localFilename).exists()) { + std::cerr << "CachedFile::check: Local file does not exist, making a note that it hasn't been retrieved" << std::endl; updateLastRetrieval(false); // empirically! } QDateTime lastRetrieval = getLastRetrieval(); if (lastRetrieval.isValid()) { + std::cerr << "CachedFile::check: Valid last retrieval at " + << lastRetrieval.toString().toStdString() << std::endl; // this will not be the case if the file is missing, after // updateLastRetrieval(false) was called above m_ok = true; if (lastRetrieval.addDays(2) < QDateTime::currentDateTime()) { //!!! + std::cerr << "CachedFile::check: Out of date; trying to retrieve again" << std::endl; // doesn't matter if retrieval fails -- we just don't // update the last retrieval time @@ -109,15 +130,21 @@ // retrieval every single time if it isn't working if (retrieve()) { + std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; updateLastRetrieval(true); - } + } else { + std::cerr << "CachedFile::check: Retrieval failed, will try again later (using existing file for now)" << std::endl; + } } } else { + std::cerr << "CachedFile::check: No valid last retrieval" << std::endl; // there is no acceptable file if (retrieve()) { + std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; m_ok = true; updateLastRetrieval(true); } else { + std::cerr << "CachedFile::check: Retrieval failed, remaining in invalid state" << std::endl; // again, we don't need to do anything here -- the last // retrieval timestamp is already invalid } Modified: sonic-visualiser/trunk/data/fileio/CachedFile.h =================================================================== --- sonic-visualiser/trunk/data/fileio/CachedFile.h 2008-10-27 15:07:35 UTC (rev 1253) +++ sonic-visualiser/trunk/data/fileio/CachedFile.h 2008-10-27 18:15:20 UTC (rev 1254) @@ -25,6 +25,7 @@ class CachedFile { public: + CachedFile(QString fileOrUrl, ProgressReporter *reporter = 0); CachedFile(QUrl url, ProgressReporter *reporter = 0); virtual ~CachedFile(); @@ -39,7 +40,7 @@ ProgressReporter *m_reporter; bool m_ok; - void refresh(); + void check(); bool retrieve(); QDateTime getLastRetrieval(); Modified: sonic-visualiser/trunk/rdf/PluginRDFIndexer.cpp =================================================================== --- sonic-visualiser/trunk/rdf/PluginRDFIndexer.cpp 2008-10-27 15:07:35 UTC (rev 1253) +++ sonic-visualiser/trunk/rdf/PluginRDFIndexer.cpp 2008-10-27 18:15:20 UTC (rev 1254) @@ -17,7 +17,8 @@ #include "SimpleSPARQLQuery.h" -#include "data/fileio/FileSource.h" +//!!!#include "data/fileio/FileSource.h" +#include "data/fileio/CachedFile.h" #include "data/fileio/PlaylistFileReader.h" #include "plugin/PluginIdentifier.h" @@ -100,11 +101,12 @@ PluginRDFIndexer::~PluginRDFIndexer() { QMutexLocker locker(&m_mutex); - +/*!!! while (!m_sources.empty()) { delete *m_sources.begin(); m_sources.erase(m_sources.begin()); } +*/ } bool @@ -125,12 +127,19 @@ std::cerr << "PluginRDFIndexer::indexConfiguredURLs: index url is " << index.toStdString() << std::endl; +/*!!! expireCacheMaybe(index); FileSource indexSource(index, 0, FileSource::PersistentCache); if (!indexSource.isAvailable()) continue; indexSource.waitForData(); +*/ + CachedFile cf(index); + if (!cf.isOK()) continue; + + FileSource indexSource(cf.getLocalFilename()); + PlaylistFileReader reader(indexSource); if (!reader.isOK()) continue; @@ -230,7 +239,7 @@ QString urlString = url.toString(); return indexURL(urlString); } - +/*!!! void PluginRDFIndexer::expireCacheMaybe(QString urlString) { @@ -266,7 +275,7 @@ settings.endGroup(); } - +*/ bool PluginRDFIndexer::indexURL(QString urlString) { @@ -284,6 +293,13 @@ //!!! how do we avoid hammering the server if it doesn't have //!!! the file, and/or the network if it can't get through? + CachedFile cf(urlString); + if (!cf.isOK()) { + return false; + } + + localString = cf.getLocalFilename(); +/*!!! expireCacheMaybe(urlString); FileSource *source = new FileSource @@ -295,6 +311,7 @@ source->waitForData(); localString = QUrl::fromLocalFile(source->getLocalFilename()).toString(); m_sources.insert(source); +*/ } // cerr << "PluginRDFIndexer::indexURL: url = <" << urlString.toStdString() << ">" << endl; Modified: sonic-visualiser/trunk/rdf/PluginRDFIndexer.h =================================================================== --- sonic-visualiser/trunk/rdf/PluginRDFIndexer.h 2008-10-27 15:07:35 UTC (rev 1253) +++ sonic-visualiser/trunk/rdf/PluginRDFIndexer.h 2008-10-27 18:15:20 UTC (rev 1254) @@ -22,7 +22,7 @@ #include <map> #include <set> -class FileSource; +//!!!class FileSource; class PluginRDFIndexer { @@ -55,14 +55,16 @@ protected: PluginRDFIndexer(); QMutex m_mutex; +/*!!! std::set<FileSource *> m_sources; +*/ typedef std::map<QString, QString> StringMap; StringMap m_uriToIdMap; StringMap m_idToUriMap; StringMap m_idToDescriptionMap; bool indexFile(QString path); static PluginRDFIndexer *m_instance; - void expireCacheMaybe(QString); +//!!! void expireCacheMaybe(QString); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |