~ubuntu-branches/ubuntu/maverick/gwhere/maverick

« back to all changes in this revision

Viewing changes to src/gwpluginsmanager.c

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2007-01-27 16:01:01 UTC
  • mfrom: (2.1.1 feisty)
  • Revision ID: james.westby@ubuntu.com-20070127160101-u673yo4vke03jg26
Tags: 0.2.3.dfsg.1-2
* debian/rules: Convert gwhere.desktop to UTF-8.  Closes: #405137.
* debian/rules: Replace all "extraibles" with "extraíbles" in
  gwhere.desktop.  Closes: #405138.
* debian/copyright: Updated for year 2007.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "gwpluginsmanager.h"
22
22
 
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 */
26
26
 
27
27
#include "gwapplicationmanager.h"
 
28
#include "gwhelper.h"
28
29
 
29
30
 
30
31
GWPluginsManager my_plugins_manager;
31
32
 
32
33
 
33
 
gint gw_plugins_manager_init ( )
34
 
{
 
34
typedef struct gw_plugin_s {
 
35
        GModule *module;
 
36
        gpointer data;
 
37
}GWPlugin;
 
38
 
 
39
 
 
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*);
 
43
 
 
44
 
 
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;
 
53
 
 
54
 
 
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);
 
61
 
 
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);
 
74
 
 
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);
 
83
                                                                                        } else {
 
84
                                                                                                g_free ( plugin);
 
85
                                                                                                plugin = NULL;
 
86
                                                                                        }
 
87
                                                                                } else {}
 
88
 
 
89
                                                                                g_free ( module_path);
 
90
                                                                        } else {}
 
91
                                                                } else {}
 
92
 
 
93
                                                                file_ext = NULL;
 
94
                                                        } else {}
 
95
                                                }
 
96
 
 
97
                                                closedir ( plugins_dir);
 
98
                                        } else {}
 
99
                                } else {}
 
100
                        } else {}
 
101
                } else {}
 
102
        } else {}
 
103
 
 
104
        return plugins;
 
105
}
 
106
 
 
107
 
 
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;
 
152
 
 
153
 
 
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));
 
195
 
 
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 ) {
 
227
 
 
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;
 
237
                                } else {
 
238
                                        catalog_plugin->gw_db_catalog_get_capacity = gw_helper_plugin_db_catalog_get_capacity;
 
239
                                }
 
240
                                if ( func_gw_db_catalog_get_full != NULL) {
 
241
                                        catalog_plugin->gw_db_catalog_get_full = func_gw_db_catalog_get_full;
 
242
                                } else {
 
243
                                        catalog_plugin->gw_db_catalog_get_full = gw_helper_plugin_db_catalog_get_full;
 
244
                                }
 
245
                                if ( func_gw_db_catalog_get_free != NULL) {
 
246
                                        catalog_plugin->gw_db_catalog_get_free = func_gw_db_catalog_get_free;
 
247
                                } else {
 
248
                                        catalog_plugin->gw_db_catalog_get_free = gw_helper_plugin_db_catalog_get_free;
 
249
                                }
 
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;
 
265
                                } else {
 
266
                                        catalog_plugin->gw_db_catalog_get_db_category_by_index = gw_helper_plugin_db_catalog_get_db_category_by_index;
 
267
                                }
 
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;
 
270
                                } else {
 
271
                                        catalog_plugin->gw_db_catalog_get_db_category_by_name = gw_helper_plugin_db_catalog_get_db_category_by_name;
 
272
                                }
 
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;
 
275
                                } else {
 
276
                                        catalog_plugin->gw_db_catalog_get_db_disk_by_name = gw_helper_plugin_db_catalog_get_db_disk_by_name;
 
277
                                }
 
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;
 
280
                                } else {
 
281
                                        catalog_plugin->gw_db_disk_get_db_file_by_name = gw_helper_plugin_db_disk_get_db_file_by_name;
 
282
                                }
 
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;
 
285
                                } else {
 
286
                                        catalog_plugin->gw_db_file_get_db_file_by_name = gw_helper_plugin_db_file_get_db_file_by_name;
 
287
                                }
 
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;
 
