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-server-provider-extra.h>
26 #include <libgda/binreloc/gda-binreloc.h>
27 #include "gda-capi.h"
28 #include "gda-capi-provider.h"
29 
30 static gchar      *module_path = NULL;
31 const gchar       *plugin_get_name (void);
32 const gchar       *plugin_get_description (void);
33 gchar             *plugin_get_dsn_spec (void);
34 GdaServerProvider *plugin_create_provider (void);
35 
36 /*
37  * Functions executed when calling g_module_open() and g_module_close()
38  */
39 const gchar *
g_module_check_init(G_GNUC_UNUSED GModule * module)40 g_module_check_init (G_GNUC_UNUSED GModule *module)
41 {
42         /*g_module_make_resident (module);*/
43         return NULL;
44 }
45 
46 void
g_module_unload(G_GNUC_UNUSED GModule * module)47 g_module_unload (G_GNUC_UNUSED GModule *module)
48 {
49         g_free (module_path);
50         module_path = NULL;
51 }
52 
53 /*
54  * Normal plugin functions
55  */
56 void
plugin_init(const gchar * real_path)57 plugin_init (const gchar *real_path)
58 {
59         if (real_path)
60                 module_path = g_strdup (real_path);
61 }
62 
63 const gchar *
plugin_get_name(void)64 plugin_get_name (void)
65 {
66 	return CAPI_PROVIDER_NAME;
67 }
68 
69 const gchar *
plugin_get_description(void)70 plugin_get_description (void)
71 {
72 	return _("Example provider for C API databases");
73 }
74 
75 gchar *
plugin_get_dsn_spec(void)76 plugin_get_dsn_spec (void)
77 {
78 	gchar *ret, *dir;
79 
80 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
81 	ret = gda_server_provider_load_file_contents (module_path, dir, "capi_specs_dsn.xml");
82 	g_free (dir);
83 	return ret;
84 }
85 
86 GdaServerProvider *
plugin_create_provider(void)87 plugin_create_provider (void)
88 {
89 	GdaServerProvider *prov;
90 
91 	prov = (GdaServerProvider*) g_object_new (GDA_TYPE_CAPI_PROVIDER, NULL);
92         g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
93         return prov;
94 }
95