Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.