| 1 | // Aseprite |
| 2 | // Copyright (C) 2001-2018 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/modules.h" |
| 12 | |
| 13 | #include "app/modules/gui.h" |
| 14 | #include "app/modules/palettes.h" |
| 15 | |
| 16 | namespace app { |
| 17 | |
| 18 | struct Module { |
| 19 | const char *name; |
| 20 | int (*init)(); |
| 21 | void (*exit)(); |
| 22 | int reqs; |
| 23 | bool installed; |
| 24 | }; |
| 25 | |
| 26 | static Module module[] = |
| 27 | { |
| 28 | #define DEF_MODULE(name, reqs) \ |
| 29 | { #name, init_module_##name, exit_module_##name, (reqs), false } |
| 30 | |
| 31 | // This sorting is very important because last modules depend of |
| 32 | // first ones. |
| 33 | |
| 34 | DEF_MODULE(palette, 0), |
| 35 | #ifdef ENABLE_UI |
| 36 | DEF_MODULE(gui, REQUIRE_INTERFACE), |
| 37 | #endif |
| 38 | }; |
| 39 | |
| 40 | static int modules = sizeof(module) / sizeof(Module); |
| 41 | |
| 42 | LegacyModules::LegacyModules(int requirements) |
| 43 | { |
| 44 | for (int c=0; c<modules; c++) |
| 45 | if ((module[c].reqs & requirements) == module[c].reqs) { |
| 46 | LOG("MODS: Installing module: %s\n" , module[c].name); |
| 47 | |
| 48 | if ((*module[c].init)() < 0) |
| 49 | throw base::Exception("Error initializing module: %s" , |
| 50 | static_cast<const char*>(module[c].name)); |
| 51 | |
| 52 | module[c].installed = true; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | LegacyModules::~LegacyModules() |
| 57 | { |
| 58 | for (int c=modules-1; c>=0; c--) |
| 59 | if (module[c].installed) { |
| 60 | LOG("MODS: Unstalling module: %s\n" , module[c].name); |
| 61 | (*module[c].exit)(); |
| 62 | module[c].installed = false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace app |
| 67 | |