292
                                } else {
 
293
                                        catalog_plugin->gw_db_file_get_location = gw_helper_plugin_db_file_get_location;
 
294
                                }
 
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;
 
307
 
 
308
                                result = TRUE;
 
309
                        } else {}
 
310
                } else {}
 
311
        } else {}
 
312
 
 
313
        return result;
 
314
}
 
315
 
 
316
 
 
317
gboolean gw_plugin_unload_catalog_plugin ( gchar *key, GWPlugin *plugin, gpointer data) {
 
318
        gboolean result = TRUE;
 
319
 
 
320
 
 
321
        if ( key != NULL ) {
 
322
                g_free ( key);
 
323
        } else {}
 
324
 
 
325
        if ( plugin != NULL ) {
 
326
                if ( plugin->module != NULL ) {
 
327
                        g_module_close ( plugin->module);
 
328
                } else {}
 
329
 
 
330
                g_free ( plugin);
 
331
        }
 
332
 
 
333
        return result;
 
334
}
 
335
 
 
336
 
 
337
gchar * gw_plugin_key_catalog_plugin ( GWPlugin *plugin) {
 
338
        gchar *key = NULL;
 
339
 
 
340
 
 
341
        GWCatalogPlugin *catalog_plugin = plugin->data;
 
342
        key = g_strdup ( gw_plugin_info_get_name ( catalog_plugin->gw_plugin_get_info ( )));
 
343
 
 
344
        return key;
 
345
}
 
346
 
 
347
 
 
348
gint gw_pm_init ( ) {
35
349
        gint result = -1;
36
350
        GModule *module = NULL;
37
351
        gchar *module_path = NULL;
53
367
 
54
368
 
55
369
#if GW_DEBUG_MODE
56
 
        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
 
370
        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
57
371
#endif
58
372
 
59
 
        if ( g_module_supported ( ) )
60
 
        {
 
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. */
 
376
                } else {
 
377
                        /* Plugins loading failed. */
 
378
                }
 
379
 
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*/);
65
384
 
66
385
#if GW_DEBUG_MODE
67
 
                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Starting the scan of %s...", PACKAGE_PLUGINS_DESCRIPTION_DIR);
68
 
#endif
69
 
                if ( (plugins_dir = gw_package_get_plugins_dir ( )) != NULL )
