forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.cpp
More file actions
64 lines (50 loc) · 1.41 KB
/
modules.cpp
File metadata and controls
64 lines (50 loc) · 1.41 KB
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
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/modules.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
namespace app {
struct Module {
const char *name;
int (*init)();
void (*exit)();
int reqs;
bool installed;
};
static Module module[] =
{
#define DEF_MODULE(name, reqs) \
{ #name, init_module_##name, exit_module_##name, (reqs), false }
// This sorting is very important because last modules depend of
// first ones.
DEF_MODULE(palette, 0),
DEF_MODULE(gui, REQUIRE_INTERFACE),
};
static int modules = sizeof(module) / sizeof(Module);
LegacyModules::LegacyModules(int requirements)
{
for (int c=0; c<modules; c++)
if ((module[c].reqs & requirements) == module[c].reqs) {
LOG("MODS: Installing module: %s\n", module[c].name);
if ((*module[c].init)() < 0)
throw base::Exception("Error initializing module: %s",
static_cast<const char*>(module[c].name));
module[c].installed = true;
}
}
LegacyModules::~LegacyModules()
{
for (int c=modules-1; c>=0; c--)
if (module[c].installed) {
LOG("MODS: Unstalling module: %s\n", module[c].name);
(*module[c].exit)();
module[c].installed = false;
}
}
} // namespace app