00001
00013 #include "SO3Plugin.h"
00014 #include <Ogre.h>
00015
00016 namespace SO3
00017 {
00018
00019 SPlugin::SPlugin(const std::string& pluginName)
00020 {
00021 pluginInfos.fileName = pluginName;
00022 pluginInfos.name = "Unknow";
00023 pluginInfos.author = "Unknow";
00024 pluginInfos.authorEmail = "Unknow";
00025 pluginInfos.description = "Unknow";
00026 pluginInfos.version = "Unknow";
00027 pluginInfos.urlLink = "Unknow";
00028 std::string tempPluginName = pluginName;
00029 #if SO3_PLATFORM == SO3_PLATFORM_LINUX
00030
00031 if (tempPluginName.substr(tempPluginName.length() - 3, 3) != ".so")
00032 tempPluginName = tempPluginName + ".so";
00033 #elif SO3_PLATFORM == SO3_PLATFORM_WINDOWS
00034
00035 if (tempPluginName.substr(tempPluginName.length() - 4, 4) != ".dll")
00036 tempPluginName = tempPluginName + ".dll";
00037
00038 #ifdef SO3_DEBUG
00039
00040 if (tempPluginName.substr(tempPluginName.length() - 6, 2) != "_d")
00041 tempPluginName.insert(tempPluginName.length() - 4, "_d");
00042 #endif
00043 #endif
00044 pluginInfos.fileName = tempPluginName;
00045 isLoaded = false;
00046 instanceId = NULL;
00047 }
00048
00049 SPlugin::~SPlugin()
00050 {
00051 if(isLoaded)
00052 Unload();
00053 }
00054
00055 void SPlugin::Load()
00056 {
00057 typedef SPluginInfos (*Informations)(void);
00058 SPluginInfos infos;
00059
00060 Ogre::LogManager::getSingleton().logMessage("Loading SO3 plugin \"" + pluginInfos.fileName + "\"", Ogre::LML_CRITICAL);
00061
00062 instanceId = (SO3_PLUGIN_INSTANCE)SO3_PLUGIN_LOAD(pluginInfos.fileName.c_str());
00063 if(instanceId)
00064 {
00065 void* test = 0;
00066 test = this->GetSymbol("SO3_Infos");
00067 if (!test)
00068 {
00069 Ogre::LogManager::getSingleton().logMessage("Symbol \"Infos\" not found for the plugin", Ogre::LML_CRITICAL);
00070 }
00071 else
00072 {
00073 Informations fonctionInfos = (Informations)this->GetSymbol("SO3_Infos");
00074 infos = fonctionInfos();
00075 pluginInfos.name = infos.name;
00076 pluginInfos.author = infos.author;
00077 pluginInfos.authorEmail = infos.authorEmail;
00078 pluginInfos.description = infos.description;
00079 pluginInfos.version = infos.version;
00080 pluginInfos.urlLink = infos.urlLink ;
00081
00082 Ogre::LogManager::getSingleton().logMessage("Plugin name: " + pluginInfos.name);
00083 Ogre::LogManager::getSingleton().logMessage("Version: " + pluginInfos.version);
00084 Ogre::LogManager::getSingleton().logMessage("Description: " + pluginInfos.description);
00085 Ogre::LogManager::getSingleton().logMessage("Author: " + pluginInfos.author);
00086 Ogre::LogManager::getSingleton().logMessage("Author E-mail: " + pluginInfos.authorEmail);
00087 Ogre::LogManager::getSingleton().logMessage("Url link: " + pluginInfos.urlLink);
00088 }
00089 Ogre::LogManager::getSingleton().logMessage("Loading successfull.", Ogre::LML_CRITICAL);
00090 isLoaded = true;
00091 }
00092 else
00093 {
00094 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot load plugin \"" + pluginInfos.fileName + "\". System error: " + SO3_PLUGIN_ERROR(), "SPlugin::Load");
00095 }
00096 }
00097
00098 void SPlugin::Unload()
00099 {
00100 if (isLoaded)
00101 {
00102 Ogre::LogManager::getSingleton().logMessage("Unloading plugin \"" + pluginInfos.fileName + "\"", Ogre::LML_CRITICAL);
00103
00104 if(SO3_PLUGIN_UNLOAD(instanceId))
00105 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Can not unload SO3 plugin \"" + pluginInfos.fileName + "\". System error: " + SO3_PLUGIN_ERROR(), "SPlugin::Unload");
00106 }
00107 isLoaded = false;
00108 }
00109
00110 bool SPlugin::IsLoaded()
00111 {
00112 return isLoaded;
00113 }
00114
00115 void* SPlugin::GetSymbol(const char* symbolName) const throw()
00116 {
00117 return SO3_PLUGIN_GET_SYMBOL(instanceId, symbolName);
00118 }
00119
00120 SPluginInfos SPlugin::GetInfo()
00121 {
00122 return pluginInfos;
00123 }
00124
00125 }