[Orxonox-commit 6357] r11014 - code/trunk/src/libraries/core/module
landauf at orxonox.net
landauf at orxonox.net
Sat Jan 2 15:15:04 CET 2016
Author: landauf
Date: 2016-01-02 15:15:04 +0100 (Sat, 02 Jan 2016)
New Revision: 11014
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:
moved code for loading/unloading a plugin into separate functions
Modified: code/trunk/src/libraries/core/module/Plugin.cc
===================================================================
--- code/trunk/src/libraries/core/module/Plugin.cc 2016-01-02 10:48:40 UTC (rev 11013)
+++ code/trunk/src/libraries/core/module/Plugin.cc 2016-01-02 14:15:04 UTC (rev 11014)
@@ -43,26 +43,19 @@
Plugin::~Plugin()
{
if (this->moduleInstance_ != NULL)
- {
- this->referenceCounter_ = 1; // force unloading
this->unload();
- }
}
- void Plugin::load()
+ void Plugin::reference()
{
this->referenceCounter_++;
if (this->referenceCounter_ == 1) // increased from 0 to 1 -> load plugin
- {
- orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
- this->moduleInstance_ = new ModuleInstance(this->libraryName_);
- Core::getInstance().loadModule(this->moduleInstance_);
- }
+ this->load();
else
orxout(internal_info) << "Increased reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
}
- void Plugin::unload()
+ void Plugin::dereference()
{
if (this->referenceCounter_ == 0)
{
@@ -72,13 +65,23 @@
this->referenceCounter_--;
if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
- {
- orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
- Core::getInstance().unloadModule(this->moduleInstance_);
- delete this->moduleInstance_;
- this->moduleInstance_ = NULL;
- }
+ this->unload();
else
orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
}
+
+ void Plugin::load()
+ {
+ orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
+ this->moduleInstance_ = new ModuleInstance(this->libraryName_);
+ Core::getInstance().loadModule(this->moduleInstance_);
+ }
+
+ void Plugin::unload()
+ {
+ orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
+ Core::getInstance().unloadModule(this->moduleInstance_);
+ delete this->moduleInstance_;
+ this->moduleInstance_ = NULL;
+ }
}
Modified: code/trunk/src/libraries/core/module/Plugin.h
===================================================================
--- code/trunk/src/libraries/core/module/Plugin.h 2016-01-02 10:48:40 UTC (rev 11013)
+++ code/trunk/src/libraries/core/module/Plugin.h 2016-01-02 14:15:04 UTC (rev 11014)
@@ -39,10 +39,13 @@
Plugin(const std::string& name, const std::string& libraryName);
~Plugin();
+ void reference();
+ void dereference();
+
+ private:
void load();
void unload();
- private:
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 10:48:40 UTC (rev 11013)
+++ code/trunk/src/libraries/core/module/PluginManager.cc 2016-01-02 14:15:04 UTC (rev 11014)
@@ -89,7 +89,7 @@
{
Plugin* plugin = this->plugins_[name];
if (plugin != NULL)
- plugin->load();
+ plugin->reference();
else
orxout(internal_warning) << "Cannot find plugin with name " << name << endl;
}
@@ -98,7 +98,7 @@
{
Plugin* plugin = this->plugins_[name];
if (plugin != NULL)
- plugin->unload();
+ plugin->dereference();
else
orxout(internal_warning) << "Cannot find plugin with name " << name << endl;
}
More information about the Orxonox-commit
mailing list