~ubuntu-branches/ubuntu/trusty/gobject-introspection/trusty

« back to all changes in this revision

Viewing changes to girepository/giobjectinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-03-22 00:32:36 UTC
  • mfrom: (1.4.1 upstream) (3.3.33 multiarch)
  • Revision ID: james.westby@ubuntu.com-20110322003236-4spdgfk1vai6xay1
Tags: 0.10.4-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

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