Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
module.c
Go to the documentation of this file.
1/*
2 * This file is part of darktable,
3 * Copyright (C) 2017 Tobias Ellinghaus.
4 * Copyright (C) 2020-2021 Pascal Obry.
5 * Copyright (C) 2021 Ralf Brown.
6 * Copyright (C) 2022 Martin Bařinka.
7 * Copyright (C) 2023 Alynx Zhou.
8 * Copyright (C) 2023, 2025-2026 Aurélien PIERRE.
9 *
10 * darktable is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * darktable is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "common/darktable.h"
25#include <stdlib.h>
26#include <string.h>
27#include <gmodule.h>
28#include <glib/gi18n.h>
29
30#include "config.h"
32#include "common/module.h"
33#include "control/conf.h"
34#include "gui/splash.h"
35
36GList *dt_module_load_modules(const char *subdir, size_t module_size,
37 int (*load_module_so)(void *module, const char *libname, const char *plugin_name),
38 void (*init_module)(void *module),
39 gint (*sort_modules)(gconstpointer a, gconstpointer b))
40{
41 GList *plugin_list = NULL;
42 char moduledir[PATH_MAX] = { 0 };
43 const gchar *dir_name;
44 dt_loc_get_moduledir(moduledir, sizeof(moduledir));
45 g_strlcat(moduledir, subdir, sizeof(moduledir));
46 GDir *dir = g_dir_open(moduledir, 0, NULL);
47 if(IS_NULL_PTR(dir)) return NULL;
48 const int name_offset = strlen(SHARED_MODULE_PREFIX),
49 name_end = strlen(SHARED_MODULE_PREFIX) + strlen(SHARED_MODULE_SUFFIX);
50 while((dir_name = g_dir_read_name(dir)))
51 {
52 // get lib*.so
53 if(!g_str_has_prefix(dir_name, SHARED_MODULE_PREFIX)) continue;
54 if(!g_str_has_suffix(dir_name, SHARED_MODULE_SUFFIX)) continue;
55 char *plugin_name = g_strndup(dir_name + name_offset, strlen(dir_name) - name_end);
56 void *module = calloc(1, module_size);
57 gchar *libname = g_module_build_path(moduledir, plugin_name);
58
59 int res = 1;
60
61 // Get the preference to enable/disable the plugin.
62 gchar *pref_line = g_strdup_printf("%s/%s/enable", subdir, plugin_name);
63 int load;
64
65 if(dt_conf_key_exists(pref_line))
66 {
67 // Disable plugins only if we have an explicit rule saying so.
68 load = dt_conf_get_bool(pref_line);
69 // fprintf(stdout, "%s exists : %i\n", pref_line, load);
70 }
71 else
72 {
73 // If no rule, then enable by default.
74 load = TRUE;
75 dt_conf_set_bool(pref_line, TRUE);
76 // fprintf(stdout, "%s does NOT exist\n", pref_line);
77 }
78
79 dt_free(pref_line);
80
81 if(load) res = load_module_so(module, libname, plugin_name);
82 // if(res) fprintf(stdout, "Plugin %s/%s NOT loaded\n", subdir, plugin_name);
83
84 dt_free(plugin_name);
85 dt_free(libname);
86
87 if(res)
88 {
89 dt_free(module);
90 continue;
91 }
92
93 plugin_list = g_list_prepend(plugin_list, module);
94
95 if(init_module) init_module(module);
96 }
97 g_dir_close(dir);
98
99 if(sort_modules)
100 plugin_list = g_list_sort(plugin_list, sort_modules);
101 else
102 plugin_list = g_list_reverse(plugin_list); // list was built in reverse order, so un-reverse it
103
104 return plugin_list;
105}
106
107// clang-format off
108// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
109// vim: shiftwidth=2 expandtab tabstop=2 cindent
110// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
111// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define SHARED_MODULE_SUFFIX
#define SHARED_MODULE_PREFIX
void dt_conf_set_bool(const char *name, int val)
int dt_conf_get_bool(const char *name)
int dt_conf_key_exists(const char *key)
#define dt_free(ptr)
Definition darktable.h:456
#define PATH_MAX
Definition darktable.h:1062
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
void dt_loc_get_moduledir(char *moduledir, size_t bufsize)
GList * dt_module_load_modules(const char *subdir, size_t module_size, int(*load_module_so)(void *module, const char *libname, const char *plugin_name), void(*init_module)(void *module), gint(*sort_modules)(gconstpointer a, gconstpointer b))
Definition module.c:36