1 /*
2 * Copyright (C) YEAR The GNOME Foundation
3 *
4 * AUTHORS:
5 * TO_ADD: your name and email
6 * Vivien Malerba <malerba@gnome-db.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <glib/gi18n-lib.h>
24 #include <gmodule.h>
25 #include <libgda/gda-config.h>
26 #include <libgda/gda-server-provider-extra.h>
27 #include <libgda/binreloc/gda-binreloc.h>
28 #include "gda-models.h"
29 #include "gda-models-provider.h"
30
31 static gchar *module_path = NULL;
32 const gchar *plugin_get_name (void);
33 const gchar *plugin_get_description (void);
34 gchar *plugin_get_dsn_spec (void);
35 GdaServerProvider *plugin_create_provider (void);
36
37 /*
38 * Functions executed when calling g_module_open() and g_module_close()
39 */
40 const gchar *
g_module_check_init(G_GNUC_UNUSED GModule * module)41 g_module_check_init (G_GNUC_UNUSED GModule *module)
42 {
43 /*g_module_make_resident (module);*/
44 return NULL;
45 }
46
47 void
g_module_unload(G_GNUC_UNUSED GModule * module)48 g_module_unload (G_GNUC_UNUSED GModule *module)
49 {
50 g_free (module_path);
51 module_path = NULL;
52 }
53
54 /*
55 * Normal plugin functions
56 */
57 void
plugin_init(const gchar * real_path)58 plugin_init (const gchar *real_path)
59 {
60 if (real_path)
61 module_path = g_strdup (real_path);
62 }
63
64 const gchar *
plugin_get_name(void)65 plugin_get_name (void)
66 {
67 return MODELS_PROVIDER_NAME;
68 }
69
70 const gchar *
plugin_get_description(void)71 plugin_get_description (void)
72 {
73 return _("Example provider for database where tables are based on data models");
74 }
75
76 gchar *
plugin_get_dsn_spec(void)77 plugin_get_dsn_spec (void)
78 {
79 gchar *ret, *dir;
80
81 dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
82 ret = gda_server_provider_load_file_contents (module_path, dir, "models_specs_dsn.xml");
83 g_free (dir);
84 return ret;
85 }
86
87 gchar *
plugin_get_auth_spec(void)88 plugin_get_auth_spec (void)
89 {
90 #define AUTH "<?xml version=\"1.0\"?>" \
91 "<data-set-spec>" \
92 " <parameters/>" \
93 "</data-set-spec>"
94
95 return g_strdup (AUTH);
96 }
97
98 GdaServerProvider *
plugin_create_provider(void)99 plugin_create_provider (void)
100 {
101 GdaServerProvider *prov;
102
103 prov = (GdaServerProvider *) g_object_new (GDA_TYPE_MODELS_PROVIDER, NULL);
104 g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
105 return prov;
106 }
107