fa1a66decba846cd7bef43bdf5bfae2966823cc9
[gnome.gobject-introspection] / tests / scanner / foo.c
1 #define FOO_SUCCESS_INT 0x1138
2
3 #include "foo.h"
4
5 /* A hidden type not exposed publicly, similar to GUPNP's XML wrapper
6    object */
7 typedef struct _FooHidden FooHidden;
8
9 int foo_init_argv (int argc, char **argv);
10 int foo_init_argv_address (int *argc, char ***argv);
11 void foo_private_function (FooObject *foo);
12 void foo_test_unsigned (unsigned int uint);
13 void foo_interface_do_foo (FooInterface *self);
14 void foo_do_foo (FooInterface *self);
15 int foo_enum_method (FooEnumType foo_enum);
16 FooHidden * foo_hidden_copy (const FooHidden *boxed);
17 void foo_hidden_free (FooHidden *boxed);
18 GType foo_hidden_get_type (void);
19 FooBoxed *foo_boxed_copy (const FooBoxed *boxed);
20 void foo_boxed_free (FooBoxed *boxed);
21 void foo_dbus_data_free (FooDBusData *boxed);
22 FooDBusData *foo_dbus_data_copy (const FooDBusData *boxed);
23
24 typedef struct
25 {
26   int i;
27 } PrivateStruct;
28
29 void foo_private_function (FooObject *foo)
30 {
31
32 }
33
34 GType
35 foo_interface_get_type (void)
36 {
37   static GType object_type = 0;
38
39   if (!object_type)
40     {
41       object_type = g_type_register_static_simple (G_TYPE_INTERFACE,
42                                                    "FooInterface",
43                                                    sizeof (FooInterfaceIface),
44                                                    NULL, 0, NULL, 0);
45
46       g_type_interface_add_prerequisite (object_type, G_TYPE_OBJECT);
47     }
48
49   return object_type;
50 }
51
52 void foo_interface_do_foo (FooInterface *self)
53 {
54   FOO_INTERFACE_GET_INTERFACE(self)->do_foo (self);
55 }
56
57 enum {
58   PROP_0,
59   PROP_STRING,
60   PROP_HIDDEN
61 };
62
63 enum {
64   SIGNAL,
65   LAST_SIGNAL
66 };
67
68 static guint foo_object_signals[LAST_SIGNAL] = { 0 };
69
70 static void
71 foo_foo_interface_init (gpointer         g_iface,
72                         gpointer         iface_data)
73 {
74   FooInterfaceIface *iface = (FooInterfaceIface *)g_iface;
75   iface->do_foo = foo_do_foo;
76 }
77
78 GType
79 foo_sub_interface_get_type (void)
80 {
81   static GType object_type = 0;
82
83   if (!object_type)
84     {
85       object_type = g_type_register_static_simple (G_TYPE_INTERFACE,
86                                                    "FooSubInterface",
87                                                    sizeof (FooSubInterfaceIface),
88                                                    NULL, 0, NULL, 0);
89
90       g_type_interface_add_prerequisite (object_type, FOO_TYPE_INTERFACE);
91     }
92
93   return object_type;
94 }
95
96 void foo_sub_interface_do_bar (FooSubInterface *self)
97 {
98   FOO_SUBINTERFACE_GET_INTERFACE(self)->do_bar (self);
99 }
100
101
102 G_DEFINE_TYPE_EXTENDED (FooObject, foo_object, G_TYPE_OBJECT,
103                         0, G_IMPLEMENT_INTERFACE (FOO_TYPE_INTERFACE,
104                                                   foo_foo_interface_init));
105
106 static void
107 foo_object_set_property (GObject         *object,
108                          guint            prop_id,
109                          const GValue    *value,
110                          GParamSpec      *pspec)
111 {
112   switch (prop_id)
113     {
114     case PROP_STRING:
115       break;
116     case PROP_HIDDEN:
117       break;
118     default:
119       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
120       break;
121     }
122 }
123
124 static void
125 foo_object_get_property (GObject         *object,
126                          guint            prop_id,
127                          GValue          *value,
128                          GParamSpec      *pspec)
129 {
130   switch (prop_id)
131     {
132     case PROP_STRING:
133       break;
134     case PROP_HIDDEN:
135       break;
136     default:
137       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
138       break;
139     }
140 }
141
142 static void
143 foo_object_class_init (FooObjectClass *klass)
144 {
145   GObjectClass *gobject_class;
146
147   gobject_class = G_OBJECT_CLASS (klass);
148
149   gobject_class->set_property = foo_object_set_property;
150   gobject_class->get_property = foo_object_get_property;
151
152   g_object_class_install_property (gobject_class,
153                                    PROP_STRING,
154                                    g_param_spec_string ("string",
155                                                         "String nick",
156                                                         "The String Property Blurb",
157                                                         NULL,
158                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
159   g_object_class_install_property (gobject_class,
160                                    PROP_HIDDEN,
161                                    g_param_spec_boxed ("hidden",
162                                                        "hidden property",
163                                                        "should not be exposed",
164                                                        foo_hidden_get_type (),
165                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
166   foo_object_signals[SIGNAL] =
167     g_signal_new ("signal",
168                   G_OBJECT_CLASS_TYPE (gobject_class),
169                   G_SIGNAL_RUN_LAST,
170                   0,
171                   NULL, NULL,
172                   (GSignalCMarshaller)g_cclosure_marshal_STRING__OBJECT_POINTER,
173                   G_TYPE_STRING, 2, G_TYPE_OBJECT, G_TYPE_POINTER);
174
175 }
176
177 static void
178 foo_object_init (FooObject *object)
179 {
180
181 }
182
183 UtilityObject*
184 foo_object_external_type (FooObject *object)
185 {
186   return NULL;
187 }
188
189 void                  
190 foo_object_take_all (FooObject *object, int x, ...)
191 {
192
193 }
194
195 void
196 foo_do_foo (FooInterface *self)
197 {
198
199
200 }
201
202 void
203 foo_object_is_it_time_yet (FooObject *object, time_t time)
204 {
205 }
206
207 const char *
208 foo_object_get_name (FooObject *object)
209 {
210   return "foo";
211 }
212
213 char *
214 foo_object_dup_name (FooObject *object)
215 {
216   return g_strdup ("foo");
217 }
218
219 G_DEFINE_ABSTRACT_TYPE (FooSubobject, foo_subobject, FOO_TYPE_OBJECT);
220
221 static void
222 foo_subobject_class_init (FooSubobjectClass *klass)
223 {
224
225 }
226
227 static void
228 foo_subobject_init (FooSubobject *object)
229 {
230
231 }
232
233 int foo_init (void)
234 {
235   return FOO_SUCCESS_INT;
236 }
237
238 int foo_init_argv (int argc, char **argv)
239 {
240   return FOO_SUCCESS_INT;
241 }
242
243 int foo_init_argv_address (int *argc, char ***argv)
244 {
245   return FOO_SUCCESS_INT;
246 }
247
248 GType
249 foo_enum_type_get_type (void)
250 {
251     static GType etype = 0;
252     if (G_UNLIKELY(etype == 0)) {
253         static const GEnumValue values[] = {
254             { FOO_ENUM_ALPHA, "FOO_ENUM_ALPHA", "alpha" },
255             { FOO_ENUM_BETA, "FOO_ENUM_BETA", "beta" },
256             { FOO_ENUM_DELTA, "FOO_ENUM_DELTA", "delta" },
257             { 0, NULL, NULL }
258         };
259         etype = g_enum_register_static (g_intern_static_string ("FooEnumType"), values);
260     }
261     return etype;
262 }
263
264 int foo_enum_method (FooEnumType foo_enum)
265 {
266   return 0;
267 }
268
269
270 GType
271 foo_flags_type_get_type (void)
272 {
273     static GType etype = 0;
274     if (G_UNLIKELY(etype == 0)) {
275         static const GFlagsValue values[] = {
276             { FOO_FLAGS_FIRST, "FOO_FLAGS_FIRST", "first" },
277             { FOO_FLAGS_SECOND, "FOO_FLAGS_SECOND", "second" },
278             { FOO_FLAGS_THIRD, "FOO_FLAGS_THIRD", "third" },
279             { 0, NULL, NULL }
280         };
281         etype = g_flags_register_static (g_intern_static_string ("FooFlagsType"), values);
282     }
283     return etype;
284 }
285
286 struct _FooBoxed
287 {
288   int private;
289 };
290
291
292 FooBoxed *
293 foo_boxed_copy (const FooBoxed *boxed)
294 {
295   return (FooBoxed *)g_memdup (boxed, sizeof (FooBoxed));
296 }
297
298 void
299 foo_boxed_free (FooBoxed *boxed)
300 {
301   g_slice_free (FooBoxed, boxed);
302 }
303
304
305 GType
306 foo_boxed_get_type (void)
307 {
308   static GType our_type = 0;
309   
310   if (our_type == 0)
311     our_type = g_boxed_type_register_static ("FooBoxed",
312                                              (GBoxedCopyFunc) foo_boxed_copy,
313                                              (GBoxedFreeFunc) foo_boxed_free);
314   return our_type;
315 }
316
317 FooBoxed *
318 foo_boxed_new (void)
319 {
320   return g_slice_new0 (FooBoxed);
321 }
322
323 void
324 foo_boxed_method (FooBoxed *boxed)
325 {
326
327 }
328
329 /* FooDbus */
330 struct _FooDBusData
331 {
332   double private;
333 };
334
335 FooDBusData *
336 foo_dbus_data_copy (const FooDBusData *boxed)
337 {
338   return (FooDBusData *)g_memdup (boxed, sizeof (FooDBusData));
339 }
340
341 void
342 foo_dbus_data_free (FooDBusData *boxed)
343 {
344   g_slice_free (FooDBusData, boxed);
345 }
346
347
348 GType
349 foo_dbus_data_get_type (void)
350 {
351   static GType our_type = 0;
352   
353   if (our_type == 0)
354     our_type = g_boxed_type_register_static ("FooDBusData",
355                                              (GBoxedCopyFunc) foo_dbus_data_copy,
356                                              (GBoxedFreeFunc) foo_dbus_data_free);
357   return our_type;
358 }
359
360 GType
361 foo_brect_get_type (void)
362 {
363   static GType our_type = 0;
364   
365   if (our_type == 0)
366     our_type = g_boxed_type_register_static ("FooBRect",
367                                              (GBoxedCopyFunc) g_memdup, /* Won't work */
368                                              (GBoxedFreeFunc) g_free);
369   return our_type;
370 }
371
372 GType
373 foo_bunion_get_type (void)
374 {
375   static GType our_type = 0;
376   
377   if (our_type == 0)
378     our_type = g_boxed_type_register_static ("FooBUnion",
379                                              (GBoxedCopyFunc) g_memdup, /* Won't work */
380                                              (GBoxedFreeFunc) g_free);
381   return our_type;
382 }
383
384 void foo_test_unsigned (unsigned int uint)
385 {
386 }
387
388 void
389 foo_test_string_array (char **array)
390 {
391 }
392
393 /**
394  * foo_rectangle_add:
395  * @r1: (inout): add to this rect
396  * @r2: source rectangle
397  */
398 void
399 foo_rectangle_add(FooRectangle *r1, const FooRectangle *r2)
400 {
401
402 }
403
404 /* FooHidden */
405
406 struct _FooHidden
407 {
408   char *frob;
409 };
410
411 FooHidden *
412 foo_hidden_copy (const FooHidden *boxed)
413 {
414   return (FooHidden *)g_memdup (boxed, sizeof (FooHidden));
415 }
416
417 void
418 foo_hidden_free (FooHidden *boxed)
419 {
420   g_slice_free (FooHidden, boxed);
421 }
422
423 GType
424 foo_hidden_get_type (void)
425 {
426   static GType our_type = 0;
427
428   if (our_type == 0)
429     our_type = g_boxed_type_register_static ("FooHidden",
430                                              (GBoxedCopyFunc) foo_hidden_copy,
431                                              (GBoxedFreeFunc) foo_hidden_free);
432   return our_type;
433 }
434
435 GType
436 foo_error_get_type (void)
437 {
438     static GType etype = 0;
439     if (G_UNLIKELY(etype == 0)) {
440         static const GEnumValue values[] = {
441             { FOO_ERROR_GOOD, "FOO_ERROR_GOOD", "good" },
442             { FOO_ERROR_BAD, "FOO_ERROR_BAD", "bad" },
443             { FOO_ERROR_UGLY, "FOO_ERROR_UGLY", "ugly" },
444             { 0, NULL, NULL }
445         };
446         etype = g_enum_register_static (g_intern_static_string ("FooError"), values);
447     }
448     return etype;
449 }
450
451 GQuark
452 foo_error_quark (void)
453 {
454   return g_quark_from_static_string ("foo-error-quark");
455 }
456
457 void
458 foo_some_variant (guint x, va_list args)
459 {
460 }
461
462 /* This setup of a totally hidden parent class matches
463  * http://bugzilla.gnome.org/show_bug.cgi?id=561360
464  */
465 #define FOO_TYPE_TILE_HANDLER        (foo_tile_handler_get_type ())
466 #define FOO_TILE_HANDLER(object)     (G_TYPE_CHECK_INSTANCE_CAST ((object), FOO_TYPE_TILE_HANDLER, FooTileHandler))
467 #define FOO_IS_TILE_HANDLER(object)  (G_TYPE_CHECK_INSTANCE_TYPE ((object), FOO_TYPE_TILE_HANDLER))
468
469 struct _FooTileHandler
470 {
471   FooObject parent_instance;
472 };
473
474
475 struct _FooTileHandlerClass
476 {
477   FooObjectClass parent_class;
478 };
479
480 typedef struct _FooTileHandler          FooTileHandler;
481 typedef struct _FooTileHandlerClass     FooTileHandlerClass;
482
483 G_DEFINE_TYPE(FooTileHandler, foo_tile_handler, FOO_TYPE_OBJECT);
484
485 static void
486 foo_tile_handler_class_init (FooTileHandlerClass *klass)
487 {
488
489 }
490
491 static void
492 foo_tile_handler_init (FooTileHandler *object)
493 {
494
495 }
496
497 struct _FooBuffer
498 {
499   FooTileHandler parent_instance;
500 };
501
502 struct _FooBufferClass
503 {
504   FooTileHandlerClass parent_class;
505 };
506
507 G_DEFINE_TYPE(FooBuffer, foo_buffer, FOO_TYPE_TILE_HANDLER);
508
509 static void
510 foo_buffer_class_init (FooBufferClass *klass)
511 {
512
513 }
514
515 static void
516 foo_buffer_init (FooBuffer *object)
517 {
518
519 }
520
521 void
522 foo_buffer_some_method (FooBuffer *buffer)
523 {
524 }