From a6ff654ae37ca372d785c1e155fbfe67a3a25fed Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 20 Dec 2012 20:59:11 +0100 Subject: removing plugins for gold version (for mxe cross compiling) --- src/plugins/plugininterface.h | 65 ------------------- src/plugins/pluginloader.cpp | 124 ----------------------------------- src/plugins/pluginloader.h | 87 ------------------------- src/plugins/pluginmanager.cpp | 132 -------------------------------------- src/plugins/pluginmanager.h | 87 ------------------------- src/plugins/test/CMakeLists.txt | 15 ----- src/plugins/test/colobot.ini | 3 - src/plugins/test/manager_test.cpp | 31 --------- 8 files changed, 544 deletions(-) delete mode 100644 src/plugins/plugininterface.h delete mode 100644 src/plugins/pluginloader.cpp delete mode 100644 src/plugins/pluginloader.h delete mode 100644 src/plugins/pluginmanager.cpp delete mode 100644 src/plugins/pluginmanager.h delete mode 100644 src/plugins/test/CMakeLists.txt delete mode 100644 src/plugins/test/colobot.ini delete mode 100644 src/plugins/test/manager_test.cpp (limited to 'src/plugins') diff --git a/src/plugins/plugininterface.h b/src/plugins/plugininterface.h deleted file mode 100644 index 838dbfd..0000000 --- a/src/plugins/plugininterface.h +++ /dev/null @@ -1,65 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -/** - * \file plugins/plugininterface.h - * \brief Generic plugin interface - */ - -#pragma once - - -#include - - -#define PLUGIN_INTERFACE(class_type) \ - static class_type* Plugin##class_type; \ - extern "C" void InstallPluginEntry() { Plugin##class_type = new class_type(); Plugin##class_type->InstallPlugin(); } \ - extern "C" bool UninstallPluginEntry(std::string &reason) { bool result = Plugin##class_type->UninstallPlugin(reason); \ - if (!result) \ - return false; \ - delete Plugin##class_type; \ - return true; } \ - extern "C" CPluginInterface* GetPluginInterfaceEntry() { return static_cast(Plugin##class_type); } - - -/** - * \class CPluginInterface - * - * \brief Generic plugin interface. All plugins that will be managed by plugin manager have to derive from this class. - * - */ -class CPluginInterface { - public: - /** Function to get plugin name or description - * \return returns plugin name - */ - inline virtual std::string PluginName() { return "abc"; } - - /** Function to get plugin version. 1 means version 0.01, 2 means 0.02 etc. - * \return number indicating plugin version - */ - inline virtual int PluginVersion() { return 0; } - - /** Function to initialize plugin - */ - inline virtual void InstallPlugin() {} - - /** Function called before removing plugin - */ - inline virtual bool UninstallPlugin(std::string &) { return true; } -}; - diff --git a/src/plugins/pluginloader.cpp b/src/plugins/pluginloader.cpp deleted file mode 100644 index bd0c8be..0000000 --- a/src/plugins/pluginloader.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012 Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - - -#include "plugins/pluginloader.h" - - -CPluginLoader::CPluginLoader(std::string filename) -{ - mInterface = nullptr; - mFilename = filename; - mLoaded = false; -} - - -std::string CPluginLoader::GetName() -{ - if (mLoaded) - return mInterface->PluginName(); - return "(not loaded)"; -} - - -int CPluginLoader::GetVersion() -{ - if (mLoaded) - return mInterface->PluginVersion(); - return 0; -} - - -bool CPluginLoader::IsLoaded() -{ - return mLoaded; -} - - -bool CPluginLoader::UnloadPlugin() -{ - if (!mLoaded) { - GetLogger()->Warn("Plugin %s is not loaded.\n"); - return true; - } - - bool (*uninstall)(std::string &) = reinterpret_cast( lt_dlsym(mHandle, "UninstallPluginEntry") ); - if (!uninstall) { - GetLogger()->Error("Error getting UninstallPluginEntry for plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); - return false; - } - - std::string reason; - if (!uninstall(reason)) { - GetLogger()->Error("Could not unload plugin %s: %s\n", mFilename.c_str(), reason.c_str()); - return false; - } - - lt_dlclose(mHandle); - mLoaded = false; - return true; -} - - -bool CPluginLoader::LoadPlugin() -{ - if (mFilename.length() == 0) { - GetLogger()->Warn("No plugin filename specified.\n"); - return false; - } - - mHandle = lt_dlopenext(mFilename.c_str()); - if (!mHandle) { - GetLogger()->Error("Error loading plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); - return false; - } - - void (*install)() = reinterpret_cast( lt_dlsym(mHandle, "InstallPluginEntry") ); - if (!install) { - GetLogger()->Error("Error getting InstallPluginEntry for plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); - return false; - } - - CPluginInterface* (*getInterface)() = reinterpret_cast( lt_dlsym(mHandle, "GetPluginInterfaceEntry") ); - - if (!getInterface) { - GetLogger()->Error("Error getting GetPluginInterfaceEntry for plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); - return false; - } - - install(); - mInterface = getInterface(); - mLoaded = true; - return true; -} - - -bool CPluginLoader::SetFilename(std::string filename) -{ - bool ok = true; - if (mLoaded) - ok = UnloadPlugin(); - - if (ok) - mFilename = filename; - return ok; -} - - -std::string CPluginLoader::GetFilename() -{ - return mFilename; -} diff --git a/src/plugins/pluginloader.h b/src/plugins/pluginloader.h deleted file mode 100644 index e8c2c73..0000000 --- a/src/plugins/pluginloader.h +++ /dev/null @@ -1,87 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -/** - * \file plugins/pluginloader.h - * \brief Plugin loader interface - */ - -#pragma once - - -#include "common/logger.h" - -#include "plugins/plugininterface.h" - -#include -#include - - -/** - * \class CPluginLoader - * - * \brief Plugin loader interface. Plugin manager uses this class to load plugins. - * - */ -class CPluginLoader { - public: - /** Class contructor - * \param filename plugin filename - */ - CPluginLoader(std::string filename); - - /** Function to get plugin name or description - * \return returns plugin name - */ - std::string GetName(); - - /** Function to get plugin version - * \return returns plugin version - */ - int GetVersion(); - - /** Function to unload plugin - * \return returns true on success - */ - bool UnloadPlugin(); - - /** Function to load plugin - * \return returns true on success - */ - bool LoadPlugin(); - - /** Function to check if plugin is loaded - * \return returns true if plugin is loaded - */ - bool IsLoaded(); - - /** Function to set plugin filename - * \return returns true on success. Action can fail if plugin was loaded and cannot be unloaded - */ - bool SetFilename(std::string); - - /** Function to get plugin filename - * \return returns plugin filename - */ - std::string GetFilename(); - - - private: - CPluginInterface* mInterface; - std::string mFilename; - lt_dlhandle mHandle; - bool mLoaded; -}; diff --git a/src/plugins/pluginmanager.cpp b/src/plugins/pluginmanager.cpp deleted file mode 100644 index f4dbcdb..0000000 --- a/src/plugins/pluginmanager.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012 Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - - -#include "plugins/pluginmanager.h" - - -template<> CPluginManager* CSingleton::mInstance = nullptr; - - -CPluginManager::CPluginManager() -{ - lt_dlinit(); -} - - -CPluginManager::~CPluginManager() -{ - UnloadAllPlugins(); - lt_dlexit(); -} - - - -void CPluginManager::LoadFromProfile() -{ - GetLogger()->Info("Trying to load from profile...\n"); - std::vector< std::string > dirs = GetProfile().GetLocalProfileSection("Plugins", "Path"); - std::vector< std::string > plugins = GetProfile().GetLocalProfileSection("Plugins", "File"); - - GetLogger()->Info("Path %d, files %d\n", dirs.size(), plugins.size()); - for (std::string dir : dirs) - m_folders.insert(dir); - - for (std::string plugin : plugins) { - GetLogger()->Info("Trying to load plugin %s...\n", plugin.c_str()); - LoadPlugin(plugin); - } -} - - -bool CPluginManager::LoadPlugin(std::string filename) -{ - bool result = false; - CPluginLoader *loader = new CPluginLoader(""); - for (std::string dir : m_folders) { - loader->SetFilename(dir + "/" + filename); - result = loader->LoadPlugin(); - if (result) { - GetLogger()->Info("Plugin %s (%s) version %0.2f loaded!\n", filename.c_str(), loader->GetName().c_str(), loader->GetVersion() / 100.0f); - m_plugins.push_back(loader); - break; - } - } - return result; -} - - -bool CPluginManager::UnloadPlugin(std::string filename) -{ - std::vector::iterator it; - GetLogger()->Info("Trying to unload plugin %s...\n", filename.c_str()); - for (it = m_plugins.begin(); it != m_plugins.end(); it++) { - CPluginLoader *plugin = *it; - if (NameEndsWith(plugin->GetFilename(), filename)) { - m_plugins.erase(it); - plugin->UnloadPlugin(); - delete plugin; - return true; - } - } - return false; -} - - -bool CPluginManager::AddSearchDirectory(std::string dir) -{ - m_folders.insert(dir); - return true; -} - - -bool CPluginManager::RemoveSearchDirectory(std::string dir) -{ - m_folders.erase(dir); - return false; -} - - -bool CPluginManager::UnloadAllPlugins() -{ - bool allOk = true; - std::vector::iterator it; - for (it = m_plugins.begin(); it != m_plugins.end(); it++) { - CPluginLoader *plugin = *it; - bool result; - - GetLogger()->Info("Trying to unload plugin %s (%s)...\n", plugin->GetFilename().c_str(), plugin->GetName().c_str()); - result = plugin->UnloadPlugin(); - if (!result) { - allOk = false; - continue; - } - delete plugin; - m_plugins.erase(it); - } - - return allOk; -} - - -bool CPluginManager::NameEndsWith(std::string filename, std::string ending) -{ - if (filename.length() > ending.length()) { - std::string fileEnd = filename.substr(filename.length() - ending.length()); - return (fileEnd == ending); - } - return false; -} diff --git a/src/plugins/pluginmanager.h b/src/plugins/pluginmanager.h deleted file mode 100644 index 2798483..0000000 --- a/src/plugins/pluginmanager.h +++ /dev/null @@ -1,87 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -/** - * \file plugins/pluginmanager.h - * \brief Plugin manager class. - */ - -#pragma once - - -#include "common/logger.h" -#include "common/profile.h" - -#include "common/singleton.h" - -#include "plugins/pluginloader.h" - -#include -#include -#include - - -/** - * \class CPluginManager - * - * \brief Plugin manager class. Plugin manager can load plugins from colobot.ini or manually specified files. - * - */ -class CPluginManager : public CSingleton { - public: - CPluginManager(); - ~CPluginManager(); - - /** Function loads plugin list and path list from profile file - */ - void LoadFromProfile(); - - /** Function loads specified plugin - * \param filename plugin filename - * \return returns true on success - */ - bool LoadPlugin(std::string filename); - - /** Function unloads specified plugin - * \param filename plugin filename - * \return returns true on success - */ - bool UnloadPlugin(std::string filename); - - /** Function adds path to be checked when searching for plugin file. If path was already added it will be ignored - * \param dir plugin search path - * \return returns true on success - */ - bool AddSearchDirectory(std::string dir); - - /** Function removes path from list - * \param dir plugin search path - * \return returns true on success - */ - bool RemoveSearchDirectory(std::string dir); - - /** Function tries to unload all plugins - * \return returns true on success - */ - bool UnloadAllPlugins(); - - private: - bool NameEndsWith(std::string, std::string); - - std::set< std::string > m_folders; - std::vector m_plugins; -}; - diff --git a/src/plugins/test/CMakeLists.txt b/src/plugins/test/CMakeLists.txt deleted file mode 100644 index 31b4163..0000000 --- a/src/plugins/test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -rdynamic") -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -add_executable(manager_test manager_test.cpp ../../common/logger.cpp ../../common/profile.cpp ../../common/iman.cpp ../pluginmanager.cpp ../pluginloader.cpp) - -include_directories(".") -include_directories("../../") -include_directories("../../../") - -target_link_libraries(manager_test ${LTDL_LIBRARY}) diff --git a/src/plugins/test/colobot.ini b/src/plugins/test/colobot.ini deleted file mode 100644 index 08956be..0000000 --- a/src/plugins/test/colobot.ini +++ /dev/null @@ -1,3 +0,0 @@ -[Plugins] -Path=. -File=libopenalsound.so diff --git a/src/plugins/test/manager_test.cpp b/src/plugins/test/manager_test.cpp deleted file mode 100644 index d921c1d..0000000 --- a/src/plugins/test/manager_test.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -#include - - -int main() { - new CLogger(); - new CProfile(); - new CInstanceManager(); - CPluginManager *mgr = new CPluginManager(); - - if (!GetProfile()->InitCurrentDirectory()) { - GetLogger()->Error("Config not found!\n"); - return 1; - } - - mgr->LoadFromProfile(); - CSoundInterface *sound = static_cast(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND)); - - if (!sound) { - GetLogger()->Error("Sound not loaded!\n"); - return 2; - } - - sound->Create(true); - mgr->UnloadAllPlugins(); - - return 0; -} -- cgit v1.2.3-1-g7c22