70
 
                {
71
 
                        if ( (plugins_descr_dir = opendir ( plugins_dir)) != NULL )
72
 
                        {
73
 
                                while ( (dentry = readdir ( plugins_descr_dir)) != NULL )
74
 
                                {
75
 
#if GW_DEBUG_MODE
76
 
                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Current file is %s", dentry->d_name);
77
 
#endif
78
 
 
79
 
                                        if ( dentry->d_name != NULL )
80
 
                                        {
81
 
#if GW_DEBUG_MODE
82
 
                                                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Checking the file %s", dentry->d_name);
83
 
#endif
84
 
 
85
 
                                                if ( (so = strrchr ( dentry->d_name, '.')) != NULL )
86
 
                                                {
87
 
#if GW_DEBUG_MODE
88
 
                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File extension is founded : %s", so);
89
 
#endif
90
 
 
91
 
                                                        if ( strcasecmp ( ++so, G_MODULE_SUFFIX) == 0 )
92
 
                                                        {
 
386
                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Starting the scan of %s...", PACKAGE_PLUGINS_DESCRIPTION_DIR);
 
387
#endif
 
388
 
 
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 ) {
 
392
#if GW_DEBUG_MODE
 
393
                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Current file is %s", dentry->d_name);
 
394
#endif
 
395
 
 
396
                                        if ( dentry->d_name != NULL ) {
 
397
#if GW_DEBUG_MODE
 
398
                                                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Checking the file %s", dentry->d_name);
 
399
#endif
 
400
 
 
401
                                                if ( (so = strrchr ( dentry->d_name, '.')) != NULL ) {
 
402
#if GW_DEBUG_MODE
 
403
                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File extension is founded : %s", so);
 
404
#endif
 
405
 
 
406
                                                        if ( strcasecmp ( ++so, G_MODULE_SUFFIX) == 0 ) {
93
407
                                                                /* The file extension is a valid extension for module file. */
94
408
#if GW_DEBUG_MODE
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);
96
410
#endif
97
411
                                                                module_path = g_strconcat ( PACKAGE_PLUGINS_DESCRIPTION_DIR, G_DIR_SEPARATOR_S, dentry->d_name, NULL);
98
412
 
99
413
#if GW_DEBUG_MODE
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);
101
415
#endif
102
416
 
103
417
                                                                module = g_module_open ( module_path, 0);
104
418
 
105
 
                                                                if ( module != NULL )
106
 
                                                                {
 
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));
115
428
 
116
 
                                                                        if ( (func_get_author != NULL) && (func_get_info != NULL) && (func_get_help != NULL) )
117
 
                                                                        {
118
 
#if GW_DEBUG_MODE
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 ( ));
123
 
#endif
124
 
 
125
 
                                                                                if ( (func_get_allowed_ext != NULL) && (func_get_file_descr != NULL) )
126
 
                                                                                {
127
 
#if GW_DEBUG_MODE
128
 
                                                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_ext is %s", func_get_allowed_ext ( ));
129
 
#endif
130
 
 
131
 
                                                                                        if ( (func_get_allowed_ext ( ) != NULL) && (strlen ( func_get_allowed_ext ( )) > 0) )
132
 
                                                                                        {
 
429
                                                                        if ( (func_get_author != NULL) && (func_get_info != NULL) && (func_get_help != NULL) ) {
 
430
#if GW_DEBUG_MODE
 
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 ( ):"");
 
435
#endif
 
436
 
 
437
                                                                                if ( (func_get_allowed_ext != NULL) && (func_get_file_descr != NULL) ) {
 
438
#if GW_DEBUG_MODE
 
439
                                                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_ext is %s", func_get_allowed_ext ( ));
 
440
#endif
 
441
 
 
442
                                                                                        if ( (func_get_allowed_ext ( ) != NULL) && (strlen ( func_get_allowed_ext ( )) > 0) ) {
133
443
                                                                                                allowed_ext = g_strsplit ( func_get_allowed_ext ( ), "|", -1);
134
444
 
135
 
                                                                                                if ( allowed_ext != NULL )
136
 
                                                                                                {
137
 
                                                                                                        for ( i = 0; allowed_ext[i] != NULL; i++)
138
 
                                                                                                        {
 
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]);
142
450
#endif
143
451
 
144
452
                                                                                                                g_strdown ( allowed_ext[i]);
151
459
                                                                                        }
152
460
                                                                                }
153
461
 
154
 
                                                                                if ( (func_get_allowed_name != NULL) && (func_get_allowed_name ( ) != NULL) && ((func_get_files_descr != NULL) || (func_get_parent_descr != NULL)) )
155
 
                                                                                {
 
462
                                                                                if ( (func_get_allowed_name != NULL) && (func_get_allowed_name ( ) != NULL) && ((func_get_files_descr != NULL) || (func_get_parent_descr != NULL)) ) {
156
463
#if GW_DEBUG_MODE
157
 
                                                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_name is %s", func_get_allowed_name ( ));
 
464
                                                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Module allowed_name is %s", func_get_allowed_name ( ));
158
465
#endif
159
466
 
160
 
                                                                                        if ( (func_get_allowed_name ( ) != NULL) && (strlen ( func_get_allowed_name ( )) > 0) )
161
 
                                                                                        {
 
467
                                                                                        if ( (func_get_allowed_name ( ) != NULL) && (strlen ( func_get_allowed_name ( )) > 0) ) {
162
468
                                                                                                allowed_name = g_strsplit ( func_get_allowed_name ( ), "|", -1);
163
469
 
164
 
                                                                                                if ( allowed_name != NULL )
165
 
                                                                                                {
166
 
                                                                                                        for ( i = 0; allowed_name[i] != NULL; i++)
167
 
                                                                                                        {
 
470
                                                                                                if ( allowed_name != NULL ) {
 
471
                                                                                                        for ( i = 0; allowed_name[i] != NULL; i++) {
168
472
                                                                                                                g_hash_table_insert ( my_plugins_manager.descr_plugins, g_strdup ( func_get_allowed_name ( )), module);
169
473
 
170
474
                                                                                                                g_strdown ( allowed_name[i]);
171
475
 
172
 
                                                                                                                if ( func_get_files_descr != NULL )
173
 
                                                                                                                {
 
476
                                                                                                                if ( func_get_files_descr != NULL ) {
174
477
                                                                                                                        g_hash_table_insert ( my_plugins_manager.files_descr_funcs, g_strdup ( allowed_name[i]), func_get_files_descr);
175
478
#if GW_DEBUG_MODE
176
 
                                                                                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_name[i]);
 
479
                                                                                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_name[i]);
177
480
#endif
178
481
                                                                                                                }
179
482
 
180
 
                                                                                                                if ( func_get_parent_descr != NULL )
181
 
                                                                                                                {
 
483
                                                                                                                if ( func_get_parent_descr != NULL ) {
182
484
                                                                                                                        g_hash_table_insert ( my_plugins_manager.parent_descr_funcs, g_strdup ( allowed_name[i]), func_get_parent_descr);
183
485
 
184
486
#if GW_DEBUG_MODE
185
 
                                                                                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_name[i]);
 
487
                                                                                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "plugin %s added", allowed_name[i]);
186
488
#endif
187
489
                                                                                                                }
188
490
                                                                                                        }
195
497
                                                                        }
196
498
                                                                } else {
197
499
#if GW_DEBUG_MODE
198
 
                                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "unabble to load plugin %s, error :%s", dentry->d_name, g_module_error ( ));
 
500
                                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "unabble to load plugin %s, error :%s", dentry->d_name, g_module_error ( ));
199
501
#endif
200
502
                                                                }
201
503
 
202
504
                                                                g_free ( module_path);
203
505
                                                                module_path = NULL;
204
 
                                                        }
205
 
                                                        else
206
 
                                                        {
 
506
                                                        } else {
207
507
                                                                /* The file extension is not supported as module file extension. */
208
508
#if GW_DEBUG_MODE
209
 
                                                                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "The file extension founded is not supported : %s.", so);
 
509
                                                                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "The file extension founded is not supported : %s.", so);
210
510
#endif
211
511
                                                        }
212
 
                                                }
213
 
                                                else
214
 
                                                {
 
512
                                                } else {
215
513
                                                        /* Unable to find the file extension. */
216
514
#if GW_DEBUG_MODE
217
 
                                                        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "No file extension has been founded.", NULL);
 
515
                                                        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "No file extension has been founded.", NULL);
218
516
#endif
219
517
                                                }
220
518
 
221
519
                                                so = NULL;
222
 
                                        }
223
 
                                        else
224
 
                                        {
 
520
                                        } else {
225
521
                                                /* Unable to get the file name. */
226
522
#if GW_DEBUG_MODE
227
 
                                                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File name is null (inode=%d).", dentry->d_ino);
 
523
                                                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "File name is null (inode=%d).", dentry->d_ino);
228
524
#endif
229
525
                                        }
230
526
 
231
527
                                }
