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