diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2025-01-12 14:23:01 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2025-01-12 14:23:01 (GMT) |
commit | baa854bfcc969022a00617b58a661e37f345cab5 (patch) | |
tree | 093d3ace4c2e1ad8fa37ce5e08723f768fffbada /src/plugins/self.h | |
parent | 0fdba5bd3e2c9ed913619990dbda7925867e46c5 (diff) |
Rewrite the plugin system.
Diffstat (limited to 'src/plugins/self.h')
-rw-r--r-- | src/plugins/self.h | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/src/plugins/self.h b/src/plugins/self.h index 4d5ddb0..78a3fe6 100644 --- a/src/plugins/self.h +++ b/src/plugins/self.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * self.h - définitions pour inclusion dans les différents greffons + * self.h - définitions de fonctionnalités facilitant la mise en place d'extensions natives * - * Copyright (C) 2020 Cyrille Bagard + * Copyright (C) 2020-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,72 +26,55 @@ #define _PLUGINS_SELF_H -#ifndef _PLUGINS_PLUGIN_H -# include "plugin.h" -#endif +#include <assert.h> +#include <malloc.h> + + +#include "plugin.h" #include "../common/compiler.h" -/* Facilitations de déclarations */ +/* Symboles principaux */ + +#define PLUGIN_CORE_SELF \ +static GPluginModule *_this_plugin = NULL; \ +static void chrysalide_plugin_set_self(GPluginModule *); \ +static void chrysalide_plugin_set_self(GPluginModule *plugin) \ +{ \ + assert(_this_plugin == NULL); \ + _this_plugin = plugin; \ +}; \ +__private GPluginModule *_chrysalide_plugin_get_self(void); \ +__private GPluginModule *_chrysalide_plugin_get_self(void) \ +{ \ + return _this_plugin; \ +}; + +#define NATIVE_PLUGIN_ENTRYPOINT(fc) \ +PLUGIN_CORE_SELF; \ +G_MODULE_EXPORT GPluginModule *get_chrysalide_plugin_instance(GModule *); \ +G_MODULE_EXPORT GPluginModule *get_chrysalide_plugin_instance(GModule *module) \ +{ \ + GPluginModule *result; /* Instance à retourner */ \ + result = fc(module); \ + chrysalide_plugin_set_self(result); \ + return result; \ +} + + +/* Spécifications */ #define CHRYSALIDE_WEBSITE(p) "https://www.chrysalide.re/" p -#define EMPTY_PG_LIST(name) \ - name = NULL, \ - name ## _count = 0 \ - -#define BUILD_PG_LIST(name, lst) \ - name = lst, \ - name ## _count = sizeof(lst) / sizeof(lst[0]) \ - -#define AL(...) BUILD_PG_LIST(.actions, ((plugin_action_t []){ __VA_ARGS__ })) - -#define RL(...) BUILD_PG_LIST(.required, ((char *[]){ __VA_ARGS__ })) - -#define NO_REQ EMPTY_PG_LIST(.required) - - -/* Composants d'interface */ - -#define PLUGIN_CORE_SELF \ -static GPluginModule *_this_plugin = NULL; \ -G_MODULE_EXPORT void chrysalide_plugin_set_self(GPluginModule *p); \ -G_MODULE_EXPORT void chrysalide_plugin_set_self(GPluginModule *p) { _this_plugin = p; }; \ -__private GPluginModule *_chrysalide_plugin_get_self(void); \ -__private GPluginModule *_chrysalide_plugin_get_self(void) { return _this_plugin; }; - -#define PLUGIN_CORE_PROPS(n, d, v, u, c) \ - \ - .magic = CHRYSALIDE_PLUGIN_MAGIC, \ - .abi_version = CURRENT_ABI_VERSION, \ - \ - .gtp_name = "G" n "Plugin", \ - .name = n, \ - .desc = d, \ - .version = v, \ - .url = u, \ - \ - .container = c - -#define DEFINE_CHRYSALIDE_PLUGIN(n, d, v, u, r, a) \ -PLUGIN_CORE_SELF \ -G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \ - PLUGIN_CORE_PROPS(n, d, v, u, false), \ - r, \ - a, \ -} +#define NO_REQ NULL, 0 -#define DEFINE_CHRYSALIDE_CONTAINER_PLUGIN(n, d, v, u, r, a) \ -PLUGIN_CORE_SELF \ -G_MODULE_EXPORT const plugin_interface _chrysalide_plugin = { \ - PLUGIN_CORE_PROPS(n, d, v, u, true), \ - r, \ - a, \ -} +#define BUILD_PG_LIST(lst) lst, sizeof(lst) / sizeof(lst[0]) + +#define REQ_LIST(...) BUILD_PG_LIST((const char *[]){ __VA_ARGS__ }) -/* Manipulations accélérées */ +/* Journalisation */ __private GPluginModule *_chrysalide_plugin_get_self(void); |