blob: 6518825f9ce7dc43b2b529baa32b031a3ebae674 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include "commonheaders.h"
extern std::list<plugin*> plugins;
extern PLUGINLINK pluglink;
void load_modules()
{
std::string path = boost::filesystem::initial_path().directory_string(); //need some workaround for windows than called indirectly
path.append("/plugins");
logger.log(LM_DEBUG, "Loading plugins...\n");
boost::filesystem::path pth(path);
if(!boost::filesystem::is_directory(pth))
return;
boost::filesystem::directory_iterator i(pth), end;
while(i != end)
{
if(boost::filesystem::is_directory(*i)) //we not look in subdirectories
{
++i;
continue;
}
if(!boost::filesystem::status_known((*i).status())) //worng data
{
++i;
continue;
}
bool is_plugin = true;
plugin::exported_functions_s *funcs = new plugin::exported_functions_s;
ACE_DLL *dll = new ACE_DLL;
boost::filesystem::path pth = i->path();
if(dll->open(pth.string().c_str()) != -1)
{
if((funcs->Load = (load)dll->symbol("load")) == NULL)
is_plugin = false;
if((funcs->OnModulesLoaded = (on_modules_loaded)dll->symbol("on_modules_loaded")) == NULL)
is_plugin = false;
if((funcs->Unload = (unload)dll->symbol("unload")) == NULL)
is_plugin = false;
if((funcs->SetPluginInfo = (set_plugin_info)dll->symbol("set_plugin_info")) == NULL)
is_plugin = false;
}
if(!is_plugin)
{
delete funcs;
delete dll;
continue;
}
PLUGININFO *info = funcs->SetPluginInfo();
plugins.push_back(new plugin(dll, info, funcs));
++i;
}
}
void run_plugins()
{ //now for testing only
if(!plugins.empty())
{
std::list<plugin*>::iterator end = plugins.end();
for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i)
{
(*i)->get_exported_functions()->Load(&pluglink);
(*i)->get_exported_functions()->OnModulesLoaded();
}
}
}
plugin::plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs)
{
if(lib)
plug = lib;
if(info)
plugininfo = info;
if(funcs)
exported_funcs = funcs;
}
const plugin::exported_functions_s* plugin::get_exported_functions()
{
return exported_funcs;
}
|