b0aff37cdd7e190f490c74e277625f24317d51bf
[platform/upstream/gobject-introspection.git] / girepository / giobjectinfo.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2  * GObject introspection: Object implementation
3  *
4  * Copyright (C) 2005 Matthias Clasen
5  * Copyright (C) 2008,2009 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib.h>
24
25 #include <girepository.h>
26 #include "girepository-private.h"
27 #include "gitypelib-internal.h"
28
29 /**
30  * SECTION:giobjectinfo
31  * @title: GIObjectInfo
32  * @short_description: Struct representing a GObject
33  *
34  * GIObjectInfo represents a #GObject. This doesn't represent a specific
35  * instance of a GObject, instead this represent the object type (eg class).
36  *
37  * A GObject has methods, fields, properties, signals, interfaces, constants
38  * and virtual functions.
39  *
40  * <refsect1 id="gi-giobjectinfo.struct-hierarchy" role="struct_hierarchy">
41  * <title role="struct_hierarchy.title">Struct hierarchy</title>
42  * <synopsis>
43  *   <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
44  *    +----<link linkend="gi-GIRegisteredTypeInfo">GIRegisteredTypeInfo</link>
45  *          +----GIObjectInfo
46  * </synopsis>
47  * </refsect1>
48  */
49
50 /**
51  * g_object_info_get_parent:
52  * @info: a #GIObjectInfo
53  *
54  * Obtain the parent of the object type.
55  *
56  * Returns: (transfer full): the #GIObjectInfo. Free the struct by calling
57  * g_base_info_unref() when done.
58  */
59 GIObjectInfo *
60 g_object_info_get_parent (GIObjectInfo *info)
61 {
62   GIRealInfo *rinfo = (GIRealInfo *)info;
63   ObjectBlob *blob;
64
65   g_return_val_if_fail (info != NULL, NULL);
66   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
67
68   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
69
70   if (blob->parent)
71     return (GIObjectInfo *) _g_info_from_entry (rinfo->repository,
72                                                 rinfo->typelib, blob->parent);
73   else
74     return NULL;
75 }
76
77 /**
78  * g_object_info_get_abstract:
79  * @info: a #GIObjectInfo
80  *
81  * Obtain if the object type is an abstract type, eg if it cannot be
82  * instantiated
83  *
84  * Returns: %TRUE if the object type is abstract
85  */
86 gboolean
87 g_object_info_get_abstract (GIObjectInfo *info)
88 {
89   GIRealInfo *rinfo = (GIRealInfo *)info;
90   ObjectBlob *blob;
91
92   g_return_val_if_fail (info != NULL, FALSE);
93   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), FALSE);
94
95   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
96
97   return blob->abstract != 0;
98 }
99
100 /**
101  * g_object_info_get_fundamental:
102  * @info: a #GIObjectInfo
103  *
104  * Obtain if the object type is of a fundamental type which is not
105  * G_TYPE_OBJECT. This is mostly for supporting GstMiniObject.
106  *
107  * Returns: %TRUE if the object type is a fundamental type
108  */
109 gboolean
110 g_object_info_get_fundamental (GIObjectInfo *info)
111 {
112   GIRealInfo *rinfo = (GIRealInfo *)info;
113   ObjectBlob *blob;
114
115   g_return_val_if_fail (info != NULL, FALSE);
116   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), FALSE);
117
118   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
119
120   return blob->fundamental != 0;
121 }
122
123 /**
124  * g_object_info_get_type_name:
125  * @info: a #GIObjectInfo
126  *
127  * Obtain the name of the objects class/type.
128  *
129  * Returns: name of the objects type
130  */
131 const gchar *
132 g_object_info_get_type_name (GIObjectInfo *info)
133 {
134   GIRealInfo *rinfo = (GIRealInfo *)info;
135   ObjectBlob *blob;
136
137   g_return_val_if_fail (info != NULL, NULL);
138   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
139
140   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
141
142   return g_typelib_get_string (rinfo->typelib, blob->gtype_name);
143 }
144
145 /**
146  * g_object_info_get_type_init:
147  * @info: a #GIObjectInfo
148  *
149  * Obtain the function which when called will return the GType
150  * function for which this object type is registered.
151  *
152  * Returns: the type init function
153  */
154 const gchar *
155 g_object_info_get_type_init (GIObjectInfo *info)
156 {
157   GIRealInfo *rinfo = (GIRealInfo *)info;
158   ObjectBlob *blob;
159
160   g_return_val_if_fail (info != NULL, NULL);
161   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
162
163   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
164
165   return g_typelib_get_string (rinfo->typelib, blob->gtype_init);
166 }
167
168 /**
169  * g_object_info_get_n_interfaces:
170  * @info: a #GIObjectInfo
171  *
172  * Obtain the number of interfaces that this object type has.
173  *
174  * Returns: number of interfaces
175  */
176 gint
177 g_object_info_get_n_interfaces (GIObjectInfo *info)
178 {
179   GIRealInfo *rinfo = (GIRealInfo *)info;
180   ObjectBlob *blob;
181
182   g_return_val_if_fail (info != NULL, 0);
183   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
184
185   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
186
187   return blob->n_interfaces;
188 }
189
190 /**
191  * g_object_info_get_interface:
192  * @info: a #GIObjectInfo
193  * @n: index of interface to get
194  *
195  * Obtain an object type interface at index @n.
196  *
197  * Returns: (transfer full): the #GIInterfaceInfo. Free the struct by calling
198  * g_base_info_unref() when done.
199  */
200 GIInterfaceInfo *
201 g_object_info_get_interface (GIObjectInfo *info,
202                              gint          n)
203 {
204   GIRealInfo *rinfo = (GIRealInfo *)info;
205   ObjectBlob *blob;
206
207   g_return_val_if_fail (info != NULL, NULL);
208   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
209
210   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
211
212   return (GIInterfaceInfo *) _g_info_from_entry (rinfo->repository,
213                                                  rinfo->typelib, blob->interfaces[n]);
214 }
215
216 /**
217  * g_object_info_get_n_fields:
218  * @info: a #GIObjectInfo
219  *
220  * Obtain the number of fields that this object type has.
221  *
222  * Returns: number of fields
223  */
224 gint
225 g_object_info_get_n_fields (GIObjectInfo *info)
226 {
227   GIRealInfo *rinfo = (GIRealInfo *)info;
228   ObjectBlob *blob;
229
230   g_return_val_if_fail (info != NULL, 0);
231   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
232
233   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
234
235   return blob->n_fields;
236 }
237
238 /**
239  * g_object_info_get_field:
240  * @info: a #GIObjectInfo
241  * @n: index of field to get
242  *
243  * Obtain an object type field at index @n.
244  *
245  * Returns: (transfer full): the #GIFieldInfo. Free the struct by calling
246  * g_base_info_unref() when done.
247  */
248 GIFieldInfo *
249 g_object_info_get_field (GIObjectInfo *info,
250                          gint          n)
251 {
252   gint offset;
253   GIRealInfo *rinfo = (GIRealInfo *)info;
254   Header *header;
255   ObjectBlob *blob;
256
257   g_return_val_if_fail (info != NULL, NULL);
258   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
259
260   header = (Header *)rinfo->typelib->data;
261   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
262
263   offset = rinfo->offset + header->object_blob_size
264     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
265     + n * header->field_blob_size;
266
267   return (GIFieldInfo *) g_info_new (GI_INFO_TYPE_FIELD, (GIBaseInfo*)info, rinfo->typelib, offset);
268 }
269
270 /**
271  * g_object_info_get_n_properties:
272  * @info: a #GIObjectInfo
273  *
274  * Obtain the number of properties that this object type has.
275  *
276  * Returns: number of properties
277  */
278 gint
279 g_object_info_get_n_properties (GIObjectInfo *info)
280 {
281   GIRealInfo *rinfo = (GIRealInfo *)info;
282   ObjectBlob *blob;
283
284   g_return_val_if_fail (info != NULL, 0);
285   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
286
287   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
288   return blob->n_properties;
289 }
290
291 /**
292  * g_object_info_get_property:
293  * @info: a #GIObjectInfo
294  * @n: index of property to get
295  *
296  * Obtain an object type property at index @n.
297  *
298  * Returns: (transfer full): the #GIPropertyInfo. Free the struct by calling
299  * g_base_info_unref() when done.
300  */
301 GIPropertyInfo *
302 g_object_info_get_property (GIObjectInfo *info,
303                             gint          n)
304 {
305   gint offset;
306   GIRealInfo *rinfo = (GIRealInfo *)info;
307   Header *header;
308   ObjectBlob *blob;
309
310   g_return_val_if_fail (info != NULL, NULL);
311   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
312
313   header = (Header *)rinfo->typelib->data;
314   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
315
316   offset = rinfo->offset + header->object_blob_size
317     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
318     + blob->n_fields * header->field_blob_size
319     + n * header->property_blob_size;
320
321   return (GIPropertyInfo *) g_info_new (GI_INFO_TYPE_PROPERTY, (GIBaseInfo*)info,
322                                         rinfo->typelib, offset);
323 }
324
325 /**
326  * g_object_info_get_n_methods:
327  * @info: a #GIObjectInfo
328  *
329  * Obtain the number of methods that this object type has.
330  *
331  * Returns: number of methods
332  */
333 gint
334 g_object_info_get_n_methods (GIObjectInfo *info)
335 {
336   GIRealInfo *rinfo = (GIRealInfo *)info;
337   ObjectBlob *blob;
338
339   g_return_val_if_fail (info != NULL, 0);
340   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
341
342   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
343
344   return blob->n_methods;
345 }
346
347 /**
348  * g_object_info_get_method:
349  * @info: a #GIObjectInfo
350  * @n: index of method to get
351  *
352  * Obtain an object type method at index @n.
353  *
354  * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
355  * g_base_info_unref() when done.
356  */
357 GIFunctionInfo *
358 g_object_info_get_method (GIObjectInfo *info,
359                           gint          n)
360 {
361   gint offset;
362   GIRealInfo *rinfo = (GIRealInfo *)info;
363   Header *header;
364   ObjectBlob *blob;
365
366   g_return_val_if_fail (info != NULL, NULL);
367   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
368
369   header = (Header *)rinfo->typelib->data;
370   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
371
372
373   offset = rinfo->offset + header->object_blob_size
374     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
375     + blob->n_fields * header->field_blob_size
376     + blob->n_properties * header->property_blob_size
377     + n * header->function_blob_size;
378
379     return (GIFunctionInfo *) g_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
380                                           rinfo->typelib, offset);
381 }
382
383 /**
384  * g_object_info_find_method:
385  * @info: a #GIObjectInfo
386  * @name: name of method to obtain
387  *
388  * Obtain a method of the object type given a @name. %NULL will be
389  * returned if there's no method available with that name.
390  *
391  * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
392  * g_base_info_unref() when done.
393  */
394 GIFunctionInfo *
395 g_object_info_find_method (GIObjectInfo *info,
396                            const gchar  *name)
397 {
398   gint offset;
399   GIRealInfo *rinfo = (GIRealInfo *)info;
400   Header *header;
401   ObjectBlob *blob;
402
403   g_return_val_if_fail (info != NULL, 0);
404   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
405
406   header = (Header *)rinfo->typelib->data;
407   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
408
409   offset = rinfo->offset + header->object_blob_size
410     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
411     + blob->n_fields * header->field_blob_size +
412     + blob->n_properties * header->property_blob_size;
413
414   return _g_base_info_find_method ((GIBaseInfo*)info, offset, blob->n_methods, name);
415 }
416
417 /**
418  * g_object_info_find_method_using_interfaces:
419  * @info: a #GIObjectInfo
420  * @name: name of method to obtain
421  * @implementor: (out) (transfer full): The implementor of the interface
422  *
423  * Obtain a method of the object given a @name, searching both the
424  * object @info and any interfaces it implements.  %NULL will be
425  * returned if there's no method available with that name.
426  *
427  * Note that this function does *not* search parent classes; you will have
428  * to chain up if that's desired.
429  *
430  * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
431  * g_base_info_unref() when done.
432  */
433 GIFunctionInfo *
434 g_object_info_find_method_using_interfaces (GIObjectInfo  *info,
435                                             const gchar   *name,
436                                             GIObjectInfo **implementor)
437 {
438   GIFunctionInfo *result = NULL;
439   GIObjectInfo *implementor_result = NULL;
440
441   result = g_object_info_find_method (info, name);
442   if (result)
443     implementor_result = g_base_info_ref ((GIBaseInfo*) info);
444
445   if (result == NULL)
446     {
447       int n_interfaces;
448       int i;
449
450       n_interfaces = g_object_info_get_n_interfaces (info);
451       for (i = 0; i < n_interfaces; ++i)
452         {
453           GIInterfaceInfo *iface_info;
454
455           iface_info = g_object_info_get_interface (info, i);
456
457           result = g_interface_info_find_method (iface_info, name);
458
459           if (result != NULL)
460             {
461               implementor_result = iface_info;
462               break;
463             }
464           g_base_info_unref ((GIBaseInfo*) iface_info);
465         }
466     }
467   if (implementor)
468     *implementor = implementor_result;
469   else if (implementor_result != NULL)
470     g_base_info_unref ((GIBaseInfo*) implementor_result);
471   return result;
472 }
473
474 /**
475  * g_object_info_get_n_signals:
476  * @info: a #GIObjectInfo
477  *
478  * Obtain the number of signals that this object type has.
479  *
480  * Returns: number of signals
481  */
482 gint
483 g_object_info_get_n_signals (GIObjectInfo *info)
484 {
485   GIRealInfo *rinfo = (GIRealInfo *)info;
486   ObjectBlob *blob;
487
488   g_return_val_if_fail (info != NULL, 0);
489   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
490
491   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
492
493   return blob->n_signals;
494 }
495
496 /**
497  * g_object_info_get_signal:
498  * @info: a #GIObjectInfo
499  * @n: index of signal to get
500  *
501  * Obtain an object type signal at index @n.
502  *
503  * Returns: (transfer full): the #GISignalInfo. Free the struct by calling
504  * g_base_info_unref() when done.
505  */
506 GISignalInfo *
507 g_object_info_get_signal (GIObjectInfo *info,
508                           gint          n)
509 {
510   gint offset;
511   GIRealInfo *rinfo = (GIRealInfo *)info;
512   Header *header;
513   ObjectBlob *blob;
514
515   g_return_val_if_fail (info != NULL, NULL);
516   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
517
518   header = (Header *)rinfo->typelib->data;
519   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
520
521   offset = rinfo->offset + header->object_blob_size
522     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
523     + blob->n_fields * header->field_blob_size
524     + blob->n_properties * header->property_blob_size
525     + blob->n_methods * header->function_blob_size
526     + n * header->signal_blob_size;
527
528   return (GISignalInfo *) g_info_new (GI_INFO_TYPE_SIGNAL, (GIBaseInfo*)info,
529                                       rinfo->typelib, offset);
530 }
531
532 /**
533  * g_object_info_find_signal:
534  * @info: a #GIObjectInfo
535  * @name: Name of signal
536  *
537  * TODO
538  *
539  * Returns: Info for the signal with name @name in @info, or %NULL on failure.
540  */
541 GISignalInfo *
542 g_object_info_find_signal (GIObjectInfo *info,
543                            const gchar  *name)
544 {
545   gint n_signals;
546   gint i;
547
548   n_signals = g_object_info_get_n_signals (info);
549   for (i = 0; i < n_signals; i++)
550     {
551       GISignalInfo *siginfo = g_object_info_get_signal (info, i);
552
553       if (g_strcmp0 (g_base_info_get_name (siginfo), name) != 0)
554         {
555           g_base_info_unref ((GIBaseInfo*)siginfo);
556           continue;
557         }
558
559       return siginfo;
560     }
561   return NULL;
562 }
563
564
565 /**
566  * g_object_info_get_n_vfuncs:
567  * @info: a #GIObjectInfo
568  *
569  * Obtain the number of virtual functions that this object type has.
570  *
571  * Returns: number of virtual functions
572  */
573 gint
574 g_object_info_get_n_vfuncs (GIObjectInfo *info)
575 {
576   GIRealInfo *rinfo = (GIRealInfo *)info;
577   ObjectBlob *blob;
578
579   g_return_val_if_fail (info != NULL, 0);
580   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
581
582   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
583
584   return blob->n_vfuncs;
585 }
586
587 /**
588  * g_object_info_get_vfunc:
589  * @info: a #GIObjectInfo
590  * @n: index of virtual function to get
591  *
592  * Obtain an object type virtual function at index @n.
593  *
594  * Returns: (transfer full): the #GIVFuncInfo. Free the struct by calling
595  * g_base_info_unref() when done.
596  */
597 GIVFuncInfo *
598 g_object_info_get_vfunc (GIObjectInfo *info,
599                          gint          n)
600 {
601   gint offset;
602   GIRealInfo *rinfo = (GIRealInfo *)info;
603   Header *header;
604   ObjectBlob *blob;
605
606   g_return_val_if_fail (info != NULL, NULL);
607   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
608
609   header = (Header *)rinfo->typelib->data;
610   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
611
612   offset = rinfo->offset + header->object_blob_size
613     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
614     + blob->n_fields * header->field_blob_size
615     + blob->n_properties * header->property_blob_size
616     + blob->n_methods * header->function_blob_size
617     + blob->n_signals * header->signal_blob_size
618     + n * header->vfunc_blob_size;
619
620   return (GIVFuncInfo *) g_info_new (GI_INFO_TYPE_VFUNC, (GIBaseInfo*)info,
621                                      rinfo->typelib, offset);
622 }
623
624 /**
625  * g_object_info_find_vfunc:
626  * @info: a #GIObjectInfo
627  * @name: The name of a virtual function to find.
628  *
629  * Locate a virtual function slot with name @name. Note that the namespace
630  * for virtuals is distinct from that of methods; there may or may not be
631  * a concrete method associated for a virtual. If there is one, it may
632  * be retrieved using g_vfunc_info_get_invoker(), otherwise %NULL will be
633  * returned.
634  * See the documentation for g_vfunc_info_get_invoker() for more
635  * information on invoking virtuals.
636  *
637  * Returns: (transfer full): the #GIVFuncInfo, or %NULL. Free it with
638  * g_base_info_unref() when done.
639  */
640 GIVFuncInfo *
641 g_object_info_find_vfunc (GIObjectInfo *info,
642                           const gchar  *name)
643 {
644   gint offset;
645   GIRealInfo *rinfo = (GIRealInfo *)info;
646   Header *header;
647   ObjectBlob *blob;
648
649   g_return_val_if_fail (info != NULL, NULL);
650   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
651
652   header = (Header *)rinfo->typelib->data;
653   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
654
655   offset = rinfo->offset + header->object_blob_size
656     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
657     + blob->n_fields * header->field_blob_size
658     + blob->n_properties * header->property_blob_size
659     + blob->n_methods * header->function_blob_size
660     + blob->n_signals * header->signal_blob_size;
661
662   return _g_base_info_find_vfunc (rinfo, offset, blob->n_vfuncs, name);
663 }
664
665 /**
666  * g_object_info_find_vfunc_using_interfaces:
667  * @info: a #GIObjectInfo
668  * @name: name of method to obtain
669  * @implementor: (out) (transfer full): The implementor of the interface
670  *
671  * Locate a virtual function slot with name @name, searching both the object
672  * @info and any interfaces it implements.  Note that the namespace for
673  * virtuals is distinct from that of methods; there may or may not be a
674  * concrete method associated for a virtual. If there is one, it may be
675  * retrieved using g_vfunc_info_get_invoker(), otherwise %NULL will be
676  * returned.
677  *
678  * Note that this function does *not* search parent classes; you will have
679  * to chain up if that's desired.
680  *
681  * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
682  * g_base_info_unref() when done.
683  */
684 GIVFuncInfo *
685 g_object_info_find_vfunc_using_interfaces (GIObjectInfo  *info,
686                                            const gchar   *name,
687                                            GIObjectInfo **implementor)
688 {
689   GIVFuncInfo *result = NULL;
690   GIObjectInfo *implementor_result = NULL;
691
692   result = g_object_info_find_vfunc (info, name);
693   if (result)
694     implementor_result = g_base_info_ref ((GIBaseInfo*) info);
695
696   if (result == NULL)
697     {
698       int n_interfaces;
699       int i;
700
701       n_interfaces = g_object_info_get_n_interfaces (info);
702       for (i = 0; i < n_interfaces; ++i)
703         {
704           GIInterfaceInfo *iface_info;
705
706           iface_info = g_object_info_get_interface (info, i);
707
708           result = g_interface_info_find_vfunc (iface_info, name);
709
710           if (result != NULL)
711             {
712               implementor_result = iface_info;
713               break;
714             }
715           g_base_info_unref ((GIBaseInfo*) iface_info);
716         }
717     }
718   if (implementor)
719     *implementor = implementor_result;
720   else if (implementor_result != NULL)
721     g_base_info_unref ((GIBaseInfo*) implementor_result);
722   return result;
723 }
724
725 /**
726  * g_object_info_get_n_constants:
727  * @info: a #GIObjectInfo
728  *
729  * Obtain the number of constants that this object type has.
730  *
731  * Returns: number of constants
732  */
733 gint
734 g_object_info_get_n_constants (GIObjectInfo *info)
735 {
736   GIRealInfo *rinfo = (GIRealInfo *)info;
737   ObjectBlob *blob;
738
739   g_return_val_if_fail (info != NULL, 0);
740   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
741
742   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
743
744   return blob->n_constants;
745 }
746
747 /**
748  * g_object_info_get_constant:
749  * @info: a #GIObjectInfo
750  * @n: index of constant to get
751  *
752  * Obtain an object type constant at index @n.
753  *
754  * Returns: (transfer full): the #GIConstantInfo. Free the struct by calling
755  * g_base_info_unref() when done.
756  */
757 GIConstantInfo *
758 g_object_info_get_constant (GIObjectInfo *info,
759                             gint          n)
760 {
761   gint offset;
762   GIRealInfo *rinfo = (GIRealInfo *)info;
763   Header *header;
764   ObjectBlob *blob;
765
766   g_return_val_if_fail (info != NULL, NULL);
767   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
768
769   header = (Header *)rinfo->typelib->data;
770   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
771
772   offset = rinfo->offset + header->object_blob_size
773     + (blob->n_interfaces + blob->n_interfaces % 2) * 2
774     + blob->n_fields * header->field_blob_size
775     + blob->n_properties * header->property_blob_size
776     + blob->n_methods * header->function_blob_size
777     + blob->n_signals * header->signal_blob_size
778     + blob->n_vfuncs * header->vfunc_blob_size
779     + n * header->constant_blob_size;
780
781   return (GIConstantInfo *) g_info_new (GI_INFO_TYPE_CONSTANT, (GIBaseInfo*)info,
782                                         rinfo->typelib, offset);
783 }
784
785 /**
786  * g_object_info_get_class_struct:
787  * @info: a #GIObjectInfo
788  *
789  * Every #GObject has two structures; an instance structure and a class
790  * structure.  This function returns the metadata for the class structure.
791  *
792  * Returns: (transfer full): the #GIStructInfo or %NULL. Free with
793  * g_base_info_unref() when done.
794  */
795 GIStructInfo *
796 g_object_info_get_class_struct (GIObjectInfo *info)
797 {
798   GIRealInfo *rinfo = (GIRealInfo *)info;
799   ObjectBlob *blob;
800
801   g_return_val_if_fail (info != NULL, NULL);
802   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
803
804   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
805
806   if (blob->gtype_struct)
807     return (GIStructInfo *) _g_info_from_entry (rinfo->repository,
808                                                 rinfo->typelib, blob->gtype_struct);
809   else
810     return NULL;
811 }
812
813 typedef const char* (*SymbolGetter) (GIObjectInfo *info);
814
815 static void *
816 _get_func(GIObjectInfo *info,
817           SymbolGetter getter)
818 {
819   const char* symbol;
820   GSList *parents = NULL, *l;
821   GIObjectInfo *parent_info;
822   gpointer func = NULL;
823
824   parent_info = g_base_info_ref (info);
825   while (parent_info != NULL)
826     {
827       parents = g_slist_prepend (parents, parent_info);
828       parent_info = g_object_info_get_parent (parent_info);
829     }
830
831   for (l = parents; l; l = l->next)
832     {
833       parent_info = l->data;
834       symbol = getter (parent_info);
835       if (symbol == NULL)
836         continue;
837
838       g_typelib_symbol (((GIRealInfo *)parent_info)->typelib, symbol, (gpointer*) &func);
839       if (func)
840         break;
841     }
842
843   g_slist_free_full (parents, (GDestroyNotify) g_base_info_unref);
844   return func;
845 }
846
847 /**
848  * g_object_info_get_ref_function:
849  * @info: a #GIObjectInfo
850  *
851  * Obtain the symbol name of the function that should be called to ref this
852  * object type. It's mainly used fundamental types. The type signature for
853  * the symbol is %GIObjectInfoRefFunction, to fetch the function pointer
854  * see g_object_info_get_ref_function().
855  *
856  * Returns: the symbol or %NULL
857  */
858 const char *
859 g_object_info_get_ref_function (GIObjectInfo *info)
860 {
861   GIRealInfo *rinfo = (GIRealInfo *)info;
862   ObjectBlob *blob;
863
864   g_return_val_if_fail (info != NULL, NULL);
865   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
866
867   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
868
869   if (blob->ref_func)
870     return g_typelib_get_string (rinfo->typelib, blob->ref_func);
871
872   return NULL;
873 }
874
875 /**
876  * g_object_info_get_ref_function_pointer: (skip)
877  * @info: a #GIObjectInfo
878  *
879  * Obtain a pointer to a function which can be used to
880  * increase the reference count an instance of this object type.
881  * This takes derivation into account and will reversely traverse
882  * the base classes of this type, starting at the top type.
883  *
884  * Returns: the function pointer or %NULL
885  */
886 GIObjectInfoRefFunction
887 g_object_info_get_ref_function_pointer (GIObjectInfo *info)
888 {
889   g_return_val_if_fail (info != NULL, NULL);
890   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
891
892   return (GIObjectInfoRefFunction)_get_func(info, (SymbolGetter)g_object_info_get_ref_function);
893 }
894
895 /**
896  * g_object_info_get_unref_function:
897  * @info: a #GIObjectInfo
898  *
899  * Obtain the symbol name of the function that should be called to unref this
900  * object type. It's mainly used fundamental types. The type signature for
901  * the symbol is %GIObjectInfoUnrefFunction, to fetch the function pointer
902  * see g_object_info_get_unref_function().
903  *
904  * Returns: the symbol or %NULL
905  */
906 const char *
907 g_object_info_get_unref_function (GIObjectInfo *info)
908 {
909   GIRealInfo *rinfo = (GIRealInfo *)info;
910   ObjectBlob *blob;
911
912   g_return_val_if_fail (info != NULL, NULL);
913   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
914
915   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
916
917   if (blob->unref_func)
918     return g_typelib_get_string (rinfo->typelib, blob->unref_func);
919
920   return NULL;
921 }
922
923 /**
924  * g_object_info_get_unref_function_pointer: (skip)
925  * @info: a #GIObjectInfo
926  *
927  * Obtain a pointer to a function which can be used to
928  * decrease the reference count an instance of this object type.
929  * This takes derivation into account and will reversely traverse
930  * the base classes of this type, starting at the top type.
931  *
932  * Returns: the function pointer or %NULL
933  */
934 GIObjectInfoUnrefFunction
935 g_object_info_get_unref_function_pointer (GIObjectInfo *info)
936 {
937   g_return_val_if_fail (info != NULL, NULL);
938   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
939
940   return (GIObjectInfoUnrefFunction)_get_func(info, (SymbolGetter)g_object_info_get_unref_function);
941 }
942
943 /**
944  * g_object_info_get_set_value_function:
945  * @info: a #GIObjectInfo
946  *
947  * Obtain the symbol name of the function that should be called to convert
948  * set a GValue giving an object instance pointer of this object type.
949  * I's mainly used fundamental types. The type signature for the symbol
950  * is %GIObjectInfoSetValueFunction, to fetch the function pointer
951  * see g_object_info_get_set_value_function().
952  *
953  * Returns: the symbol or %NULL
954  */
955 const char *
956 g_object_info_get_set_value_function (GIObjectInfo *info)
957 {
958   GIRealInfo *rinfo = (GIRealInfo *)info;
959   ObjectBlob *blob;
960
961   g_return_val_if_fail (info != NULL, NULL);
962   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
963
964   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
965
966   if (blob->set_value_func)
967     return g_typelib_get_string (rinfo->typelib, blob->set_value_func);
968
969   return NULL;
970 }
971
972 /**
973  * g_object_info_get_set_value_function_pointer: (skip)
974  * @info: a #GIObjectInfo
975  *
976  * Obtain a pointer to a function which can be used to
977  * set a GValue given an instance of this object type.
978  * This takes derivation into account and will reversely traverse
979  * the base classes of this type, starting at the top type.
980  *
981  * Returns: the function pointer or %NULL
982  */
983 GIObjectInfoSetValueFunction
984 g_object_info_get_set_value_function_pointer (GIObjectInfo *info)
985 {
986   g_return_val_if_fail (info != NULL, NULL);
987   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
988
989   return (GIObjectInfoSetValueFunction)_get_func(info, (SymbolGetter)g_object_info_get_set_value_function);
990 }
991
992 /**
993  * g_object_info_get_get_value_function:
994  * @info: a #GIObjectInfo
995  *
996  * Obtain the symbol name of the function that should be called to convert
997  * an object instance pointer of this object type to a GValue.
998  * I's mainly used fundamental types. The type signature for the symbol
999  * is %GIObjectInfoGetValueFunction, to fetch the function pointer
1000  * see g_object_info_get_get_value_function().
1001  *
1002  * Returns: the symbol or %NULL
1003  */
1004 const char *
1005 g_object_info_get_get_value_function (GIObjectInfo *info)
1006 {
1007   GIRealInfo *rinfo = (GIRealInfo *)info;
1008   ObjectBlob *blob;
1009
1010   g_return_val_if_fail (info != NULL, NULL);
1011   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1012
1013   blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
1014
1015   if (blob->get_value_func)
1016     return g_typelib_get_string (rinfo->typelib, blob->get_value_func);
1017
1018   return NULL;
1019 }
1020
1021 /**
1022  * g_object_info_get_get_value_function_pointer: (skip)
1023  * @info: a #GIObjectInfo
1024  *
1025  * Obtain a pointer to a function which can be used to
1026  * extract an instance of this object type out of a GValue.
1027  * This takes derivation into account and will reversely traverse
1028  * the base classes of this type, starting at the top type.
1029  *
1030  * Returns: the function pointer or %NULL
1031  */
1032 GIObjectInfoGetValueFunction
1033 g_object_info_get_get_value_function_pointer (GIObjectInfo *info)
1034 {
1035   g_return_val_if_fail (info != NULL, NULL);
1036   g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1037
1038   return (GIObjectInfoGetValueFunction)_get_func(info, (SymbolGetter)g_object_info_get_get_value_function);
1039 }