[Orxonox-commit 6358] r11015 - code/trunk/src/libraries/core/module

landauf at orxonox.net landauf at orxonox.net
Sat Jan 2 15:36:10 CET 2016


Author: landauf
Date: 2016-01-02 15:36:10 +0100 (Sat, 02 Jan 2016)
New Revision: 11015

Modified:
   code/trunk/src/libraries/core/module/Plugin.cc
   code/trunk/src/libraries/core/module/Plugin.h
   code/trunk/src/libraries/core/module/PluginManager.cc
Log:
added option to merely deactivate a plugin when its reference count drops to zero instead of unloading it

Modified: code/trunk/src/libraries/core/module/Plugin.cc
===================================================================
--- code/trunk/src/libraries/core/module/Plugin.cc	2016-01-02 14:15:04 UTC (rev 11014)
+++ code/trunk/src/libraries/core/module/Plugin.cc	2016-01-02 14:36:10 UTC (rev 11015)
@@ -31,6 +31,7 @@
 #include "ModuleInstance.h"
 #include "util/Output.h"
 #include "core/Core.h"
+#include "StaticInitializationManager.h"
 
 namespace orxonox
 {
@@ -42,8 +43,9 @@
 
     Plugin::~Plugin()
     {
+        // force unloading of the module when the plugin is destroyed
         if (this->moduleInstance_ != NULL)
-            this->unload();
+            this->unloadModule();
     }
 
     void Plugin::reference()
@@ -55,7 +57,7 @@
             orxout(internal_info) << "Increased reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
     }
 
-    void Plugin::dereference()
+    void Plugin::dereference(bool bMerelyDeactivate)
     {
         if (this->referenceCounter_ == 0)
         {
@@ -65,23 +67,55 @@
 
         this->referenceCounter_--;
         if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
-            this->unload();
+            this->unload(bMerelyDeactivate);
         else
             orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
     }
 
+    //////////////////////////////////////////
+    //                 LOAD                 //
+    //////////////////////////////////////////
     void Plugin::load()
     {
+        // only load module if it isn't already loaded. otherwise merely activate it.
+        if (this->moduleInstance_ == NULL)
+            this->loadModule();
+        else
+            this->activateModule();
+    }
+    void Plugin::loadModule()
+    {
         orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
         this->moduleInstance_ = new ModuleInstance(this->libraryName_);
         Core::getInstance().loadModule(this->moduleInstance_);
     }
+    void Plugin::activateModule()
+    {
+        orxout(internal_info) << "Activating plugin " << this->name_ << "..." << endl;
+        StaticInitializationManager::getInstance().loadModule(this->moduleInstance_);
+    }
 
-    void Plugin::unload()
+    //////////////////////////////////////////
+    //                UNLOAD                //
+    //////////////////////////////////////////
+    void Plugin::unload(bool bMerelyDeactivate)
     {
+        // fully unload the module unless otherwise requested.
+        if (bMerelyDeactivate)
+            this->deactivateModule();
+        else
+            this->unloadModule();
+    }
+    void Plugin::unloadModule()
+    {
         orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
         Core::getInstance().unloadModule(this->moduleInstance_);
         delete this->moduleInstance_;
         this->moduleInstance_ = NULL;
     }
+    void Plugin::deactivateModule()
+    {
+        orxout(internal_info) << "Deactivating plugin " << this->name_ << "..." << endl;
+        StaticInitializationManager::getInstance().unloadModule(this->moduleInstance_);
+    }
 }

Modified: code/trunk/src/libraries/core/module/Plugin.h
===================================================================
--- code/trunk/src/libraries/core/module/Plugin.h	2016-01-02 14:15:04 UTC (rev 11014)
+++ code/trunk/src/libraries/core/module/Plugin.h	2016-01-02 14:36:10 UTC (rev 11015)
@@ -40,12 +40,18 @@
             ~Plugin();
 
             void reference();
-            void dereference();
+            void dereference(bool bMerelyDeactivate);
 
         private:
             void load();
-            void unload();
+            void unload(bool bMerelyDeactivate);
 
+            void loadModule();
+            void activateModule();
+
+            void unloadModule();
+            void deactivateModule();
+
             std::string name_;
             std::string libraryName_;
             unsigned int referenceCounter_;

Modified: code/trunk/src/libraries/core/module/PluginManager.cc
===================================================================
--- code/trunk/src/libraries/core/module/PluginManager.cc	2016-01-02 14:15:04 UTC (rev 11014)
+++ code/trunk/src/libraries/core/module/PluginManager.cc	2016-01-02 14:36:10 UTC (rev 11015)
@@ -98,7 +98,7 @@
     {
         Plugin* plugin = this->plugins_[name];
         if (plugin != NULL)
-            plugin->dereference();
+            plugin->dereference(false);
         else
             orxout(internal_warning) << "Cannot find plugin with name " << name << endl;
     }




More information about the Orxonox-commit mailing list