changeset 477:e0784311a103

* Start thread to populate uninstalled transforms only on request (so runner doesn't have to have it)
author Chris Cannam
date Tue, 11 Nov 2008 09:41:45 +0000
parents acddcc3cca36
children 1405f4a2caf3
files rdf/PluginRDFIndexer.cpp rdf/PluginRDFIndexer.h transform/TransformFactory.cpp transform/TransformFactory.h
diffstat 4 files changed, 47 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/rdf/PluginRDFIndexer.cpp	Fri Nov 07 20:25:57 2008 +0000
+++ b/rdf/PluginRDFIndexer.cpp	Tue Nov 11 09:41:45 2008 +0000
@@ -52,6 +52,17 @@
 
 PluginRDFIndexer::PluginRDFIndexer()
 {
+    indexInstalledURLs();
+}
+
+PluginRDFIndexer::~PluginRDFIndexer()
+{
+    QMutexLocker locker(&m_mutex);
+}
+
+void
+PluginRDFIndexer::indexInstalledURLs()
+{
     vector<string> paths = PluginHostAdapter::getPluginPath();
 
     QStringList filters;
@@ -98,11 +109,6 @@
     }
 }
 
-PluginRDFIndexer::~PluginRDFIndexer()
-{
-    QMutexLocker locker(&m_mutex);
-}
-
 bool
 PluginRDFIndexer::indexConfiguredURLs()
 {
--- a/rdf/PluginRDFIndexer.h	Fri Nov 07 20:25:57 2008 +0000
+++ b/rdf/PluginRDFIndexer.h	Tue Nov 11 09:41:45 2008 +0000
@@ -22,8 +22,6 @@
 #include <map>
 #include <set>
 
-//!!!class FileSource;
-
 class PluginRDFIndexer
 {
 public:
@@ -31,9 +29,11 @@
 
     /**
      * Index all URLs obtained from index files defined in the current
-     * settings.  This is not done automatically because it may incur
-     * significant processing and networking effort.  It could be
-     * called from a background thread at startup, for example.
+     * settings.  In contrast to indexing URLs that are installed
+     * locally alongside plugins, this is not done automatically
+     * because it may incur significant processing and networking
+     * effort.  It could be called from a background thread at
+     * startup, for example.
      *
      * Note that this class has a single mutex, so other functions
      * will block if called from a different thread while this one is
@@ -55,16 +55,15 @@
 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;
+
+    void indexInstalledURLs();
     bool indexFile(QString path);
     static PluginRDFIndexer *m_instance;
-//!!!    void expireCacheMaybe(QString);
 };
 
 #endif
--- a/transform/TransformFactory.cpp	Fri Nov 07 20:25:57 2008 +0000
+++ b/transform/TransformFactory.cpp	Tue Nov 11 09:41:45 2008 +0000
@@ -51,17 +51,27 @@
 
 TransformFactory::TransformFactory() :
     m_transformsPopulated(false),
-    m_uninstalledTransformsPopulated(false)
+    m_uninstalledTransformsPopulated(false),
+    m_thread(0)
 {
-    UninstalledTransformsPopulateThread *thread =
-        new UninstalledTransformsPopulateThread(this);
-    thread->start();
 }
 
 TransformFactory::~TransformFactory()
 {
 }
 
+void
+TransformFactory::startPopulationThread()
+{
+    MutexLocker locker(&m_uninstalledTransformsMutex,
+                       "TransformFactory::startPopulationThread");
+
+    if (m_thread) return;
+
+    m_thread = new UninstalledTransformsPopulateThread(this);
+    m_thread->start();
+}
+
 TransformList
 TransformFactory::getAllTransformDescriptions()
 {
--- a/transform/TransformFactory.h	Fri Nov 07 20:25:57 2008 +0000
+++ b/transform/TransformFactory.h	Tue Nov 11 09:41:45 2008 +0000
@@ -40,6 +40,18 @@
 
     static TransformFactory *getInstance();
 
+    /**
+     * TransformFactory has a background thread that can populate
+     * uninstalled transforms from network RDF resources.  It is not
+     * started by default, but it's a good idea to start it when the
+     * program starts up, if the uninstalled transforms may be of use
+     * later; otherwise there will be a bottleneck the first time
+     * they're requested.
+     *
+     * If this thread is not already running, start it now.
+     */
+    void startPopulationThread();
+
     TransformList getAllTransformDescriptions();
     TransformDescription getTransformDescription(TransformId id);
 
@@ -212,6 +224,8 @@
         TransformFactory *m_factory;
     };
 
+    UninstalledTransformsPopulateThread *m_thread;
+
     static TransformFactory *m_instance;
 };