summaryrefslogtreecommitdiff
path: root/src/plugins/self.h
blob: 6a2e12d9886e7fc6594cec27213cd291d63dd76b (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

/* Chrysalide - Outil d'analyse de fichiers binaires
 * self.h - définitions pour inclusion dans les différents greffons
 *
 * Copyright (C) 2020 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef _PLUGINS_SELF_H
#define _PLUGINS_SELF_H


#include <config.h>


#ifndef _PLUGINS_PLUGIN_H
#   include "plugin.h"
#endif



/* Facilitations de déclarations */

#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 __private __attribute__((visibility("hidden")))

#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 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,                                                          \
}


/* Manipulations accélérées */

__private GPluginModule *_chrysalide_plugin_get_self(void);

#define log_plugin_simple_message(type, msg)                                        \
    do                                                                              \
    {                                                                               \
        GPluginModule *__this;                                                      \
        __this = _chrysalide_plugin_get_self();                                     \
        if (__this != NULL)                                                         \
            g_plugin_module_log_simple_message(__this, type, msg);                  \
        else                                                                        \
            log_simple_message(type, msg);                                          \
    }                                                                               \
    while (0)

#define log_plugin_variadic_message(type, msg, ...)                                 \
    do                                                                              \
    {                                                                               \
        GPluginModule *__this;                                                      \
        __this = _chrysalide_plugin_get_self();                                     \
        if (__this != NULL)                                                         \
            g_plugin_module_log_variadic_message(__this, type, msg, __VA_ARGS__);   \
        else                                                                        \
            log_variadic_message(type, msg, __VA_ARGS__);                           \
    }                                                                               \
    while (0)



#endif  /* _PLUGINS_SELF_H */