summaryrefslogtreecommitdiff
path: root/core/modules.cpp
blob: 50bb7ac0ccc0f440a6ef9c8052f7a317965b5efc (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
#include "commonheaders.h"

std::list<plugin*> plugins;

void load_modules()
{
    wxDir dir((wxChar*)"./plugins");
    if(!dir.IsOpened())
    {
        wxLogDebug("Plugins directory does not exists\n");
        return;
    }
    wxString filename;
#ifdef _WIN32
    if(!dir.GetFirst(&filename, (wxChar*)".dll", 0))
    {
        wxLogDebug("Plugins directory does not contain plugins\n");
        return;
    }

#else
    if(!dir.GetFirst(&filename, (wxChar*)".so", 0))
    {
        wxLogDebug("Plugins directory does not contain plugins\n");
        return;
    }

#endif
    do
    {
        wxDynamicLibrary *plug = new wxDynamicLibrary(filename);
        bool is_plugin = true;
        plugin::exported_functions_s *funcs = new plugin::exported_functions_s;
        if((funcs->Load = (load)plug->GetSymbol((wxChar*)"load")) == NULL)
            is_plugin = false;
        if((funcs->OnModulesLoaded = (on_modules_loaded)plug->GetSymbol((wxChar*)"on_modules_loaded")) == NULL)
            is_plugin = false;
        if((funcs->Unload = (unload)plug->GetSymbol((wxChar*)"unload")) == NULL)
            is_plugin = false;
        if((funcs->SetPluginInfo = (set_plugin_info)plug->GetSymbol((wxChar*)"set_plugin_info")) == NULL)
            is_plugin = false;
        if(!is_plugin)
        {
            delete plug;
            delete funcs;
            continue;
        }
        PLUGININFO *info = funcs->SetPluginInfo();
        plugins.push_back(new plugin(plug, info, funcs));
    }
    while(dir.GetNext(&filename));

}

plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs)
{
    if(lib)
        plug = lib;
    if(info)
        plugininfo = info;
    if(funcs)
        exported_funcs = funcs;
}