1 /*
2  * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  * Copyright (C) 2011 Murray Cumming <murrayc@murrayc.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 "dummy-object.h"
21 #include <glib-object.h>
22 
23 /*
24  * Main static functions
25  */
26 static void dummy_object_class_init (DummyObjectClass * class);
27 static void dummy_object_init (DummyObject *object);
28 
29 /* get a pointer to the parents to be able to call their destructor */
30 static GObjectClass  *parent_class = NULL;
31 
32 /* signals */
33 enum
34 {
35 	SIG0,
36         SIG1,
37         SIG2,
38         LAST_SIGNAL
39 };
40 
41 static gint dummy_object_signals[LAST_SIGNAL] = { 0, 0, 0 };
42 
43 GType
dummy_object_get_type(void)44 dummy_object_get_type (void)
45 {
46 	static GType type = 0;
47 
48 	if (G_UNLIKELY (type == 0)) {
49 		static GMutex registering;
50 		static const GTypeInfo info = {
51 			sizeof (DummyObjectClass),
52 			(GBaseInitFunc) NULL,
53 			(GBaseFinalizeFunc) NULL,
54 			(GClassInitFunc) dummy_object_class_init,
55 			NULL,
56 			NULL,
57 			sizeof (DummyObject),
58 			0,
59 			(GInstanceInitFunc) dummy_object_init,
60 			NULL
61 		};
62 
63 		g_mutex_lock (&registering);
64 		if (type == 0)
65 			type = g_type_register_static (G_TYPE_OBJECT, "DummyObject", &info, 0);
66 		g_mutex_unlock (&registering);
67 	}
68 
69 	return type;
70 }
71 
72 /* VOID:STRING,INT (gda-marshal.list:39) */
73 #define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
74 #define g_marshal_value_peek_int(v)      g_value_get_int (v)
75 static void
local_marshal_VOID__STRING_INT(GClosure * closure,GValue * return_value G_GNUC_UNUSED,guint n_param_values,const GValue * param_values,gpointer invocation_hint G_GNUC_UNUSED,gpointer marshal_data)76 local_marshal_VOID__STRING_INT (GClosure     *closure,
77                                GValue       *return_value G_GNUC_UNUSED,
78                                guint         n_param_values,
79                                const GValue *param_values,
80                                gpointer      invocation_hint G_GNUC_UNUSED,
81                                gpointer      marshal_data)
82 {
83   typedef void (*GMarshalFunc_VOID__STRING_INT) (gpointer     data1,
84                                                  gpointer     arg_1,
85                                                  gint         arg_2,
86                                                  gpointer     data2);
87   register GMarshalFunc_VOID__STRING_INT callback;
88   register GCClosure *cc = (GCClosure*) closure;
89   register gpointer data1, data2;
90 
91   g_return_if_fail (n_param_values == 3);
92 
93   if (G_CCLOSURE_SWAP_DATA (closure))
94     {
95       data1 = closure->data;
96       data2 = g_value_peek_pointer (param_values + 0);
97     }
98   else
99     {
100       data1 = g_value_peek_pointer (param_values + 0);
101       data2 = closure->data;
102     }
103   callback = (GMarshalFunc_VOID__STRING_INT) (marshal_data ? marshal_data : cc->callback);
104 
105   callback (data1,
106             g_marshal_value_peek_string (param_values + 1),
107             g_marshal_value_peek_int (param_values + 2),
108             data2);
109 }
110 
111 static void
dummy_object_class_init(DummyObjectClass * class)112 dummy_object_class_init (DummyObjectClass *class)
113 {
114 	GObjectClass *object_class = G_OBJECT_CLASS (class);
115 
116 	parent_class = g_type_class_peek_parent (class);
117 
118 	dummy_object_signals[SIG0] =
119                 g_signal_new ("sig0",
120                               G_TYPE_FROM_CLASS (object_class),
121                               G_SIGNAL_RUN_FIRST,
122                               G_STRUCT_OFFSET (DummyObjectClass, sig0),
123                               NULL, NULL,
124                               g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
125 	dummy_object_signals[SIG1] =
126                 g_signal_new ("sig1",
127                               G_TYPE_FROM_CLASS (object_class),
128                               G_SIGNAL_RUN_FIRST,
129                               G_STRUCT_OFFSET (DummyObjectClass, sig1),
130                               NULL, NULL,
131                               g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
132 	dummy_object_signals[SIG1] =
133                 g_signal_new ("sig2",
134                               G_TYPE_FROM_CLASS (object_class),
135                               G_SIGNAL_RUN_FIRST,
136                               G_STRUCT_OFFSET (DummyObjectClass, sig1),
137                               NULL, NULL,
138                               local_marshal_VOID__STRING_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
139 
140         class->sig1 = NULL;
141         class->sig0 = NULL;
142         class->sig2 = NULL;
143 }
144 
145 static void
dummy_object_init(DummyObject * object)146 dummy_object_init (DummyObject *object)
147 {
148 }
149 
150 /**
151  * dummy_object_new
152  *
153  * Creates a new object of type @type
154  *
155  * Returns: a new #DummyObject object
156  */
157 DummyObject *
dummy_object_new(void)158 dummy_object_new (void)
159 {
160         return (DummyObject *) g_object_new (DUMMY_TYPE_OBJECT, NULL);
161 }
162