Explorar o código

Added a plugin framework property for pre-loading libraries.

Sascha Zelzer %!s(int64=13) %!d(string=hai) anos
pai
achega
77a580b0cc

+ 1 - 0
Libs/PluginFramework/ctkPluginConstants.cpp

@@ -30,6 +30,7 @@ const QString ctkPluginConstants::FRAMEWORK_STORAGE = "org.commontk.pluginfw.sto
 const QString ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN = "org.commontk.pluginfw.storage.clean";
 const QString ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT = "onFirstInit";
 const QString ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS = "org.commontk.pluginfw.loadhints";
+const QString ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES = "org.commontk.pluginfw.preloadlibs";
 
 const QString ctkPluginConstants::PLUGIN_SYMBOLICNAME = "Plugin-SymbolicName";
 const QString ctkPluginConstants::PLUGIN_COPYRIGHT = "Plugin-Copyright";

+ 16 - 0
Libs/PluginFramework/ctkPluginConstants.h

@@ -107,6 +107,22 @@ struct CTK_PLUGINFW_EXPORT ctkPluginConstants {
   static const QString FRAMEWORK_PLUGIN_LOAD_HINTS; // = "org.commontk.pluginfw.loadhints"
 
   /**
+   * Specifies the set of libraries which should be dynamically opened when starting
+   * the framework. The value of this property must be either of type QString
+   * or QStringList. The given libraries are loaded with QLibrary::load(), using the
+   * load hints specified in FRAMEWORK_PLUGIN_LOAD_HINTS. The library search path is
+   * defined by the QLibrary class.
+   *
+   * Setting this property can improve the initial framework start-up time dramatically if
+   * a lot of plug-ins with deeply nested library dependencies are installed. During
+   * initial framework start-up (no plug-in meta-data cached yet), the repeated loading
+   * and unloading of the installed plug-ins will then only lead to repeated loading
+   * and unloading of plug-in dependencies which are not contained in the transitive
+   * dependency closure of the given set of pre-loaded libraries.
+   */
+  static const QString FRAMEWORK_PRELOAD_LIBRARIES; // = "org.commontk.pluginfw.preloadlibs"
+
+  /**
    * Manifest header identifying the plugin's symbolic name.
    *
    * <p>

+ 26 - 0
Libs/PluginFramework/ctkPluginFrameworkContext.cpp

@@ -86,6 +86,32 @@ void ctkPluginFrameworkContext::init()
   services = new ctkServices(this);
   plugins = new ctkPlugins(this);
 
+  // Pre-load libraries
+  // This may speed up installing new plug-ins if they have dependencies on
+  // one of these libraries. It prevents repeated loading and unloading of the
+  // pre-loaded libraries during caching of the plug-in meta-data.
+  if (props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].isValid())
+  {
+    QStringList preloadLibs = props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].toStringList();
+    QLibrary::LoadHints loadHints;
+    QVariant loadHintsVariant = props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
+    if (loadHintsVariant.isValid())
+    {
+      loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
+    }
+
+    foreach(QString preloadLib, preloadLibs)
+    {
+      QLibrary lib(preloadLib);
+      lib.setLoadHints(loadHints);
+      log() << "Pre-loading library" << preloadLib << "with hints [" << static_cast<int>(loadHints) << "]";
+      if (!lib.load())
+      {
+        qWarning() << "Pre-loading library" << preloadLib << "failed";
+      }
+    }
+  }
+
   plugins->load();
 
   log() << "inited";