From f1d1cdceee3ec49546ba800a1b53a2dfb9c21e11 Mon Sep 17 00:00:00 2001 From: erihel Date: Thu, 9 Aug 2012 21:21:14 +0200 Subject: Changes after merge --- src/plugins/plugin.cpp | 97 ---------------------------------------- src/plugins/plugin.h | 46 ------------------- src/plugins/pluginloader.cpp | 97 ++++++++++++++++++++++++++++++++++++++++ src/plugins/pluginloader.h | 46 +++++++++++++++++++ src/plugins/test/CMakeLists.txt | 2 +- src/plugins/test/plugin_test.cpp | 4 +- src/sound/sound.h | 4 +- 7 files changed, 148 insertions(+), 148 deletions(-) delete mode 100644 src/plugins/plugin.cpp delete mode 100644 src/plugins/plugin.h create mode 100644 src/plugins/pluginloader.cpp create mode 100644 src/plugins/pluginloader.h diff --git a/src/plugins/plugin.cpp b/src/plugins/plugin.cpp deleted file mode 100644 index ca0fe0e..0000000 --- a/src/plugins/plugin.cpp +++ /dev/null @@ -1,97 +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/. - -// plugin.cpp - - -#include "plugin.h" - - -CPlugin::CPlugin(std::string filename) -{ - mInterface = nullptr; - mFilename = filename; - mLoaded = false; -} - - -char* CPlugin::GetName() -{ - if (mLoaded) - return mInterface->PluginName(); - return nullptr; -} - - -int CPlugin::GetVersion() -{ - if (mLoaded) - return mInterface->PluginVersion(); - return 0; -} - - -bool CPlugin::IsLoaded() -{ - return mLoaded; -} - - -bool CPlugin::UnloadPlugin() -{ - if (!mLoaded) { - GetLogger()->Warn("Plugin %s is not loaded.\n"); - return true; - } - - void (*uninstall)() = (void (*)()) lt_dlsym(mHandle, "UninstallPluginEntry"); - if (!uninstall) { - GetLogger()->Error("Error getting UninstallPluginEntry for plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); - return false; - } - - lt_dlclose(mHandle); - mLoaded = false; - return true; -} - - -bool CPlugin::LoadPlugin() -{ - 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)() = (void (*)()) 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)() = (CPluginInterface* (*)()) 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; -} diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h deleted file mode 100644 index e7d4b12..0000000 --- a/src/plugins/plugin.h +++ /dev/null @@ -1,46 +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/. - -// plugin.h - - -#pragma once - -#include -#include - -#include - -#include "plugininterface.h" - - -class CPlugin { - public: - CPlugin(std::string filename); - - char* GetName(); - int GetVersion(); - bool UnloadPlugin(); - bool LoadPlugin(); - bool IsLoaded(); - - - private: - CPluginInterface* mInterface; - std::string mFilename; - lt_dlhandle mHandle; - bool mLoaded; -}; diff --git a/src/plugins/pluginloader.cpp b/src/plugins/pluginloader.cpp new file mode 100644 index 0000000..adceb6b --- /dev/null +++ b/src/plugins/pluginloader.cpp @@ -0,0 +1,97 @@ +// * 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/. + +// pluginloader.cpp + + +#include "pluginloader.h" + + +CPluginLoader::CPluginLoader(std::string filename) +{ + mInterface = nullptr; + mFilename = filename; + mLoaded = false; +} + + +char* CPluginLoader::GetName() +{ + if (mLoaded) + return mInterface->PluginName(); + return nullptr; +} + + +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; + } + + void (*uninstall)() = (void (*)()) lt_dlsym(mHandle, "UninstallPluginEntry"); + if (!uninstall) { + GetLogger()->Error("Error getting UninstallPluginEntry for plugin %s: %s\n", mFilename.c_str(), lt_dlerror()); + return false; + } + + lt_dlclose(mHandle); + mLoaded = false; + return true; +} + + +bool CPluginLoader::LoadPlugin() +{ + 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)() = (void (*)()) 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)() = (CPluginInterface* (*)()) 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; +} diff --git a/src/plugins/pluginloader.h b/src/plugins/pluginloader.h new file mode 100644 index 0000000..d9ee041 --- /dev/null +++ b/src/plugins/pluginloader.h @@ -0,0 +1,46 @@ +// * 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/. + +// pluginloader.h + + +#pragma once + +#include +#include + +#include + +#include "plugininterface.h" + + +class CPluginLoader { + public: + CPluginLoader(std::string filename); + + char* GetName(); + int GetVersion(); + bool UnloadPlugin(); + bool LoadPlugin(); + bool IsLoaded(); + + + private: + CPluginInterface* mInterface; + std::string mFilename; + lt_dlhandle mHandle; + bool mLoaded; +}; diff --git a/src/plugins/test/CMakeLists.txt b/src/plugins/test/CMakeLists.txt index 551daeb..5953468 100644 --- a/src/plugins/test/CMakeLists.txt +++ b/src/plugins/test/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8) set(CMAKE_BUILD_TYPE debug) set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0 -std=c++11 -rdynamic") -add_executable(plugin_test plugin_test.cpp ../../common/iman.cpp ../../common/logger.cpp ../plugin.cpp) +add_executable(plugin_test plugin_test.cpp ../../common/iman.cpp ../../common/logger.cpp ../pluginloader.cpp) # Change to DirectX SDK directory include_directories("../../") diff --git a/src/plugins/test/plugin_test.cpp b/src/plugins/test/plugin_test.cpp index 7175773..9aadfac 100644 --- a/src/plugins/test/plugin_test.cpp +++ b/src/plugins/test/plugin_test.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include int main() { @@ -14,7 +14,7 @@ int main() { lt_dlinit(); - CPlugin *plugin = new CPlugin("libopenalsound"); + CPluginLoader *plugin = new CPluginLoader("libopenalsound"); if (plugin->LoadPlugin()) { CSoundInterface *sound = static_cast(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND)); diff --git a/src/sound/sound.h b/src/sound/sound.h index d323918..f18a76a 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -26,7 +26,7 @@ #include -#include +#include #include @@ -148,7 +148,7 @@ enum SoundNext * @brief Sound plugin interface * */ -class CSoundInterface : public CPlugin +class CSoundInterface : public CPluginInterface { public: CSoundInterface() { -- cgit v1.2.3-1-g7c22