1 /*
2  * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  * Copyright (C) 2010 David King <davidk@openismus.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19 
20 #include <string.h>
21 #include <glib/gi18n-lib.h>
22 #include "browser-variable.h"
23 
24 /*
25  * Main static functions
26  */
27 static void browser_variable_class_init (BrowserVariableClass *klass);
28 static void browser_variable_init (BrowserVariable *bvar);
29 static void browser_variable_dispose (GObject *object);
30 
31 /* get a pointer to the parents to be able to call their destructor */
32 static GObjectClass  *parent_class = NULL;
33 
34 struct _BrowserVariablePrivate {
35 	GdaHolder *holder;
36 };
37 
38 GType
39 browser_variable_get_type (void)
40 {
41 	static GType type = 0;
42 
43 	if (G_UNLIKELY (type == 0)) {
44 		static GMutex registering;
45 		static const GTypeInfo info = {
46 			sizeof (BrowserVariableClass),
47 			(GBaseInitFunc) NULL,
48 			(GBaseFinalizeFunc) NULL,
49 			(GClassInitFunc) browser_variable_class_init,
50 			NULL,
51 			NULL,
52 			sizeof (BrowserVariable),
53 			0,
54 			(GInstanceInitFunc) browser_variable_init,
55 			0
56 		};
57 
58 
59 		g_mutex_lock (&registering);
60 		if (type == 0)
61 			type = g_type_register_static (G_TYPE_OBJECT, "BrowserVariable", &info, 0);
62 		g_mutex_unlock (&registering);
63 	}
64 	return type;
65 }
66 
67 static void
68 browser_variable_class_init (BrowserVariableClass *klass)
69 {
70 	GObjectClass   *object_class = G_OBJECT_CLASS (klass);
71 	parent_class = g_type_class_peek_parent (klass);
72 
73 	object_class->dispose = browser_variable_dispose;
74 }
75 
76 static void
77 browser_variable_init (BrowserVariable *bvar)
78 {
79 	bvar->priv = g_new0 (BrowserVariablePrivate, 1);
80 	bvar->priv->holder = NULL;
81 }
82 
83 /**
84  * browser_variable_new
85  *
86  * Creates a new #BrowserVariable object
87  *
88  * Returns: the new object
89  */
90 BrowserVariable*
91 browser_variable_new (GdaHolder *holder)
92 {
93 	BrowserVariable *bvar;
94 
95 	g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);
96 
97 	bvar = BROWSER_VARIABLE (g_object_new (BROWSER_TYPE_VARIABLE, NULL));
98 	bvar->priv->holder = g_object_ref (holder);
99 
100 	return bvar;
101 }
102 
103 static void
104 browser_variable_dispose (GObject *object)
105 {
106 	BrowserVariable *bvar;
107 
108 	g_return_if_fail (object != NULL);
109 	g_return_if_fail (BROWSER_IS_VARIABLE (object));
110 
111 	bvar = BROWSER_VARIABLE (object);
112 	if (bvar->priv) {
113 		if (bvar->priv->holder)
114 			g_object_unref (bvar->priv->holder);
115 
116 		g_free (bvar->priv);
117 		bvar->priv = NULL;
118 	}
119 
120 	/* parent class */
121 	parent_class->dispose (object);
122 }
123