Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11015 for code


Ignore:
Timestamp:
Jan 2, 2016, 3:36:10 PM (9 years ago)
Author:
landauf
Message:

added option to merely deactivate a plugin when its reference count drops to zero instead of unloading it

Location:
code/trunk/src/libraries/core/module
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/module/Plugin.cc

    r11014 r11015  
    3232#include "util/Output.h"
    3333#include "core/Core.h"
     34#include "StaticInitializationManager.h"
    3435
    3536namespace orxonox
     
    4344    Plugin::~Plugin()
    4445    {
     46        // force unloading of the module when the plugin is destroyed
    4547        if (this->moduleInstance_ != NULL)
    46             this->unload();
     48            this->unloadModule();
    4749    }
    4850
     
    5658    }
    5759
    58     void Plugin::dereference()
     60    void Plugin::dereference(bool bMerelyDeactivate)
    5961    {
    6062        if (this->referenceCounter_ == 0)
     
    6668        this->referenceCounter_--;
    6769        if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
    68             this->unload();
     70            this->unload(bMerelyDeactivate);
    6971        else
    7072            orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
    7173    }
    7274
     75    //////////////////////////////////////////
     76    //                 LOAD                 //
     77    //////////////////////////////////////////
    7378    void Plugin::load()
     79    {
     80        // only load module if it isn't already loaded. otherwise merely activate it.
     81        if (this->moduleInstance_ == NULL)
     82            this->loadModule();
     83        else
     84            this->activateModule();
     85    }
     86    void Plugin::loadModule()
    7487    {
    7588        orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
     
    7790        Core::getInstance().loadModule(this->moduleInstance_);
    7891    }
     92    void Plugin::activateModule()
     93    {
     94        orxout(internal_info) << "Activating plugin " << this->name_ << "..." << endl;
     95        StaticInitializationManager::getInstance().loadModule(this->moduleInstance_);
     96    }
    7997
    80     void Plugin::unload()
     98    //////////////////////////////////////////
     99    //                UNLOAD                //
     100    //////////////////////////////////////////
     101    void Plugin::unload(bool bMerelyDeactivate)
     102    {
     103        // fully unload the module unless otherwise requested.
     104        if (bMerelyDeactivate)
     105            this->deactivateModule();
     106        else
     107            this->unloadModule();
     108    }
     109    void Plugin::unloadModule()
    81110    {
    82111        orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
     
    85114        this->moduleInstance_ = NULL;
    86115    }
     116    void Plugin::deactivateModule()
     117    {
     118        orxout(internal_info) << "Deactivating plugin " << this->name_ << "..." << endl;
     119        StaticInitializationManager::getInstance().unloadModule(this->moduleInstance_);
     120    }
    87121}
  • code/trunk/src/libraries/core/module/Plugin.h

    r11014 r11015  
    4141
    4242            void reference();
    43             void dereference();
     43            void dereference(bool bMerelyDeactivate);
    4444
    4545        private:
    4646            void load();
    47             void unload();
     47            void unload(bool bMerelyDeactivate);
     48
     49            void loadModule();
     50            void activateModule();
     51
     52            void unloadModule();
     53            void deactivateModule();
    4854
    4955            std::string name_;
  • code/trunk/src/libraries/core/module/PluginManager.cc

    r11014 r11015  
    9999        Plugin* plugin = this->plugins_[name];
    100100        if (plugin != NULL)
    101             plugin->dereference();
     101            plugin->dereference(false);
    102102        else
    103103            orxout(internal_warning) << "Cannot find plugin with name " << name << endl;
Note: See TracChangeset for help on using the changeset viewer.