[10552] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "PluginManager.h" |
---|
| 30 | |
---|
| 31 | #include <fstream> |
---|
| 32 | |
---|
| 33 | #include "SpecialConfig.h" |
---|
| 34 | #include "Plugin.h" |
---|
| 35 | #include "core/ApplicationPaths.h" |
---|
| 36 | #include "core/command/ConsoleCommandIncludes.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | SetConsoleCommand("PluginManager", "load", &PluginManager::loadPlugin); |
---|
| 41 | SetConsoleCommand("PluginManager", "unload", &PluginManager::unloadPlugin); |
---|
| 42 | |
---|
| 43 | PluginManager* PluginManager::singletonPtr_s = 0; |
---|
| 44 | |
---|
| 45 | PluginManager::PluginManager() |
---|
| 46 | { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | PluginManager::~PluginManager() |
---|
| 50 | { |
---|
| 51 | for (std::map<std::string, Plugin*>::iterator it = this->plugins_.begin(); it != this->plugins_.end(); ++it) |
---|
| 52 | delete it->second; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void PluginManager::findPlugins() |
---|
| 56 | { |
---|
| 57 | const std::vector<std::string>& pluginPaths = ApplicationPaths::getInstance().getPluginPaths(); |
---|
| 58 | for (std::vector<std::string>::const_iterator it = pluginPaths.begin(); it != pluginPaths.end(); ++it) |
---|
| 59 | { |
---|
| 60 | std::string name; |
---|
| 61 | std::string libraryName = (*it); |
---|
| 62 | std::string filename = libraryName + + specialConfig::pluginExtension; |
---|
| 63 | std::ifstream infile(filename.c_str()); |
---|
| 64 | if (infile >> name) |
---|
| 65 | { |
---|
| 66 | orxout(internal_info) << "Found plugin with name '" << name << "' in module " << libraryName << endl; |
---|
| 67 | this->plugins_[name] = new Plugin(name, libraryName); |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | orxout(internal_warning) << "Could not read plugin file " << filename << endl; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /*static*/ void PluginManager::loadPlugin(const std::string& name) |
---|
| 77 | { |
---|
| 78 | Plugin* plugin = PluginManager::getInstance().plugins_[name]; |
---|
| 79 | if (plugin != NULL) |
---|
| 80 | plugin->load(); |
---|
| 81 | else |
---|
| 82 | orxout(internal_warning) << "Cannot find plugin with name " << name << endl; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /*static*/ void PluginManager::unloadPlugin(const std::string& name) |
---|
| 86 | { |
---|
| 87 | Plugin* plugin = PluginManager::getInstance().plugins_[name]; |
---|
| 88 | if (plugin != NULL) |
---|
| 89 | plugin->unload(); |
---|
| 90 | else |
---|
| 91 | orxout(internal_warning) << "Cannot find plugin with name " << name << endl; |
---|
| 92 | } |
---|
| 93 | } |
---|