Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
module_api.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010 Henrik Andersson.
4 Copyright (C) 2010-2012, 2014 johannes hanika.
5 Copyright (C) 2012 Richard Wonka.
6 Copyright (C) 2014, 2016 Tobias Ellinghaus.
7 Copyright (C) 2016 Roman Lebedev.
8 Copyright (C) 2020-2021 Pascal Obry.
9 Copyright (C) 2021 Diederik Ter Rahe.
10 Copyright (C) 2022 Martin Baƙinka.
11
12 darktable is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 darktable is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with darktable. If not, see <http://www.gnu.org/licenses/>.
24*/
25#include <glib.h>
26
27#undef OPTIONAL
28#undef REQUIRED
29#undef DEFAULT
30
31#undef FULL_API_H
32
33#ifdef INCLUDE_API_FROM_MODULE_LOAD
34 #define OPTIONAL(return_type, function_name, ...) \
35 if(!g_module_symbol(module->module, #function_name, (gpointer) & (module->function_name))) \
36 module->function_name = NULL
37 #define REQUIRED(return_type, function_name, ...) \
38 if(!g_module_symbol(module->module, #function_name, (gpointer) & (module->function_name))) \
39 goto api_h_error
40 #define DEFAULT(return_type, function_name, ...) \
41 if(!g_module_symbol(module->module, #function_name, (gpointer) & (module->function_name))) \
42 module->function_name = default_ ## function_name
43
44 dt_print(DT_DEBUG_CONTROL, "[" INCLUDE_API_FROM_MODULE_LOAD "] loading `%s' from %s\n", module_name, libname);
45 module->module = g_module_open(libname, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
46 if(!module->module) goto api_h_error;
47 int (*version)();
48 if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer) & (version))) goto api_h_error;
49 if(version() != dt_version())
50 {
51 fprintf(stderr,
52 "[" INCLUDE_API_FROM_MODULE_LOAD "] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n",
53 libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()),
54 dt_version() < 0 ? "debug" : "opt");
55 goto api_h_error;
56 }
57 if(!g_module_symbol(module->module, "dt_module_mod_version", (gpointer) & (module->version))) goto api_h_error;
58
59 goto skip_error;
60api_h_error:
61 fprintf(stderr, "[" INCLUDE_API_FROM_MODULE_LOAD "] failed to open `%s': %s\n", module_name, g_module_error());
62 if(module->module) g_module_close(module->module);
63 return 1;
64skip_error:
65 #undef INCLUDE_API_FROM_MODULE_LOAD
66#elif defined(INCLUDE_API_FROM_MODULE_H)
67 #define OPTIONAL(return_type, function_name, ...) return_type (*function_name)(__VA_ARGS__)
68 #define REQUIRED(return_type, function_name, ...) return_type (*function_name)(__VA_ARGS__)
69 #define DEFAULT(return_type, function_name, ...) return_type (*function_name)(__VA_ARGS__)
70 int (*version)();
71 #undef INCLUDE_API_FROM_MODULE_H
72#elif defined(INCLUDE_API_FROM_MODULE_LOAD_BY_SO)
73 #define OPTIONAL(return_type, function_name, ...) module->function_name = so->function_name
74 #define REQUIRED(return_type, function_name, ...) module->function_name = so->function_name
75 #define DEFAULT(return_type, function_name, ...) module->function_name = so->function_name
76 #undef INCLUDE_API_FROM_MODULE_LOAD_BY_SO
77#else
78 #define FULL_API_H
79 #define OPTIONAL(return_type, function_name, ...) return_type function_name(__VA_ARGS__)
80 #define REQUIRED(return_type, function_name, ...) return_type function_name(__VA_ARGS__)
81 #define DEFAULT(return_type, function_name, ...) return_type function_name(__VA_ARGS__)
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 // these 2 functions are defined by DT_MODULE() macro.
86 #pragma GCC visibility push(default)
87 // returns the version of dt's module interface at the time this module was build
89 // returns the version of this module
91 #pragma GCC visibility pop
92 #ifdef __cplusplus
93 }
94 #endif
95#endif
96
97// clang-format off
98// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
99// vim: shiftwidth=2 expandtab tabstop=2 cindent
100// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
101// clang-format on
102
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1530
@ DT_DEBUG_CONTROL
Definition darktable.h:637
static int dt_version()
Definition darktable.h:153
#define INCLUDE_API_FROM_MODULE_LOAD
int dt_module_dt_version()
int dt_module_mod_version()