Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 12, 2015, 4:10:02 PM (9 years ago)
Author:
landauf
Message:

it's now possible to define required plugins in the level definition (in XML)

Location:
code/branches/core7/src/libraries/core/module
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/module/CMakeLists.txt

    r10552 r10580  
    55  Plugin.cc
    66  PluginManager.cc
     7  PluginReference.cc
    78  StaticallyInitializedInstance.cc
    89  StaticInitializationHandlerIncludes.cc
  • code/branches/core7/src/libraries/core/module/PluginManager.cc

    r10552 r10580  
    3333#include "SpecialConfig.h"
    3434#include "Plugin.h"
     35#include "PluginReference.h"
    3536#include "core/ApplicationPaths.h"
    3637#include "core/command/ConsoleCommandIncludes.h"
     38#include "core/object/Context.h"
    3739
    3840namespace orxonox
    3941{
    40     SetConsoleCommand("PluginManager", "load", &PluginManager::loadPlugin);
    41     SetConsoleCommand("PluginManager", "unload", &PluginManager::unloadPlugin);
     42    static const std::string __CC_PluginManager_load_name  = "load";
     43    static const std::string __CC_PluginManager_unload_name  = "unload";
     44
     45    SetConsoleCommand("PluginManager", __CC_PluginManager_load_name, &PluginManager::loadPlugin);
     46    SetConsoleCommand("PluginManager", __CC_PluginManager_unload_name, &PluginManager::unloadPlugin);
    4247
    4348    PluginManager* PluginManager::singletonPtr_s  = 0;
     
    4550    PluginManager::PluginManager()
    4651    {
     52        ModifyConsoleCommand("PluginManager", __CC_PluginManager_load_name).setObject(this);
     53        ModifyConsoleCommand("PluginManager", __CC_PluginManager_unload_name).setObject(this);
    4754    }
    4855
    4956    PluginManager::~PluginManager()
    5057    {
     58        ModifyConsoleCommand("PluginManager", __CC_PluginManager_load_name).setObject(NULL);
     59        ModifyConsoleCommand("PluginManager", __CC_PluginManager_unload_name).setObject(NULL);
     60
     61        for (std::map<std::string, PluginReference*>::iterator it = this->references_.begin(); it != this->references_.end(); ++it)
     62            delete it->second;
    5163        for (std::map<std::string, Plugin*>::iterator it = this->plugins_.begin(); it != this->plugins_.end(); ++it)
    5264            delete it->second;
     
    7486    }
    7587
    76     /*static*/ void PluginManager::loadPlugin(const std::string& name)
     88    void PluginManager::referencePlugin(const std::string& name)
    7789    {
    78         Plugin* plugin = PluginManager::getInstance().plugins_[name];
     90        Plugin* plugin = this->plugins_[name];
    7991        if (plugin != NULL)
    8092            plugin->load();
     
    8395    }
    8496
    85     /*static*/ void PluginManager::unloadPlugin(const std::string& name)
     97    void PluginManager::dereferencePlugin(const std::string& name)
    8698    {
    87         Plugin* plugin = PluginManager::getInstance().plugins_[name];
     99        Plugin* plugin = this->plugins_[name];
    88100        if (plugin != NULL)
    89101            plugin->unload();
     
    91103            orxout(internal_warning) << "Cannot find plugin with name " << name << endl;
    92104    }
     105
     106    /**
     107     * @brief Console command to manually load a plugin. The plugin stays loaded until @ref unloadPlugin is called.
     108     */
     109    void PluginManager::loadPlugin(const std::string& name)
     110    {
     111        if (this->references_[name] == NULL)
     112        {
     113            this->references_[name] = new PluginReference(name);
     114        }
     115        else
     116            orxout(internal_warning) << "Plugin " << name << " is already loaded" << endl;
     117    }
     118
     119    /**
     120     * @brief Console command to unload a plugin if it was previously loaded manually by calling @ref loadPlugin.
     121     * Does not unload the plugin immediately if it is still used by another @ref PluginReference (e.g. by a @ref Level).
     122     */
     123    void PluginManager::unloadPlugin(const std::string& name)
     124    {
     125        PluginReference* reference = this->references_[name];
     126        if (reference != NULL)
     127        {
     128            this->references_[name] = NULL;
     129            delete reference;
     130        }
     131        else
     132            orxout(internal_warning) << "Plugin " << name << " is already unloaded" << endl;
     133    }
    93134}
  • code/branches/core7/src/libraries/core/module/PluginManager.h

    r10552 r10580  
    4848            void findPlugins();
    4949
    50             static void loadPlugin(const std::string& name);
    51             static void unloadPlugin(const std::string& name);
     50            void referencePlugin(const std::string& name);
     51            void dereferencePlugin(const std::string& name);
     52
     53            // console commands
     54            void loadPlugin(const std::string& name);
     55            void unloadPlugin(const std::string& name);
    5256
    5357        private:
    5458            std::map<std::string, Plugin*> plugins_;
     59            std::map<std::string, PluginReference*> references_; // references that were created by console command
    5560
    5661            static PluginManager* singletonPtr_s;
Note: See TracChangeset for help on using the changeset viewer.