21
21
#include "gwpluginsmanager.h"
23
23
#include <gmodule.h>
24
#include <dirent.h> /* opendir readir closedir*/
24
#include <dirent.h> /* opendir readir closedir */
25
25
#include <string.h> /* strstr */
27
27
#include "gwapplicationmanager.h"
30
31
GWPluginsManager my_plugins_manager;
33
gint gw_plugins_manager_init ( )
34
typedef struct gw_plugin_s {
40
typedef gboolean (*func_gw_plugin_load_t)(GWPlugin*);
41
typedef gboolean (*func_gw_plugin_unload_t)(gchar*,GWPlugin*,gpointer);
42
typedef gchar* (*func_gw_plugin_key_t)(GWPlugin*);
45
GHashTable * gw_plugin_manager_load_plugins ( const gchar *directory, const gchar *extension, func_gw_plugin_load_t gw_plugin_load, func_gw_plugin_key_t gw_plugin_key) {
46
GHashTable *plugins = NULL;
47
DIR *plugins_dir = NULL;
48
struct dirent *dentry = NULL;
49
gchar *file_ext = NULL;
50
gchar *module_path = NULL;
51
GModule *module = NULL;
52
GWPlugin *plugin = NULL;
55
if ( directory != NULL ) {
56
if ( extension != NULL) {
57
if ( gw_plugin_load != NULL) {
58
if ( gw_plugin_key != NULL) {
59
// Creates the hashtable to store all the plugins
60
plugins = g_hash_table_new ( g_str_hash, g_str_equal);
62
// Tries to open the plugins directory
63
if ( (plugins_dir = opendir ( directory)) != NULL ) {
64
// Scans the plugins directory
65
while ( (dentry = readdir ( plugins_dir)) != NULL ) {
66
// Checks the file name
67
if ( dentry->d_name != NULL ) {
68
// Search the file extension
69
if ( (file_ext = strrchr ( dentry->d_name, '.')) != NULL ) {
70
// Checks if the file extension correspond to a plugin file
71
if ( strcasecmp ( ++file_ext, extension) == 0 ) {
72
// Builds the module (plugin) path
73
module_path = g_strconcat ( directory, G_DIR_SEPARATOR_S, dentry->d_name, NULL);
75
// Tries to load the found module
76
if ( (module = g_module_open ( module_path, 0)) != NULL ) {
77
// Checks if the plugin can be loaded and load it
78
plugin = (GWPlugin*)g_malloc ( sizeof ( GWPlugin));
79
memset ( plugin, '\0', sizeof ( GWPlugin));
80
plugin->module = module;
81
if ( gw_plugin_load ( plugin) == TRUE ) {
82
g_hash_table_insert ( plugins, gw_plugin_key ( plugin), plugin);
89
g_free ( module_path);
97
closedir ( plugins_dir);
108
gboolean gw_plugin_load_catalog_plugin ( GWPlugin *plugin) {
109
gboolean result = FALSE;
110
GModule *module = NULL;
111
GWCatalogPlugin *catalog_plugin = NULL;
112
func_gw_plugin_get_info_t func_gw_plugin_get_info = NULL;
113
func_gw_db_catalog_create_t func_gw_db_catalog_create = NULL;
114
func_gw_db_catalog_open_t func_gw_db_catalog_open = NULL;
115
func_gw_db_catalog_save_t func_gw_db_catalog_save = NULL;
116
func_gw_db_catalog_close_t func_gw_db_catalog_close = NULL;
117
func_gw_db_catalog_get_db_catalog_t func_gw_db_catalog_get_db_catalog = NULL;
118
func_gw_db_catalog_get_db_category_t func_gw_db_catalog_get_db_category = NULL;
119
func_gw_db_catalog_get_db_disk_t func_gw_db_catalog_get_db_disk = NULL;
120
func_gw_db_catalog_get_db_file_t func_gw_db_catalog_get_db_file = NULL;
121
func_gw_db_catalog_get_db_categories_t func_gw_db_catalog_get_db_categories = NULL;
122
func_gw_db_catalog_get_db_disks_t func_gw_db_catalog_get_db_disks = NULL;
123
func_gw_db_disk_get_db_files_t func_gw_db_disk_get_db_files = NULL;
124
func_gw_db_file_get_db_files_t func_gw_db_file_get_db_files = NULL;
125
func_gw_db_file_get_db_disk_t func_gw_db_file_get_db_disk = NULL;
126
func_gw_db_file_get_parent_db_file_t func_gw_db_file_get_parent_db_file = NULL;
127
func_gw_db_catalog_add_db_category_t func_gw_db_catalog_add_db_category = NULL;
128
func_gw_db_catalog_add_db_disk_t func_gw_db_catalog_add_db_disk = NULL;
129
func_gw_db_disk_add_db_file_t func_gw_db_disk_add_db_file = NULL;
130
func_gw_db_file_add_db_file_t func_gw_db_file_add_db_file = NULL;
131
func_gw_db_catalog_remove_db_category_t func_gw_db_catalog_remove_db_category = NULL;
132
func_gw_db_catalog_remove_db_disk_t func_gw_db_catalog_remove_db_disk = NULL;
133
func_gw_db_catalog_remove_db_file_t func_gw_db_catalog_remove_db_file = NULL;
134
func_gw_db_catalog_update_t func_gw_db_catalog_update = NULL;
135
func_gw_db_category_update_t func_gw_db_category_update = NULL;
136
func_gw_db_disk_update_t func_gw_db_disk_update = NULL;
137
func_gw_db_file_update_t func_gw_db_file_update = NULL;
138
func_gw_db_catalog_get_nb_db_files_t func_gw_db_catalog_get_nb_db_files = NULL;
139
func_gw_db_catalog_get_nb_db_folders_t func_gw_db_catalog_get_nb_db_folders = NULL;
140
func_gw_db_catalog_get_nb_db_disks_t func_gw_db_catalog_get_nb_db_disks = NULL;
141
func_gw_db_disk_get_nb_db_files_t func_gw_db_disk_get_nb_db_files = NULL;
142
func_gw_db_disk_get_nb_db_folders_t func_gw_db_disk_get_nb_db_folders = NULL;
143
func_gw_db_catalog_get_capacity_t func_gw_db_catalog_get_capacity = NULL;
144
func_gw_db_catalog_get_full_t func_gw_db_catalog_get_full = NULL;
145
func_gw_db_catalog_get_free_t func_gw_db_catalog_get_free = NULL;
146
func_gw_db_catalog_get_db_category_by_index_t func_gw_db_catalog_get_db_category_by_index = NULL;
147
func_gw_db_catalog_get_db_category_by_name_t func_gw_db_catalog_get_db_category_by_name = NULL;
148
func_gw_db_catalog_get_db_disk_by_name_t func_gw_db_catalog_get_db_disk_by_name = NULL;
149
func_gw_db_disk_get_db_file_by_name_t func_gw_db_disk_get_db_file_by_name = NULL;
150
func_gw_db_file_get_db_file_by_name_t func_gw_db_file_get_db_file_by_name = NULL;
151
func_gw_db_file_get_location_t func_gw_db_file_get_location = NULL;
154
if ( (module = plugin->module) != NULL ) {
155
g_module_symbol ( module, "plugin_get_info", (gpointer *)(&func_gw_plugin_get_info));
156
g_module_symbol ( module, "plugin_db_catalog_create", (gpointer *)(&func_gw_db_catalog_create));
157
g_module_symbol ( module, "plugin_db_catalog_open", (gpointer *)(&func_gw_db_catalog_open));
158
g_module_symbol ( module, "plugin_db_catalog_save", (gpointer *)(&func_gw_db_catalog_save));
159
g_module_symbol ( module, "plugin_db_catalog_close", (gpointer *)(&func_gw_db_catalog_close));
160
g_module_symbol ( module, "plugin_db_catalog_get_capacity", (gpointer *)(&func_gw_db_catalog_get_capacity));
161
g_module_symbol ( module, "plugin_db_catalog_get_full", (gpointer *)(&func_gw_db_catalog_get_full));
162
g_module_symbol ( module, "plugin_db_catalog_get_free", (gpointer *)(&func_gw_db_catalog_get_free));
163
g_module_symbol ( module, "plugin_db_catalog_get_nb_db_files", (gpointer *)(&func_gw_db_catalog_get_nb_db_files));
164
g_module_symbol ( module, "plugin_db_catalog_get_nb_db_folders", (gpointer *)(&func_gw_db_catalog_get_nb_db_folders));
165
g_module_symbol ( module, "plugin_db_catalog_get_nb_db_disks", (gpointer *)(&func_gw_db_catalog_get_nb_db_disks));
166
g_module_symbol ( module, "plugin_db_catalog_get_db_catalog", (gpointer *)(&func_gw_db_catalog_get_db_catalog));
167
g_module_symbol ( module, "plugin_db_catalog_get_db_category", (gpointer *)(&func_gw_db_catalog_get_db_category));
168
g_module_symbol ( module, "plugin_db_catalog_get_db_disk", (gpointer *)(&func_gw_db_catalog_get_db_disk));
169
g_module_symbol ( module, "plugin_db_catalog_get_db_file", (gpointer *)(&func_gw_db_catalog_get_db_file));
170
g_module_symbol ( module, "plugin_db_catalog_get_db_categories", (gpointer *)(&func_gw_db_catalog_get_db_categories));
171
g_module_symbol ( module, "plugin_db_catalog_get_db_disks", (gpointer *)(&func_gw_db_catalog_get_db_disks));
172
g_module_symbol ( module, "plugin_db_disk_get_nb_db_files", (gpointer *)(&func_gw_db_disk_get_nb_db_files));
173
g_module_symbol ( module, "plugin_db_disk_get_nb_db_folders", (gpointer *)(&func_gw_db_disk_get_nb_db_folders));
174
g_module_symbol ( module, "plugin_db_disk_get_db_files", (gpointer *)(&func_gw_db_disk_get_db_files));
175
g_module_symbol ( module, "plugin_db_file_get_db_files", (gpointer *)(&func_gw_db_file_get_db_files));
176
g_module_symbol ( module, "plugin_db_catalog_get_db_category_by_index", (gpointer *)(&func_gw_db_catalog_get_db_category_by_index));
177
g_module_symbol ( module, "plugin_db_catalog_get_db_category_by_name", (gpointer *)(&func_gw_db_catalog_get_db_category_by_name));
178
g_module_symbol ( module, "plugin_db_catalog_get_db_disk_by_name", (gpointer *)(&func_gw_db_catalog_get_db_disk_by_name));
179
g_module_symbol ( module, "plugin_db_disk_get_db_file_by_name", (gpointer *)(&func_gw_db_disk_get_db_file_by_name));
180
g_module_symbol ( module, "plugin_db_file_get_db_file_by_name", (gpointer *)(&func_gw_db_file_get_db_file_by_name));
181
g_module_symbol ( module, "plugin_db_file_get_db_disk", (gpointer *)(&func_gw_db_file_get_db_disk));
182
g_module_symbol ( module, "plugin_db_file_get_parent_db_file", (gpointer *)(&func_gw_db_file_get_parent_db_file));
183
g_module_symbol ( module, "plugin_db_file_get_location", (gpointer *)(&func_gw_db_file_get_location));
184
g_module_symbol ( module, "plugin_db_catalog_add_db_category", (gpointer *)(&func_gw_db_catalog_add_db_category));
185
g_module_symbol ( module, "plugin_db_catalog_add_db_disk", (gpointer *)(&func_gw_db_catalog_add_db_disk));
186
g_module_symbol ( module, "plugin_db_disk_add_db_file", (gpointer *)(&func_gw_db_disk_add_db_file));
187
g_module_symbol ( module, "plugin_db_file_add_db_file", (gpointer *)(&func_gw_db_file_add_db_file));
188
g_module_symbol ( module, "plugin_db_catalog_remove_db_category", (gpointer *)(&func_gw_db_catalog_remove_db_category));
189
g_module_symbol ( module, "plugin_db_catalog_remove_db_disk", (gpointer *)(&func_gw_db_catalog_remove_db_disk));
190
g_module_symbol ( module, "plugin_db_catalog_remove_db_file", (gpointer *)(&func_gw_db_catalog_remove_db_file));
191
g_module_symbol ( module, "plugin_db_catalog_update", (gpointer *)(&func_gw_db_catalog_update));
192
g_module_symbol ( module, "plugin_db_category_update", (gpointer *)(&func_gw_db_category_update));
193
g_module_symbol ( module, "plugin_db_disk_update", (gpointer *)(&func_gw_db_disk_update));
194
g_module_symbol ( module, "plugin_db_file_update", (gpointer *)(&func_gw_db_file_update));
196
if ( func_gw_plugin_get_info!=NULL &&
197
func_gw_db_catalog_create!=NULL &&
198
func_gw_db_catalog_open!=NULL &&
199
func_gw_db_catalog_save!=NULL &&
200
func_gw_db_catalog_close!=NULL &&
201
func_gw_db_catalog_get_nb_db_files!=NULL &&
202
func_gw_db_catalog_get_nb_db_folders!=NULL &&
203
func_gw_db_catalog_get_nb_db_disks!=NULL &&
204
func_gw_db_catalog_get_db_catalog!=NULL &&
205
func_gw_db_catalog_get_db_category!=NULL &&
206
func_gw_db_catalog_get_db_disk!=NULL &&
207
func_gw_db_catalog_get_db_file!=NULL &&
208
func_gw_db_catalog_get_db_categories!=NULL &&
209
func_gw_db_catalog_get_db_disks!=NULL &&
210
func_gw_db_disk_get_nb_db_files!=NULL &&
211
func_gw_db_disk_get_nb_db_folders!=NULL &&
212
func_gw_db_disk_get_db_files!=NULL &&
213
func_gw_db_file_get_db_files!=NULL &&
214
func_gw_db_file_get_db_disk!=NULL &&
215
func_gw_db_file_get_parent_db_file!=NULL &&
216
func_gw_db_catalog_add_db_category!=NULL &&
217
func_gw_db_catalog_add_db_disk!=NULL &&
218
func_gw_db_disk_add_db_file!=NULL &&
219
func_gw_db_file_add_db_file!=NULL &&
220
func_gw_db_catalog_remove_db_category!=NULL &&
221
func_gw_db_catalog_remove_db_disk!=NULL &&
222
func_gw_db_catalog_remove_db_file!=NULL &&
223
func_gw_db_catalog_update!=NULL &&
224
func_gw_db_category_update!=NULL &&
225
func_gw_db_disk_update!=NULL &&
226
func_gw_db_file_update!=NULL ) {
228
if ( (catalog_plugin = (GWCatalogPlugin*)g_malloc ( sizeof ( GWCatalogPlugin))) != NULL ) {
229
memset ( catalog_plugin, '\0', sizeof ( GWCatalogPlugin));
230
catalog_plugin->gw_plugin_get_info = func_gw_plugin_get_info;
231
catalog_plugin->gw_db_catalog_create = func_gw_db_catalog_create;
232
catalog_plugin->gw_db_catalog_open = func_gw_db_catalog_open;
233
catalog_plugin->gw_db_catalog_save = func_gw_db_catalog_save;
234
catalog_plugin->gw_db_catalog_close = func_gw_db_catalog_close;
235
if ( func_gw_db_catalog_get_capacity != NULL) {
236
catalog_plugin->gw_db_catalog_get_capacity = func_gw_db_catalog_get_capacity;
238
catalog_plugin->gw_db_catalog_get_capacity = gw_helper_plugin_db_catalog_get_capacity;
240
if ( func_gw_db_catalog_get_full != NULL) {
241
catalog_plugin->gw_db_catalog_get_full = func_gw_db_catalog_get_full;
243
catalog_plugin->gw_db_catalog_get_full = gw_helper_plugin_db_catalog_get_full;
245
if ( func_gw_db_catalog_get_free != NULL) {
246
catalog_plugin->gw_db_catalog_get_free = func_gw_db_catalog_get_free;
248
catalog_plugin->gw_db_catalog_get_free = gw_helper_plugin_db_catalog_get_free;
250
catalog_plugin->gw_db_catalog_get_nb_db_files = func_gw_db_catalog_get_nb_db_files;
251
catalog_plugin->gw_db_catalog_get_nb_db_folders = func_gw_db_catalog_get_nb_db_folders;
252
catalog_plugin->gw_db_catalog_get_nb_db_disks = func_gw_db_catalog_get_nb_db_disks;
253
catalog_plugin->gw_db_catalog_get_db_catalog = func_gw_db_catalog_get_db_catalog;
254
catalog_plugin->gw_db_catalog_get_db_category = func_gw_db_catalog_get_db_category;
255
catalog_plugin->gw_db_catalog_get_db_disk = func_gw_db_catalog_get_db_disk;
256
catalog_plugin->gw_db_catalog_get_db_file = func_gw_db_catalog_get_db_file;
257
catalog_plugin->gw_db_catalog_get_db_categories = func_gw_db_catalog_get_db_categories;
258
catalog_plugin->gw_db_catalog_get_db_disks = func_gw_db_catalog_get_db_disks;
259
catalog_plugin->gw_db_disk_get_nb_db_files = func_gw_db_disk_get_nb_db_files;
260
catalog_plugin->gw_db_disk_get_nb_db_folders = func_gw_db_disk_get_nb_db_folders;
261
catalog_plugin->gw_db_disk_get_db_files = func_gw_db_disk_get_db_files;
262
catalog_plugin->gw_db_file_get_db_files = func_gw_db_file_get_db_files;
263
if ( func_gw_db_catalog_get_db_category_by_index != NULL) {
264
catalog_plugin->gw_db_catalog_get_db_category_by_index = func_gw_db_catalog_get_db_category_by_index;
266
catalog_plugin->gw_db_catalog_get_db_category_by_index = gw_helper_plugin_db_catalog_get_db_category_by_index;
268
if ( func_gw_db_catalog_get_db_category_by_name != NULL) {
269
catalog_plugin->gw_db_catalog_get_db_category_by_name = func_gw_db_catalog_get_db_category_by_name;
271
catalog_plugin->gw_db_catalog_get_db_category_by_name = gw_helper_plugin_db_catalog_get_db_category_by_name;
273
if ( func_gw_db_catalog_get_db_disk_by_name != NULL) {
274
catalog_plugin->gw_db_catalog_get_db_disk_by_name = func_gw_db_catalog_get_db_disk_by_name;
276
catalog_plugin->gw_db_catalog_get_db_disk_by_name = gw_helper_plugin_db_catalog_get_db_disk_by_name;
278
if ( func_gw_db_disk_get_db_file_by_name != NULL) {
279
catalog_plugin->gw_db_disk_get_db_file_by_name = func_gw_db_disk_get_db_file_by_name;
281
catalog_plugin->gw_db_disk_get_db_file_by_name = gw_helper_plugin_db_disk_get_db_file_by_name;
283
if ( func_gw_db_file_get_db_file_by_name != NULL) {
284
catalog_plugin->gw_db_file_get_db_file_by_name = func_gw_db_file_get_db_file_by_name;
286
catalog_plugin->gw_db_file_get_db_file_by_name = gw_helper_plugin_db_file_get_db_file_by_name;
288
catalog_plugin->gw_db_file_get_db_disk = func_gw_db_file_get_db_disk;
289
catalog_plugin->gw_db_file_get_parent_db_file = func_gw_db_file_get_parent_db_file;
290
if ( func_gw_db_file_get_location != NULL) {
291
catalog_plugin->gw_db_file_get_location = func_gw_db_file_get_location;
293
catalog_plugin->gw_db_file_get_location = gw_helper_plugin_db_file_get_location;
295
catalog_plugin->gw_db_catalog_add_db_category = func_gw_db_catalog_add_db_category;
296
catalog_plugin->gw_db_catalog_add_db_disk = func_gw_db_catalog_add_db_disk;
297
catalog_plugin->gw_db_disk_add_db_file = func_gw_db_disk_add_db_file;
298
catalog_plugin->gw_db_file_add_db_file = func_gw_db_file_add_db_file;
299
catalog_plugin->gw_db_catalog_remove_db_category = func_gw_db_catalog_remove_db_category;
300
catalog_plugin->gw_db_catalog_remove_db_disk = func_gw_db_catalog_remove_db_disk;
301
catalog_plugin->gw_db_catalog_remove_db_file = func_gw_db_catalog_remove_db_file;
302
catalog_plugin->gw_db_catalog_update = func_gw_db_catalog_update;
303
catalog_plugin->gw_db_category_update = func_gw_db_category_update;
304
catalog_plugin->gw_db_disk_update = func_gw_db_disk_update;
305
catalog_plugin->gw_db_file_update = func_gw_db_file_update;
306
plugin->data = catalog_plugin;
317
gboolean gw_plugin_unload_catalog_plugin ( gchar *key, GWPlugin *plugin, gpointer data) {
318
gboolean result = TRUE;
325
if ( plugin != NULL ) {
326
if ( plugin->module != NULL ) {
327
g_module_close ( plugin->module);
337
gchar * gw_plugin_key_catalog_plugin ( GWPlugin *plugin) {
341
GWCatalogPlugin *catalog_plugin = plugin->data;
342
key = g_strdup ( gw_plugin_info_get_name ( catalog_plugin->gw_plugin_get_info ( )));
348
gint gw_pm_init ( ) {
36
350
GModule *module = NULL;
37
351
gchar *module_path = NULL;
56
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
370
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
59
if ( g_module_supported ( ) )
373
if ( g_module_supported ( ) ) {
374
if ( (my_plugins_manager.catalog_plugins = gw_plugin_manager_load_plugins ( gw_package_get_plugins_catalog_dir ( ), G_MODULE_SUFFIX, &gw_plugin_load_catalog_plugin, &gw_plugin_key_catalog_plugin)) != NULL) {
375
/* Plugins are loaded. */
377
/* Plugins loading failed. */
61
380
my_plugins_manager.descr_plugins = g_hash_table_new ( g_str_hash, g_str_equal/*(GCompareFunc)strcasecmp*/);
62
381
my_plugins_manager.file_descr_funcs = g_hash_table_new ( g_str_hash, g_str_equal/*(GCompareFunc)strcasecmp*/);
63
382
my_plugins_manager.files_descr_funcs = g_hash_table_new ( g_str_hash, g_str_equal/*(GCompareFunc)strcasecmp*/);
64
383
my_plugins_manager.parent_descr_funcs = g_hash_table_new ( g_str_hash, g_str_equal/*(GCompareFunc)strcasecmp*/);
67
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Starting the scan of %s...", PACKAGE_PLUGINS_DESCRIPTION_DIR);
69
if ( (plugins_dir = gw_package_get_plugins_dir ( )) != NULL )
71
if ( (plugins_descr_dir = opendir ( plugins_dir)) != NULL )
73
while ( (dentry = readdir ( plugins_descr_dir)) != NULL )
76
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Current file is %s", dentry->d_name);
79
if ( dentry->d_name != NULL )
82
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Checking the file %s", dentry->d_name);
85
if ( (so = strrchr ( dentry->d_name, '.')) != NULL )
88
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File extension is founded : %s", so);
91
if ( strcasecmp ( ++so, G_MODULE_SUFFIX) == 0 )
386
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Starting the scan of %s...", PACKAGE_PLUGINS_DESCRIPTION_DIR);
389
if ( (plugins_dir = gw_package_get_plugins_description_dir ( )) != NULL ) {
390
if ( (plugins_descr_dir = opendir ( plugins_dir)) != NULL ) {
391
while ( (dentry = readdir ( plugins_descr_dir)) != NULL ) {
393
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Current file is %s", dentry->d_name);
396
if ( dentry->d_name != NULL ) {
398
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Checking the file %s", dentry->d_name);
401
if ( (so = strrchr ( dentry->d_name, '.')) != NULL ) {
403
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File extension is founded : %s", so);
406
if ( strcasecmp ( ++so, G_MODULE_SUFFIX) == 0 ) {
93
407
/* The file extension is a valid extension for module file. */
95
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "The file extension founded is supported : %s.", so);
409
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "The file extension founded is supported : %s.", so);
97
411
module_path = g_strconcat ( PACKAGE_PLUGINS_DESCRIPTION_DIR, G_DIR_SEPARATOR_S, dentry->d_name, NULL);
100
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Trying to load %s...", module_path);
414
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Trying to load %s...", module_path);
103
417
module = g_module_open ( module_path, 0);
105
if ( module != NULL )
419
if ( module != NULL ) {
107
420
g_module_symbol ( module, "plugin_get_author", (gpointer *)(&func_get_author));
108
421
g_module_symbol ( module, "plugin_get_info", (gpointer *)(&func_get_info));
109
422
g_module_symbol ( module, "plugin_get_help", (gpointer *)(&func_get_help));
113
426
g_module_symbol ( module, "plugin_get_files_descr", (gpointer *)(&func_get_files_descr));
114
427
g_module_symbol ( module, "plugin_get_parent_descr", (gpointer *)(&func_get_parent_descr));
116
if ( (func_get_author != NULL) && (func_get_info != NULL) && (func_get_help != NULL) )
119
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module name is %s", g_module_name ( module));
120
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module author is %s", func_get_author ( ));
121
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module info is %s", func_get_info ( ));
122
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module help is %s", func_get_help ( ));
125
if ( (func_get_allowed_ext != NULL) && (func_get_file_descr != NULL) )
128
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_ext is %s", func_get_allowed_ext ( ));
131
if ( (func_get_allowed_ext ( ) != NULL) && (strlen ( func_get_allowed_ext ( )) > 0) )
429
if ( (func_get_author != NULL) && (func_get_info != NULL) && (func_get_help != NULL) ) {
431
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module name is %s", g_module_name ( module));
432
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module author is %s", func_get_author ( )!=NULL?func_get_author ( ):"");
433
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module info is %s", func_get_info ( )!=NULL?func_get_info ( ):"");
434
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module help is %s", func_get_help ( )!=NULL?func_get_help ( ):"");
437
if ( (func_get_allowed_ext != NULL) && (func_get_file_descr != NULL) ) {
439
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_ext is %s", func_get_allowed_ext ( ));
442
if ( (func_get_allowed_ext ( ) != NULL) && (strlen ( func_get_allowed_ext ( )) > 0) ) {
133
443
allowed_ext = g_strsplit ( func_get_allowed_ext ( ), "|", -1);
135
if ( allowed_ext != NULL )
137
for ( i = 0; allowed_ext[i] != NULL; i++)
445
if ( allowed_ext != NULL ) {
446
for ( i = 0; allowed_ext[i] != NULL; i++) {
139
447
g_hash_table_insert ( my_plugins_manager.descr_plugins, g_strdup ( func_get_allowed_ext ( )), module);
140
448
#if GW_DEBUG_MODE
141
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_ext[i]);
449
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_ext[i]);
144
452
g_strdown ( allowed_ext[i]);
346
gint gw_plugins_manager_exit ( )
631
gint gw_pm_exit ( ) {
348
632
gint result = -1;
351
635
#if GW_DEBUG_MODE
352
gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
636
gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
355
if ( my_plugins_manager.catalog_plugins != NULL )
357
g_hash_table_foreach_remove ( my_plugins_manager.catalog_plugins, (GHRFunc)gw_plugins_manager_module_close, NULL);
639
if ( my_plugins_manager.catalog_plugins != NULL ) {
640
// g_hash_table_foreach_remove ( my_plugins_manager.catalog_plugins, (GHRFunc)gw_pm_module_close, NULL);
641
g_hash_table_foreach_remove ( my_plugins_manager.catalog_plugins, (GHRFunc)gw_plugin_unload_catalog_plugin, NULL);
358
642
g_hash_table_destroy ( my_plugins_manager.catalog_plugins);
359
643
my_plugins_manager.catalog_plugins = NULL;
362
if ( my_plugins_manager.file_descr_funcs != NULL )
646
if ( my_plugins_manager.file_descr_funcs != NULL ) {
364
647
g_hash_table_destroy ( my_plugins_manager.file_descr_funcs);
365
648
my_plugins_manager.file_descr_funcs = NULL;
368
if ( my_plugins_manager.files_descr_funcs != NULL )
651
if ( my_plugins_manager.files_descr_funcs != NULL ) {
370
652
g_hash_table_destroy ( my_plugins_manager.files_descr_funcs);
371
653
my_plugins_manager.files_descr_funcs = NULL;
374
if ( my_plugins_manager.parent_descr_funcs != NULL )
656
if ( my_plugins_manager.parent_descr_funcs != NULL ) {
376
657
g_hash_table_destroy ( my_plugins_manager.parent_descr_funcs);
377
658
my_plugins_manager.parent_descr_funcs = NULL;
380
if ( my_plugins_manager.descr_plugins != NULL )
382
g_hash_table_foreach_remove ( my_plugins_manager.descr_plugins, (GHRFunc)gw_plugins_manager_module_close, NULL);
661
if ( my_plugins_manager.descr_plugins != NULL ) {
662
g_hash_table_foreach_remove ( my_plugins_manager.descr_plugins, (GHRFunc)gw_pm_module_close, NULL);
383
663
g_hash_table_destroy ( my_plugins_manager.descr_plugins);
384
664
my_plugins_manager.descr_plugins = NULL;
671
GWCatalogPlugin * gw_pm_get_catalog_plugin ( gchar* name) {
672
GWCatalogPlugin * catalog_plugin = NULL;
675
if ( my_plugins_manager.catalog_plugins != NULL) {
676
GWPlugin *plugin = g_hash_table_lookup ( my_plugins_manager.catalog_plugins, name);
678
if ( plugin != NULL) {
679
catalog_plugin = plugin->data;
684
return catalog_plugin;
688
GWCatalogPlugin * gw_pm_get_default_catalog_plugin ( ) {
689
//TODO read the plugin name in the settings
690
return gw_pm_get_catalog_plugin ( "GWhere catalog");
694
void gw_pm_add_plugin_name ( gpointer key, gpointer value, gpointer data) {
695
gchar **names = data;
697
GWPlugin *plugin = value;
701
if ( data!=NULL && key!=NULL) {
702
/* Doesn't add the current catalog plugin */
703
if ( plugin->data != gw_pm_get_current_catalog_plugin ( )) {
704
for ( i = 0; names[i] != NULL; i++);
711
gchar ** gw_pm_get_all_catalog_import_plugin_name ( ) {
712
gchar **names = NULL;
716
if ( my_plugins_manager.catalog_plugins != NULL ) {
717
if ( (nb = g_hash_table_size ( my_plugins_manager.catalog_plugins)) > 0 ) {
718
if ( gw_pm_get_current_catalog_plugin ( ) != NULL ) {
722
names = (gchar**)g_malloc0 ( sizeof ( gchar*) * ( nb + 1));
723
for ( i = 0; i < (nb + 1); i++) names[i] = NULL;
724
g_hash_table_foreach ( my_plugins_manager.catalog_plugins, (GHFunc)gw_pm_add_plugin_name, names);
732
gchar ** gw_pm_get_all_catalog_export_plugin_name ( ) {
733
gchar **names = NULL;
737
if ( my_plugins_manager.catalog_plugins != NULL ) {
738
if ( (nb = g_hash_table_size ( my_plugins_manager.catalog_plugins)) > 0 ) {
739
if ( gw_pm_get_current_catalog_plugin ( ) != NULL ) {
743
names = (gchar**)g_malloc0 ( sizeof ( gchar*) * ( nb + 1));
744
for ( i = 0; i < (nb + 1); i++) names[i] = NULL;
745
g_hash_table_foreach ( my_plugins_manager.catalog_plugins, (GHFunc)gw_pm_add_plugin_name, names);
753
void gw_pm_set_current_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
754
my_plugins_manager.current_ctg_plugin = ctg_plugin;
758
GWCatalogPlugin * gw_pm_get_current_catalog_plugin ( ) {
759
return my_plugins_manager.current_ctg_plugin;
763
void gw_pm_set_selected_import_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
764
my_plugins_manager.selected_import_ctg_pugin = ctg_plugin;
768
GWCatalogPlugin * gw_pm_get_selected_import_catalog_plugin ( ) {
769
return my_plugins_manager.selected_import_ctg_pugin;
773
void gw_pm_set_selected_export_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
774
my_plugins_manager.selected_export_ctg_pugin = ctg_plugin;
778
GWCatalogPlugin * gw_pm_get_selected_export_catalog_plugin ( ) {
779
return my_plugins_manager.selected_export_ctg_pugin;