232
528
 
233
529
                                closedir ( plugins_descr_dir);
234
 
                        }
235
 
                        else
236
 
                        {
 
530
                        } else {
237
531
#if GW_DEBUG_MODE
238
 
                                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "%s not found.", PACKAGE_PLUGINS_DESCRIPTION_DIR);
 
532
                                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "%s not found.", PACKAGE_PLUGINS_DESCRIPTION_DIR);
239
533
#endif
240
534
                        }
241
535
 
243
537
                }
244
538
 
245
539
#if GW_DEBUG_MODE
246
 
                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Scan of %s is stopped.", PACKAGE_PLUGINS_DESCRIPTION_DIR);
 
540
                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Scan of %s is stopped.", PACKAGE_PLUGINS_DESCRIPTION_DIR);
247
541
#endif
248
 
        }
249
 
        else
250
 
        {
 
542
 
 
543
                gw_pm_set_current_catalog_plugin ( gw_pm_get_default_catalog_plugin ( ));
 
544
        } else {
251
545
#if GW_DEBUG_MODE
252
 
                gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Dynamic modules are not supported!!");
 
546
                gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, "Dynamic modules are not supported!!");
253
547
#endif
254
548
        }
255
549
 
257
551
}
258
552
 
259
553
 
260
 
gboolean gw_plugins_manager_module_close ( gchar * key, GModule *value, gpointer data)
261
 
