Project

General

Profile

SO3Engine
SO3PluginManager.cpp
Go to the documentation of this file.
1
6
7namespace Ogre
8{
9 //Singleton instance
10 template<> SO3::SPluginManager* Ogre::Singleton<SO3::SPluginManager>::msSingleton = 0;
11}
12
13namespace SO3
14{
15
17{
18 return msSingleton;
19}
20
22{
23 assert(msSingleton);
24 return (*msSingleton);
25}
26
30
31SPlugin* SPluginManager::Load(const std::string& fileName)
32{
33 SPlugin* plugin = new SPlugin(fileName);
34 plugin->Load();
35 pluginList.insert(SPluginList::value_type(plugin->GetInfo().name, plugin));
36
37 if (plugin)
38 {
39 if (plugin->IsLoaded())
40 {
41 SO3_START_PLUGIN pFunc = (SO3_START_PLUGIN)plugin->GetSymbol("SO3_Start");
42
43 if (!pFunc)
44 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot find the \"Start\" symbol in SO3 plugin " + plugin->GetInfo().name, "SPluginManager::Load");
45
46 pFunc();
47 }
48 }
49 return plugin;
50}
51
53{
54 SPluginList::iterator i = pluginList.find(loadedPlugin->GetInfo().name);
55 if (i != pluginList.end())
56 {
57 // Call plugin shutdown
58 SO3_STOP_PLUGIN pFunc = (SO3_STOP_PLUGIN)(i->second)->GetSymbol("SO3_Stop");
59
60 if (!pFunc)
61 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot find the \"Stop\" symbol in SO3 plugin " + (i->second)->GetInfo().name, "SPluginManager::Unload");
62
63 pFunc();
64 pluginList.erase(i);
65 }
66 delete loadedPlugin;
67}
68
69void SPluginManager::Unload(const std::string& pluginName)
70{
71 SPluginList::iterator i = pluginList.find(pluginName);
72 if (i != pluginList.end())
73 {
74 Unload(i->second);
75 }
76}
77
79{
80 std::vector<std::string> list = GetPluginList();
81 int nbPlugins = list.size()-1;
82
83 for(int it = nbPlugins; it >= 0; it--)
84 {
85 Unload(list[it]);
86 }
87 pluginList.clear();
88}
89
90std::vector<std::string> SPluginManager::GetPluginList()
91{
92 std::vector<std::string> list;
93 SPluginList::iterator i = pluginList.begin();
94
95 while (i != pluginList.end())
96 {
97 list.push_back(i->first);
98 i++;
99 }
100
101 return list;
102}
103
104}
virtual void * GetSymbol(const char *symbolName) const
virtual void Load()
Definition SO3Plugin.cpp:55
bool IsLoaded()
SPluginInfos GetInfo()
void Unload(SPlugin *loadedPlugin)
std::vector< std::string > GetPluginList()
static SPluginManager * getSingletonPtr()
static SPluginManager & getSingleton()
SPlugin * Load(const std::string &fileName)
void(* SO3_START_PLUGIN)(void)
Definition SO3Plugin.h:24
void(* SO3_STOP_PLUGIN)(void)
Definition SO3Plugin.h:25
std::string name
Definition SO3Plugin.h:16