Просмотр исходного кода

When caching resources, load the plugins with the provided load hints.

On MacOS, typeinfo symbols where still missing on the first application
run. The plugins where loaded with no hints (hence with RTLD_LOCAL),
then unloaded and later on loaded again with the provided load hints.
Still, some dynamic_cast calls failed. Using the same flags during the
first plugin load solved this issue.
Sascha Zelzer лет назад: 14
Родитель
Сommit
87277ae906

+ 16 - 0
Libs/PluginFramework/ctkPluginDatabase.cpp

@@ -27,6 +27,7 @@
 #include "ctkPluginArchive_p.h"
 #include "ctkPluginStorage_p.h"
 #include "ctkPluginFrameworkUtil_p.h"
+#include "ctkPluginFrameworkContext_p.h"
 #include "ctkServiceException.h"
 
 #include <QApplication>
@@ -262,6 +263,20 @@ void ctkPluginDatabase::updateDB()
 }
 
 //----------------------------------------------------------------------------
+QLibrary::LoadHints ctkPluginDatabase::getPluginLoadHints() const
+{
+  if (m_PluginStorage->getFrameworkContext()->props.contains(ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS))
+  {
+    QVariant loadHintsVariant = m_PluginStorage->getFrameworkContext()->props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS]; 
+    if (loadHintsVariant.isValid())
+    {
+      return loadHintsVariant.value<QLibrary::LoadHints>();
+    }
+  }
+  return QLibrary::LoadHints(0);
+}
+
+//----------------------------------------------------------------------------
 ctkPluginArchive* ctkPluginDatabase::insertPlugin(const QUrl& location, const QString& localPath, bool createArchive)
 {
   checkConnection();
@@ -318,6 +333,7 @@ ctkPluginArchive* ctkPluginDatabase::insertPlugin(const QUrl& location, const QS
 
   // Load the plugin and cache the resources
   QPluginLoader pluginLoader;
+  pluginLoader.setLoadHints(getPluginLoadHints());
   pluginLoader.setFileName(localPath);
   if (!pluginLoader.load())
   {

+ 5 - 0
Libs/PluginFramework/ctkPluginDatabase_p.h

@@ -156,6 +156,11 @@ public:
 private:
 
   enum TransactionType{Read, Write};
+  
+  /**
+   * Get load hints from the framework for plugins.
+   */
+  QLibrary::LoadHints getPluginLoadHints() const;
 
   /**
    *  Helper method that creates the database tables:

+ 6 - 0
Libs/PluginFramework/ctkPluginStorage.cpp

@@ -45,6 +45,12 @@ ctkPluginStorage::ctkPluginStorage(ctkPluginFrameworkContext* framework)
 }
 
 //----------------------------------------------------------------------------
+ctkPluginFrameworkContext* ctkPluginStorage::getFrameworkContext() const
+{
+  return framework;
+}
+
+//----------------------------------------------------------------------------
 ctkPluginArchive* ctkPluginStorage::insertPlugin(const QUrl& location, const QString& localPath)
 {
   ctkPluginArchive* pa = pluginDatabase.insertPlugin(location, localPath);

+ 4 - 0
Libs/PluginFramework/ctkPluginStorage_p.h

@@ -71,6 +71,10 @@ public:
    */
   ctkPluginStorage(ctkPluginFrameworkContext* framework);
 
+  /**
+   * Return the framework context.
+   */
+  ctkPluginFrameworkContext* getFrameworkContext() const;
 
   /**
    * Insert a plugin (shared library) into the persistent storage