{
 
554
gboolean gw_pm_module_close ( gchar * key, GModule *value, gpointer data) {
262
555
        gboolean result = FALSE;
263
556
 
264
557
 
265
558
#if GW_DEBUG_MODE
266
 
        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
 
559
        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
267
560
#endif
268
561
 
269
 
        if ( key != NULL )
270
 
        {
 
562
        if ( key != NULL ) {
271
563
                g_free ( key);
272
564
        }
273
565
 
274
 
        if ( value != NULL )
275
 
        {
 
566
        if ( value != NULL ) {
276
567
                g_module_close ( value);
277
568
        }
278
569
 
280
571
}
281
572
 
282
573
 
283
 
gint gw_plugins_manager_get_file_descr_func ( const gchar *ext, func_get_file_descr_t *f)
284
 
{
 
574
gint gw_pm_get_file_descr_func ( const gchar *ext, func_get_file_descr_t *f) {
285
575
        gint result = -1;
286
576
        gchar *ext_lower = NULL;
287
577
 
288
578
 
289
579
#if GW_DEBUG_MODE
290
 
        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
 
580
        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
291
581
#endif
292
582
 
293
 
        if ( (my_plugins_manager.file_descr_funcs != NULL) && (ext != NULL) )
294
 
        {
 
583
        if ( (my_plugins_manager.file_descr_funcs != NULL) && (ext != NULL) ) {
295
584
                g_strdown ( ext_lower = g_strdup ( ext));
296
585
                *f = g_hash_table_lookup ( my_plugins_manager.file_descr_funcs, ext_lower);
297
586
                g_free ( ext_lower);
301
590
}
302
591
 
303
592
 
304
 
gint gw_plugins_manager_get_files_descr_func ( const gchar *name, func_get_files_descr_t *f)
305
 
{
 
593
gint gw_pm_get_files_descr_func ( const gchar *name, func_get_files_descr_t *f) {
306
594
        gint result = -1;
307
595
        gchar *name_lower = NULL;
308
596
 
309
597
 
310
598
#if GW_DEBUG_MODE
311
 
        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
 
599
        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
312
600
#endif
313
601
 
314
 
        if ( (my_plugins_manager.files_descr_funcs != NULL) && ( name != NULL) )
315
 
        {
 
602
        if ( (my_plugins_manager.files_descr_funcs != NULL) && ( name != NULL) ) {
316
603
                g_strdown ( name_lower = g_strdup ( name));
317
604
                *f = g_hash_table_lookup ( my_plugins_manager.files_descr_funcs, name_lower);
318
605
                g_free ( name_lower);
322
609
}
323
610
 
324
611
 
325
 
gint gw_plugins_manager_get_parent_descr_func ( const gchar *name, func_get_parent_descr_t *f)
326
 
{
 
612
gint gw_pm_get_parent_descr_func ( const gchar *name, func_get_parent_descr_t *f) {
327
613
        gint result = -1;
328
614
        gchar *name_lower = NULL;
329
615
 
330
616
 
331
617
#if GW_DEBUG_MODE
332
 
        gw_application_manager_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
 
618
        gw_am_log_msg ( 0, __FILE__, __LINE__, __PRETTY_FUNCTION__, NULL);
333
619
#endif
334
620
 
335
 
        if ( (my_plugins_manager.parent_descr_funcs != NULL) && (name != NULL) )
336
 
        {
 
621
        if ( (my_plugins_manager.parent_descr_funcs != NULL) && (name != NULL) ) {
337
622
                g_strdown ( name_lower = g_strdup ( name));
338
623
                *f = g_hash_table_lookup ( my_plugins_manager.parent_descr_funcs, name_lower);
339
624
                g_free ( name_lower);
343
628
}
344
629
 
345
630
 
346
 
gint gw_plugins_manager_exit ( )
347
 
{
 
631
gint gw_pm_exit ( ) {
348
632
        gint result = -1;
349
633
 
350
634
 
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);
353
637
#endif
354
638
 
355
 
        if ( my_plugins_manager.catalog_plugins != NULL )
356
 
        {
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;
360
644
        }
361
645
 
362
 
        if ( my_plugins_manager.file_descr_funcs != NULL )
363
 
        {
 
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;
366
649
        }
367
650
 
368
 
        if ( my_plugins_manager.files_descr_funcs != NULL )
369
 
        {
 
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;
372
654
        }
373
655
 
374
 
        if ( my_plugins_manager.parent_descr_funcs != NULL )
375
 
        {
 
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;
378
659
        }
379
660
 
380
 
        if ( my_plugins_manager.descr_plugins != NULL )
381
 
        {
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;
385
665
        }
386
666
 
387
667
        return result;
388
668
}
 
669
 
 
670
 
 
671
GWCatalogPlugin * gw_pm_get_catalog_plugin ( gchar* name) {
 
672
        GWCatalogPlugin * catalog_plugin = NULL;
 
673
 
 
674
 
 
675
        if ( my_plugins_manager.catalog_plugins != NULL) {
 
676
                GWPlugin *plugin = g_hash_table_lookup ( my_plugins_manager.catalog_plugins, name);
 
677
 
 
678
                if ( plugin != NULL) {
 
679
                        catalog_plugin = plugin->data;
 
680
                } else {}
 
681
        } else {}
 
682
 
 
683
 
 
684
        return catalog_plugin;
 
685
}
 
686
 
 
687
 
 
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");
 
691
}
 
692
 
 
693
 
 
694
void gw_pm_add_plugin_name ( gpointer key, gpointer value, gpointer data) {
 
695
        gchar **names = data;
 
696
        gchar *name = key;
 
697
        GWPlugin *plugin = value;
 
698
        gint i = 0;
 
699
 
 
700
 
 
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++);
 
705
                        names[i] = name;
 
706
                } else {}
 
707
        }
 
708
}
 
709
 
 
710
 
 
711
gchar ** gw_pm_get_all_catalog_import_plugin_name ( ) {
 
712
        gchar **names = NULL;
 
713
        gint i = 0, nb = 0;
 
714
 
 
715
 
 
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 ) {
 
719
                                nb--;
 
720
                        }
 
721
 
 
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);
 
725
                } else {}
 
726
        } else {}
 
727
 
 
728
        return names;
 
729
}
 
730
 
 
731
 
 
732
gchar ** gw_pm_get_all_catalog_export_plugin_name ( ) {
 
733
        gchar **names = NULL;
 
734
        gint i = 0, nb = 0;
 
735
 
 
736
 
 
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 ) {
 
740
                                nb--;
 
741
                        }
 
742
 
 
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);
 
746
                } else {}
 
747
        } else {}
 
748
 
 
749
        return names;
 
750
}
 
751
 
 
752
 
 
753
void gw_pm_set_current_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
 
754
        my_plugins_manager.current_ctg_plugin = ctg_plugin;
 
755
}
 
756
 
 
757
 
 
758
GWCatalogPlugin * gw_pm_get_current_catalog_plugin ( ) {
 
759
        return my_plugins_manager.current_ctg_plugin;
 
760
}
 
761
 
 
762
 
 
763
void gw_pm_set_selected_import_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
 
764
        my_plugins_manager.selected_import_ctg_pugin = ctg_plugin;
 
765
}
 
766
 
 
767
 
 
768
GWCatalogPlugin * gw_pm_get_selected_import_catalog_plugin ( ) {
 
769
        return my_plugins_manager.selected_import_ctg_pugin;
 
770
}
 
771
 
 
772
 
 
773
void gw_pm_set_selected_export_catalog_plugin ( GWCatalogPlugin *ctg_plugin) {
 
774
        my_plugins_manager.selected_export_ctg_pugin = ctg_plugin;
 
775
}
 
776
 
 
777
 
 
778
GWCatalogPlugin * gw_pm_get_selected_export_catalog_plugin ( ) {
 
779
        return my_plugins_manager.selected_export_ctg_pugin;
 
780
}