SO3Engine
SO3Plugin.cpp
Go to the documentation of this file.
1
13#include "SO3Utils/SO3Plugin.h"
14#include <Ogre.h>
15
16namespace SO3
17{
18
19SPlugin::SPlugin(const std::string& pluginName)
20{
21 pluginInfos.fileName = pluginName;
22 pluginInfos.name = "Unknow";
23 pluginInfos.author = "Unknow";
24 pluginInfos.authorEmail = "Unknow";
25 pluginInfos.description = "Unknow";
26 pluginInfos.version = "Unknow";
27 pluginInfos.urlLink = "Unknow";
28 std::string tempPluginName = pluginName;
29 #if SO3_PLATFORM == SO3_PLATFORM_LINUX
30 // Add ".so" extension if required.
31 if (tempPluginName.substr(tempPluginName.length() - 3, 3) != ".so")
32 tempPluginName = tempPluginName + ".so";
33 #elif SO3_PLATFORM == SO3_PLATFORM_WINDOWS
34 // Add ".dll" extension if required.
35 if (tempPluginName.substr(tempPluginName.length() - 4, 4) != ".dll")
36 tempPluginName = tempPluginName + ".dll";
37
38 #ifdef SO3_DEBUG
39 // Add "_d" for debug.
40 if (tempPluginName.substr(tempPluginName.length() - 6, 2) != "_d")
41 tempPluginName.insert(tempPluginName.length() - 4, "_d");
42 #endif
43 #endif
44 pluginInfos.fileName = tempPluginName;
45 isLoaded = false;
46 instanceId = NULL;
47}
48
50{
51 if(isLoaded)
52 Unload();
53}
54
56{
57 typedef SPluginInfos (*Informations)(void);
58 SPluginInfos infos;
59
60 Ogre::LogManager::getSingleton().logMessage("Loading SO3 plugin \"" + pluginInfos.fileName + "\"", Ogre::LML_CRITICAL);
61#ifndef SCOL_STATIC
62 instanceId = (SO3_PLUGIN_INSTANCE)SO3_PLUGIN_LOAD(pluginInfos.fileName.c_str());
63 if(instanceId)
64 {
65 void* test = 0;
66 test = this->GetSymbol("SO3_Infos");
67 if (!test)
68 {
69 Ogre::LogManager::getSingleton().logMessage("Symbol \"Infos\" not found for the plugin", Ogre::LML_CRITICAL);
70 }
71 else
72 {
73 Informations fonctionInfos = (Informations)this->GetSymbol("SO3_Infos");
74 infos = fonctionInfos();
75 pluginInfos.name = infos.name;
76 pluginInfos.author = infos.author;
77 pluginInfos.authorEmail = infos.authorEmail;
78 pluginInfos.description = infos.description;
79 pluginInfos.version = infos.version;
80 pluginInfos.urlLink = infos.urlLink ;
81
82 Ogre::LogManager::getSingleton().logMessage("Plugin name: " + pluginInfos.name);
83 Ogre::LogManager::getSingleton().logMessage("Version: " + pluginInfos.version);
84 Ogre::LogManager::getSingleton().logMessage("Description: " + pluginInfos.description);
85 Ogre::LogManager::getSingleton().logMessage("Author: " + pluginInfos.author);
86 Ogre::LogManager::getSingleton().logMessage("Author E-mail: " + pluginInfos.authorEmail);
87 Ogre::LogManager::getSingleton().logMessage("Url link: " + pluginInfos.urlLink);
88 }
89 Ogre::LogManager::getSingleton().logMessage("Loading successfull.", Ogre::LML_CRITICAL);
90 isLoaded = true;
91 }
92 else
93#endif
94 {
95 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot load plugin \"" + pluginInfos.fileName + "\". System error: " + SO3_PLUGIN_ERROR(), "SPlugin::Load");
96 }
97}
98
100{
101 if (isLoaded)
102 {
103 Ogre::LogManager::getSingleton().logMessage("Unloading plugin \"" + pluginInfos.fileName + "\"", Ogre::LML_CRITICAL);
104
105 if(SO3_PLUGIN_UNLOAD(instanceId))
106 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Can not unload SO3 plugin \"" + pluginInfos.fileName + "\". System error: " + SO3_PLUGIN_ERROR(), "SPlugin::Unload");
107 }
108 isLoaded = false;
109}
110
112{
113 return isLoaded;
114}
115
116void* SPlugin::GetSymbol(const char* symbolName) const throw()
117{
118 return SO3_PLUGIN_GET_SYMBOL(instanceId, symbolName);
119}
120
125
126}
virtual void * GetSymbol(const char *symbolName) const
virtual void Load()
Definition SO3Plugin.cpp:55
SPluginInfos pluginInfos
Definition SO3Plugin.h:33
bool isLoaded
Definition SO3Plugin.h:34
virtual void Unload()
Definition SO3Plugin.cpp:99
virtual ~SPlugin()
Definition SO3Plugin.cpp:49
bool IsLoaded()
SPlugin(const std::string &pluginName)
Definition SO3Plugin.cpp:19
SPluginInfos GetInfo()
SO3_PLUGIN_INSTANCE instanceId
Definition SO3Plugin.h:35
std::string version
Definition SO3Plugin.h:17
std::string author
Definition SO3Plugin.h:18
std::string description
Definition SO3Plugin.h:20
std::string fileName
Definition SO3Plugin.h:15
std::string urlLink
Definition SO3Plugin.h:21
std::string name
Definition SO3Plugin.h:16
std::string authorEmail
Definition SO3Plugin.h:19