Changeset 10580
- Timestamp:
- Sep 12, 2015, 4:10:02 PM (9 years ago)
- Location:
- code/branches/core7/src
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/CorePrereqs.h
r10555 r10580 212 212 class Plugin; 213 213 class PluginManager; 214 class PluginReference; 214 215 struct ResourceInfo; 215 216 template <ScopeID::Value> -
code/branches/core7/src/libraries/core/module/CMakeLists.txt
r10552 r10580 5 5 Plugin.cc 6 6 PluginManager.cc 7 PluginReference.cc 7 8 StaticallyInitializedInstance.cc 8 9 StaticInitializationHandlerIncludes.cc -
code/branches/core7/src/libraries/core/module/PluginManager.cc
r10552 r10580 33 33 #include "SpecialConfig.h" 34 34 #include "Plugin.h" 35 #include "PluginReference.h" 35 36 #include "core/ApplicationPaths.h" 36 37 #include "core/command/ConsoleCommandIncludes.h" 38 #include "core/object/Context.h" 37 39 38 40 namespace orxonox 39 41 { 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); 42 47 43 48 PluginManager* PluginManager::singletonPtr_s = 0; … … 45 50 PluginManager::PluginManager() 46 51 { 52 ModifyConsoleCommand("PluginManager", __CC_PluginManager_load_name).setObject(this); 53 ModifyConsoleCommand("PluginManager", __CC_PluginManager_unload_name).setObject(this); 47 54 } 48 55 49 56 PluginManager::~PluginManager() 50 57 { 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; 51 63 for (std::map<std::string, Plugin*>::iterator it = this->plugins_.begin(); it != this->plugins_.end(); ++it) 52 64 delete it->second; … … 74 86 } 75 87 76 /*static*/ void PluginManager::loadPlugin(const std::string& name)88 void PluginManager::referencePlugin(const std::string& name) 77 89 { 78 Plugin* plugin = PluginManager::getInstance().plugins_[name];90 Plugin* plugin = this->plugins_[name]; 79 91 if (plugin != NULL) 80 92 plugin->load(); … … 83 95 } 84 96 85 /*static*/ void PluginManager::unloadPlugin(const std::string& name)97 void PluginManager::dereferencePlugin(const std::string& name) 86 98 { 87 Plugin* plugin = PluginManager::getInstance().plugins_[name];99 Plugin* plugin = this->plugins_[name]; 88 100 if (plugin != NULL) 89 101 plugin->unload(); … … 91 103 orxout(internal_warning) << "Cannot find plugin with name " << name << endl; 92 104 } 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 } 93 134 } -
code/branches/core7/src/libraries/core/module/PluginManager.h
r10552 r10580 48 48 void findPlugins(); 49 49 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); 52 56 53 57 private: 54 58 std::map<std::string, Plugin*> plugins_; 59 std::map<std::string, PluginReference*> references_; // references that were created by console command 55 60 56 61 static PluginManager* singletonPtr_s; -
code/branches/core7/src/orxonox/Level.cc
r10579 r10580 35 35 #include "core/XMLFile.h" 36 36 #include "core/XMLPort.h" 37 #include "core/module/PluginReference.h" 37 38 38 39 #include "infos/PlayerInfo.h" … … 65 66 if (this->xmlfile_) 66 67 Loader::getInstance().unload(this->xmlfile_); 68 69 this->unloadPlugins(); 67 70 } 68 71 } … … 72 75 SUPER(Level, XMLPort, xmlelement, mode); 73 76 77 XMLPortParam(Level, "plugins", setPluginsString, getPluginsString, xmlelement, mode); 74 78 XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 75 79 … … 106 110 Template::getTemplate(*it)->applyOn(this); 107 111 } 112 } 113 114 void Level::setPluginsString(const std::string& pluginsString) 115 { 116 // unload old plugins 117 this->unloadPlugins(); 118 119 // load new plugins 120 this->pluginsString_ = pluginsString; 121 SubString tokens(pluginsString, ","); 122 for (size_t i = 0; i < tokens.size(); ++i) 123 this->plugins_.push_back(new PluginReference(tokens[i])); 124 } 125 126 void Level::unloadPlugins() 127 { 128 // use destroyLater() - this ensures that plugins are not unloaded too early. 129 // Note: When a level gets unloaded, the Level object is usually the last object that gets destroyed. This is because all other 130 // objects inside a level have a StrongPtr (in BaseObject) that references the Level object. This means that the Level 131 // object is only destroyed, when all StrongPtrs that pointed to it were destroyed. But at the time when the last StrongPtr 132 // is destroyed, the other object is not yet fully destroyed because the StrongPtr is destroyed in ~BaseObject (and this 133 // means that e.g. ~Identifiable was not yet called for this object). This means that technically there are still other 134 // objects alive when ~Level is called. This is the reason why we cannot directly destroy() the Plugins - instead we need 135 // to call destroyLater() to ensure that no instances from this plugin exist anymore. 136 for (std::list<PluginReference*>::iterator it = this->plugins_.begin(); it != this->plugins_.end(); ++it) 137 (*it)->destroyLater(); 138 this->plugins_.clear(); 108 139 } 109 140 -
code/branches/core7/src/orxonox/Level.h
r9667 r10580 65 65 // MeshLodInformation* getLodInfo(unsigned int index) const; 66 66 67 void setPluginsString(const std::string& pluginsString); 68 inline const std::string& getPluginsString() const 69 { return this->pluginsString_; } 70 71 void unloadPlugins(); 72 67 73 void setGametypeString(const std::string& gametype); 68 74 inline const std::string& getGametypeString() const … … 70 76 71 77 void networkcallback_applyXMLFile(); 78 79 std::string pluginsString_; 80 std::list<PluginReference*> plugins_; 72 81 73 82 std::string gametype_;
Note: See TracChangeset
for help on using the changeset viewer.