1 /*
2  * Copyright (C) 2007 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  * Copyright (C) 2010 David King <davidk@openismus.com>
4  * Copyright (C) 2011 Murray Cumming <murrayc@murrayc.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301, USA.
20  */
21 
22 #include <glib/gi18n-lib.h>
23 #include <string.h>
24 #include <sqlite3.h>
25 #include "gda-virtual-provider.h"
26 
27 #define PARENT_TYPE GDA_TYPE_SQLITE_PROVIDER
28 #define CLASS(obj) (GDA_VIRTUAL_PROVIDER_CLASS (G_OBJECT_GET_CLASS (obj)))
29 
30 static void gda_virtual_provider_class_init (GdaVirtualProviderClass *klass);
31 static void gda_virtual_provider_init       (GdaVirtualProvider *prov, GdaVirtualProviderClass *klass);
32 static void gda_virtual_provider_finalize   (GObject *object);
33 static GObjectClass *parent_class = NULL;
34 
35 static gboolean gda_virtual_provider_close_connection (GdaServerProvider *prov,
36 						       GdaConnection *cnc);
37 
38 /*
39  * GdaVirtualProvider class implementation
40  */
41 static void
gda_virtual_provider_class_init(GdaVirtualProviderClass * klass)42 gda_virtual_provider_class_init (GdaVirtualProviderClass *klass)
43 {
44 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
45 	GdaServerProviderClass *prov_class = GDA_SERVER_PROVIDER_CLASS (klass);
46 
47 	parent_class = g_type_class_peek_parent (klass);
48 
49 	/* virtual methods */
50 	object_class->finalize = gda_virtual_provider_finalize;
51 	prov_class->close_connection = gda_virtual_provider_close_connection;
52 }
53 
54 static void
gda_virtual_provider_init(G_GNUC_UNUSED GdaVirtualProvider * vprov,G_GNUC_UNUSED GdaVirtualProviderClass * klass)55 gda_virtual_provider_init (G_GNUC_UNUSED GdaVirtualProvider *vprov, G_GNUC_UNUSED GdaVirtualProviderClass *klass)
56 {
57 }
58 
59 static void
gda_virtual_provider_finalize(GObject * object)60 gda_virtual_provider_finalize (GObject *object)
61 {
62 	GdaVirtualProvider *prov = (GdaVirtualProvider *) object;
63 
64 	g_return_if_fail (GDA_IS_VIRTUAL_PROVIDER (prov));
65 
66 	/* chain to parent class */
67 	parent_class->finalize (object);
68 }
69 
70 static gboolean
gda_virtual_provider_close_connection(GdaServerProvider * prov,GdaConnection * cnc)71 gda_virtual_provider_close_connection (GdaServerProvider *prov, GdaConnection *cnc)
72 {
73 	g_return_val_if_fail (GDA_IS_VIRTUAL_PROVIDER (prov), FALSE);
74 	return GDA_SERVER_PROVIDER_CLASS (parent_class)->close_connection (prov, cnc);
75 }
76 
77 GType
gda_virtual_provider_get_type(void)78 gda_virtual_provider_get_type (void)
79 {
80 	static GType type = 0;
81 
82 	if (G_UNLIKELY (type == 0)) {
83 		static GMutex registering;
84 		if (type == 0) {
85 			static GTypeInfo info = {
86 				sizeof (GdaVirtualProviderClass),
87 				(GBaseInitFunc) NULL,
88 				(GBaseFinalizeFunc) NULL,
89 				(GClassInitFunc) gda_virtual_provider_class_init,
90 				NULL, NULL,
91 				sizeof (GdaVirtualProvider),
92 				0,
93 				(GInstanceInitFunc) gda_virtual_provider_init,
94 				0
95 			};
96 
97 		g_mutex_lock (&registering);
98 		if (type == 0)
99 			type = g_type_register_static (PARENT_TYPE, "GdaVirtualProvider", &info, G_TYPE_FLAG_ABSTRACT);
100 		g_mutex_unlock (&registering);
101 		}
102 	}
103 
104 	return type;
105 }
106