Branch data Line data Source code
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 : : * SPDX-License-Identifier: LGPL-2.1-or-later
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public
11 : : * License as published by the Free Software Foundation; either
12 : : * version 2 of the License, or (at your option) any later version.
13 : : *
14 : : * This library is distributed in the hope that it will be useful,
15 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : * Lesser General Public License for more details.
18 : : *
19 : : * You should have received a copy of the GNU Lesser General Public
20 : : * License along with this library; if not, write to the
21 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 : : * Boston, MA 02111-1307, USA.
23 : : */
24 : :
25 : : #include "config.h"
26 : :
27 : : #include <glib.h>
28 : :
29 : : #include <girepository/girepository.h>
30 : : #include "gibaseinfo-private.h"
31 : : #include "girepository-private.h"
32 : : #include "gitypelib-internal.h"
33 : : #include "giobjectinfo.h"
34 : :
35 : : /**
36 : : * GIObjectInfo:
37 : : *
38 : : * `GIObjectInfo` represents a classed type.
39 : : *
40 : : * Classed types in [type@GObject.Type] inherit from
41 : : * [type@GObject.TypeInstance]; the most common type is [class@GObject.Object].
42 : : *
43 : : * A `GIObjectInfo` doesn’t represent a specific instance of a classed type,
44 : : * instead this represent the object type (i.e. the class).
45 : : *
46 : : * A `GIObjectInfo` has methods, fields, properties, signals, interfaces,
47 : : * constants and virtual functions.
48 : : *
49 : : * Since: 2.80
50 : : */
51 : :
52 : : /**
53 : : * gi_object_info_get_field_offset:
54 : : * @info: a #GIObjectInfo
55 : : * @n: index of queried field
56 : : *
57 : : * Obtain the offset of the specified field.
58 : : *
59 : : * Returns: field offset, in bytes
60 : : * Since: 2.80
61 : : */
62 : : static size_t
63 : 0 : gi_object_info_get_field_offset (GIObjectInfo *info,
64 : : size_t n)
65 : : {
66 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
67 : 0 : Header *header = (Header *)rinfo->typelib->data;
68 : 0 : ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
69 : : uint32_t offset;
70 : : FieldBlob *field_blob;
71 : :
72 : 0 : offset = rinfo->offset + header->object_blob_size
73 : 0 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u;
74 : :
75 : 0 : for (size_t i = 0; i < n; i++)
76 : : {
77 : 0 : field_blob = (FieldBlob *)&rinfo->typelib->data[offset];
78 : 0 : offset += header->field_blob_size;
79 : 0 : if (field_blob->has_embedded_type)
80 : 0 : offset += header->callback_blob_size;
81 : 0 : }
82 : :
83 : 0 : return offset;
84 : : }
85 : :
86 : : /**
87 : : * gi_object_info_get_parent:
88 : : * @info: a #GIObjectInfo
89 : : *
90 : : * Obtain the parent of the object type.
91 : : *
92 : : * Returns: (transfer full) (nullable): The `GIObjectInfo`. Free the struct by
93 : : * calling [method@GIRepository.BaseInfo.unref] when done.
94 : : * Since: 2.80
95 : : */
96 : : GIObjectInfo *
97 : 2 : gi_object_info_get_parent (GIObjectInfo *info)
98 : : {
99 : 2 : GIRealInfo *rinfo = (GIRealInfo *)info;
100 : : ObjectBlob *blob;
101 : :
102 : 2 : g_return_val_if_fail (info != NULL, NULL);
103 : 3 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
104 : :
105 : 2 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
106 : :
107 : 2 : if (blob->parent)
108 : 0 : return (GIObjectInfo *) gi_info_from_entry (rinfo->repository,
109 : 0 : rinfo->typelib, blob->parent);
110 : : else
111 : 2 : return NULL;
112 : 1 : }
113 : :
114 : : /**
115 : : * gi_object_info_get_abstract:
116 : : * @info: a #GIObjectInfo
117 : : *
118 : : * Obtain if the object type is an abstract type, i.e. if it cannot be
119 : : * instantiated.
120 : : *
121 : : * Returns: `TRUE` if the object type is abstract
122 : : * Since: 2.80
123 : : */
124 : : gboolean
125 : 0 : gi_object_info_get_abstract (GIObjectInfo *info)
126 : : {
127 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
128 : : ObjectBlob *blob;
129 : :
130 : 0 : g_return_val_if_fail (info != NULL, FALSE);
131 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), FALSE);
132 : :
133 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
134 : :
135 : 0 : return blob->abstract != 0;
136 : 0 : }
137 : :
138 : : /**
139 : : * gi_object_info_get_final:
140 : : * @info: a #GIObjectInfo
141 : : *
142 : : * Checks whether the object type is a final type, i.e. if it cannot
143 : : * be derived.
144 : : *
145 : : * Returns: `TRUE` if the object type is final
146 : : * Since: 2.80
147 : : */
148 : : gboolean
149 : 0 : gi_object_info_get_final (GIObjectInfo *info)
150 : : {
151 : 0 : GIRealInfo *rinfo = (GIRealInfo *) info;
152 : : ObjectBlob *blob;
153 : :
154 : 0 : g_return_val_if_fail (info != NULL, FALSE);
155 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), FALSE);
156 : :
157 : 0 : blob = (ObjectBlob *) &rinfo->typelib->data[rinfo->offset];
158 : :
159 : 0 : return blob->final_ != 0;
160 : 0 : }
161 : :
162 : : /**
163 : : * gi_object_info_get_fundamental:
164 : : * @info: a #GIObjectInfo
165 : : *
166 : : * Obtain if the object type is of a fundamental type which is not
167 : : * `G_TYPE_OBJECT`.
168 : : *
169 : : * This is mostly for supporting `GstMiniObject`.
170 : : *
171 : : * Returns: `TRUE` if the object type is a fundamental type
172 : : * Since: 2.80
173 : : */
174 : : gboolean
175 : 0 : gi_object_info_get_fundamental (GIObjectInfo *info)
176 : : {
177 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
178 : : ObjectBlob *blob;
179 : :
180 : 0 : g_return_val_if_fail (info != NULL, FALSE);
181 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), FALSE);
182 : :
183 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
184 : :
185 : 0 : return blob->fundamental != 0;
186 : 0 : }
187 : :
188 : : /**
189 : : * gi_object_info_get_type_name:
190 : : * @info: a #GIObjectInfo
191 : : *
192 : : * Obtain the name of the object’s class/type.
193 : : *
194 : : * Returns: name of the object’s type
195 : : * Since: 2.80
196 : : */
197 : : const char *
198 : 0 : gi_object_info_get_type_name (GIObjectInfo *info)
199 : : {
200 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
201 : : ObjectBlob *blob;
202 : :
203 : 0 : g_return_val_if_fail (info != NULL, NULL);
204 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
205 : :
206 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
207 : :
208 : 0 : return gi_typelib_get_string (rinfo->typelib, blob->gtype_name);
209 : 0 : }
210 : :
211 : : /**
212 : : * gi_object_info_get_type_init_function_name:
213 : : * @info: a #GIObjectInfo
214 : : *
215 : : * Obtain the name of the function which, when called, will return the
216 : : * [type@GObject.Type] for this object type.
217 : : *
218 : : * Returns: the type init function name
219 : : * Since: 2.80
220 : : */
221 : : const char *
222 : 0 : gi_object_info_get_type_init_function_name (GIObjectInfo *info)
223 : : {
224 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
225 : : ObjectBlob *blob;
226 : :
227 : 0 : g_return_val_if_fail (info != NULL, NULL);
228 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
229 : :
230 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
231 : :
232 : 0 : return gi_typelib_get_string (rinfo->typelib, blob->gtype_init);
233 : 0 : }
234 : :
235 : : /**
236 : : * gi_object_info_get_n_interfaces:
237 : : * @info: a #GIObjectInfo
238 : : *
239 : : * Obtain the number of interfaces that this object type has.
240 : : *
241 : : * Returns: number of interfaces
242 : : * Since: 2.80
243 : : */
244 : : unsigned int
245 : 2 : gi_object_info_get_n_interfaces (GIObjectInfo *info)
246 : : {
247 : 2 : GIRealInfo *rinfo = (GIRealInfo *)info;
248 : : ObjectBlob *blob;
249 : :
250 : 2 : g_return_val_if_fail (info != NULL, 0);
251 : 3 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
252 : :
253 : 2 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
254 : :
255 : 2 : return blob->n_interfaces;
256 : 1 : }
257 : :
258 : : /**
259 : : * gi_object_info_get_interface:
260 : : * @info: a #GIObjectInfo
261 : : * @n: index of interface to get
262 : : *
263 : : * Obtain an object type interface at index @n.
264 : : *
265 : : * Returns: (transfer full): The [class@GIRepository.InterfaceInfo]. Free the
266 : : * struct by calling [method@GIRepository.BaseInfo.unref] when done.
267 : : * Since: 2.80
268 : : */
269 : : GIInterfaceInfo *
270 : 6 : gi_object_info_get_interface (GIObjectInfo *info,
271 : : unsigned int n)
272 : : {
273 : 6 : GIRealInfo *rinfo = (GIRealInfo *)info;
274 : : ObjectBlob *blob;
275 : :
276 : 6 : g_return_val_if_fail (info != NULL, NULL);
277 : 9 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
278 : 6 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
279 : :
280 : 6 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
281 : :
282 : 9 : return (GIInterfaceInfo *) gi_info_from_entry (rinfo->repository,
283 : 6 : rinfo->typelib, blob->interfaces[n]);
284 : 3 : }
285 : :
286 : : /**
287 : : * gi_object_info_get_n_fields:
288 : : * @info: a #GIObjectInfo
289 : : *
290 : : * Obtain the number of fields that this object type has.
291 : : *
292 : : * Returns: number of fields
293 : : * Since: 2.80
294 : : */
295 : : unsigned int
296 : 0 : gi_object_info_get_n_fields (GIObjectInfo *info)
297 : : {
298 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
299 : : ObjectBlob *blob;
300 : :
301 : 0 : g_return_val_if_fail (info != NULL, 0);
302 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
303 : :
304 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
305 : :
306 : 0 : return blob->n_fields;
307 : 0 : }
308 : :
309 : : /**
310 : : * gi_object_info_get_field:
311 : : * @info: a #GIObjectInfo
312 : : * @n: index of field to get
313 : : *
314 : : * Obtain an object type field at index @n.
315 : : *
316 : : * Returns: (transfer full): The [class@GIRepository.FieldInfo]. Free the struct
317 : : * by calling [method@GIRepository.BaseInfo.unref] when done.
318 : : * Since: 2.80
319 : : */
320 : : GIFieldInfo *
321 : 0 : gi_object_info_get_field (GIObjectInfo *info,
322 : : unsigned int n)
323 : : {
324 : : size_t offset;
325 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
326 : :
327 : 0 : g_return_val_if_fail (info != NULL, NULL);
328 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
329 : 0 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
330 : :
331 : 0 : offset = gi_object_info_get_field_offset(info, n);
332 : :
333 : 0 : return (GIFieldInfo *) gi_base_info_new (GI_INFO_TYPE_FIELD, (GIBaseInfo*)info, rinfo->typelib, offset);
334 : 0 : }
335 : :
336 : : /**
337 : : * gi_object_info_get_n_properties:
338 : : * @info: a #GIObjectInfo
339 : : *
340 : : * Obtain the number of properties that this object type has.
341 : : *
342 : : * Returns: number of properties
343 : : * Since: 2.80
344 : : */
345 : : unsigned int
346 : 0 : gi_object_info_get_n_properties (GIObjectInfo *info)
347 : : {
348 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
349 : : ObjectBlob *blob;
350 : :
351 : 0 : g_return_val_if_fail (info != NULL, 0);
352 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
353 : :
354 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
355 : 0 : return blob->n_properties;
356 : 0 : }
357 : :
358 : : /**
359 : : * gi_object_info_get_property:
360 : : * @info: a #GIObjectInfo
361 : : * @n: index of property to get
362 : : *
363 : : * Obtain an object type property at index @n.
364 : : *
365 : : * Returns: (transfer full): The [class@GIRepository.PropertyInfo]. Free the
366 : : * struct by calling [method@GIRepository.BaseInfo.unref] when done.
367 : : * Since: 2.80
368 : : */
369 : : GIPropertyInfo *
370 : 2 : gi_object_info_get_property (GIObjectInfo *info,
371 : : unsigned int n)
372 : : {
373 : : size_t offset;
374 : 2 : GIRealInfo *rinfo = (GIRealInfo *)info;
375 : : Header *header;
376 : : ObjectBlob *blob;
377 : :
378 : 2 : g_return_val_if_fail (info != NULL, NULL);
379 : 3 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
380 : 2 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
381 : :
382 : 2 : header = (Header *)rinfo->typelib->data;
383 : 2 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
384 : :
385 : 3 : offset = rinfo->offset + header->object_blob_size
386 : 2 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
387 : 2 : + blob->n_fields * header->field_blob_size
388 : 2 : + blob->n_field_callbacks * header->callback_blob_size
389 : 2 : + n * header->property_blob_size;
390 : :
391 : 3 : return (GIPropertyInfo *) gi_base_info_new (GI_INFO_TYPE_PROPERTY, (GIBaseInfo*)info,
392 : 1 : rinfo->typelib, offset);
393 : 1 : }
394 : :
395 : : /**
396 : : * gi_object_info_get_n_methods:
397 : : * @info: a #GIObjectInfo
398 : : *
399 : : * Obtain the number of methods that this object type has.
400 : : *
401 : : * Returns: number of methods
402 : : * Since: 2.80
403 : : */
404 : : unsigned int
405 : 4 : gi_object_info_get_n_methods (GIObjectInfo *info)
406 : : {
407 : 4 : GIRealInfo *rinfo = (GIRealInfo *)info;
408 : : ObjectBlob *blob;
409 : :
410 : 4 : g_return_val_if_fail (info != NULL, 0);
411 : 6 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
412 : :
413 : 4 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
414 : :
415 : 4 : return blob->n_methods;
416 : 2 : }
417 : :
418 : : /**
419 : : * gi_object_info_get_method:
420 : : * @info: a #GIObjectInfo
421 : : * @n: index of method to get
422 : : *
423 : : * Obtain an object type method at index @n.
424 : : *
425 : : * Returns: (transfer full): The [class@GIRepository.FunctionInfo]. Free the
426 : : * struct by calling [method@GIRepository.BaseInfo.unref] when done.
427 : : * Since: 2.80
428 : : */
429 : : GIFunctionInfo *
430 : 4 : gi_object_info_get_method (GIObjectInfo *info,
431 : : unsigned int n)
432 : : {
433 : : size_t offset;
434 : 4 : GIRealInfo *rinfo = (GIRealInfo *)info;
435 : : Header *header;
436 : : ObjectBlob *blob;
437 : :
438 : 4 : g_return_val_if_fail (info != NULL, NULL);
439 : 6 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
440 : 4 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
441 : :
442 : 4 : header = (Header *)rinfo->typelib->data;
443 : 4 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
444 : :
445 : :
446 : 6 : offset = rinfo->offset + header->object_blob_size
447 : 4 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
448 : 4 : + blob->n_fields * header->field_blob_size
449 : 4 : + blob->n_field_callbacks * header->callback_blob_size
450 : 4 : + blob->n_properties * header->property_blob_size
451 : 4 : + n * header->function_blob_size;
452 : :
453 : 6 : return (GIFunctionInfo *) gi_base_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
454 : 2 : rinfo->typelib, offset);
455 : 2 : }
456 : :
457 : : /**
458 : : * gi_object_info_find_method:
459 : : * @info: a #GIObjectInfo
460 : : * @name: name of method to obtain
461 : : *
462 : : * Obtain a method of the object type given a @name.
463 : : *
464 : : * `NULL` will be returned if there’s no method available with that name.
465 : : *
466 : : * Returns: (transfer full) (nullable): The [class@GIRepository.FunctionInfo],
467 : : * or `NULL` if no method could be found. Free the struct by calling
468 : : * [method@GIRepository.BaseInfo.unref] when done.
469 : : * Since: 2.80
470 : : */
471 : : GIFunctionInfo *
472 : 27 : gi_object_info_find_method (GIObjectInfo *info,
473 : : const char *name)
474 : : {
475 : : size_t offset;
476 : 27 : GIRealInfo *rinfo = (GIRealInfo *)info;
477 : : Header *header;
478 : : ObjectBlob *blob;
479 : :
480 : 27 : g_return_val_if_fail (info != NULL, 0);
481 : 40 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
482 : :
483 : 27 : header = (Header *)rinfo->typelib->data;
484 : 27 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
485 : :
486 : 40 : offset = rinfo->offset + header->object_blob_size
487 : 27 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
488 : 40 : + blob->n_fields * header->field_blob_size +
489 : 27 : + blob->n_field_callbacks * header->callback_blob_size
490 : 27 : + blob->n_properties * header->property_blob_size;
491 : :
492 : 27 : return gi_base_info_find_method ((GIBaseInfo*)info, offset, blob->n_methods, name);
493 : 13 : }
494 : :
495 : : /**
496 : : * gi_object_info_find_method_using_interfaces:
497 : : * @info: a #GIObjectInfo
498 : : * @name: name of method to obtain
499 : : * @declarer: (out) (transfer full) (optional) (nullable): The
500 : : * [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
501 : : * declares the method, or `NULL` to ignore. If no method is found, this will
502 : : * return `NULL`.
503 : : *
504 : : * Obtain a method of the object given a @name, searching both the
505 : : * object @info and any interfaces it implements.
506 : : *
507 : : * `NULL` will be returned if there’s no method available with that name.
508 : : *
509 : : * Note that this function does *not* search parent classes; you will have
510 : : * to chain up if that’s desired.
511 : : *
512 : : * Returns: (transfer full) (nullable): The [class@GIRepository.FunctionInfo],
513 : : * or `NULL` if none was found. Free the struct by calling
514 : : * [method@GIRepository.BaseInfo.unref] when done.
515 : : * Since: 2.80
516 : : */
517 : : GIFunctionInfo *
518 : 2 : gi_object_info_find_method_using_interfaces (GIObjectInfo *info,
519 : : const char *name,
520 : : GIBaseInfo **declarer)
521 : : {
522 : 2 : GIFunctionInfo *result = NULL;
523 : 2 : GIBaseInfo *declarer_result = NULL;
524 : :
525 : 2 : result = gi_object_info_find_method (info, name);
526 : 2 : if (result)
527 : 0 : declarer_result = gi_base_info_ref (info);
528 : :
529 : 2 : if (result == NULL)
530 : : {
531 : : unsigned int n_interfaces, i;
532 : :
533 : 2 : n_interfaces = gi_object_info_get_n_interfaces (info);
534 : 6 : for (i = 0; i < n_interfaces; ++i)
535 : : {
536 : : GIInterfaceInfo *iface_info;
537 : :
538 : 6 : iface_info = gi_object_info_get_interface (info, i);
539 : :
540 : 6 : result = gi_interface_info_find_method (iface_info, name);
541 : :
542 : 6 : if (result != NULL)
543 : : {
544 : 2 : declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
545 : 2 : break;
546 : : }
547 : 4 : gi_base_info_unref ((GIBaseInfo*) iface_info);
548 : 2 : }
549 : 1 : }
550 : :
551 : 2 : if (declarer)
552 : 2 : *declarer = g_steal_pointer (&declarer_result);
553 : :
554 : 2 : g_clear_pointer (&declarer_result, gi_base_info_unref);
555 : :
556 : 2 : return g_steal_pointer (&result);
557 : : }
558 : :
559 : : /**
560 : : * gi_object_info_get_n_signals:
561 : : * @info: a #GIObjectInfo
562 : : *
563 : : * Obtain the number of signals that this object type has.
564 : : *
565 : : * Returns: number of signals
566 : : * Since: 2.80
567 : : */
568 : : unsigned int
569 : 8 : gi_object_info_get_n_signals (GIObjectInfo *info)
570 : : {
571 : 8 : GIRealInfo *rinfo = (GIRealInfo *)info;
572 : : ObjectBlob *blob;
573 : :
574 : 8 : g_return_val_if_fail (info != NULL, 0);
575 : 12 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
576 : :
577 : 8 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
578 : :
579 : 8 : return blob->n_signals;
580 : 4 : }
581 : :
582 : : static uint32_t
583 : 8 : object_get_signal_offset (GIObjectInfo *info, unsigned int n)
584 : : {
585 : 8 : GIRealInfo *rinfo = (GIRealInfo *) info;
586 : 8 : Header *header = (Header *) rinfo->typelib->data;
587 : 8 : ObjectBlob *blob = (ObjectBlob *) &rinfo->typelib->data[rinfo->offset];
588 : :
589 : 12 : return rinfo->offset + header->object_blob_size
590 : 8 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
591 : 8 : + blob->n_fields * header->field_blob_size
592 : 8 : + blob->n_field_callbacks * header->callback_blob_size
593 : 8 : + blob->n_properties * header->property_blob_size
594 : 8 : + blob->n_methods * header->function_blob_size
595 : 8 : + n * header->signal_blob_size;
596 : : }
597 : :
598 : : /**
599 : : * gi_object_info_get_signal:
600 : : * @info: a #GIObjectInfo
601 : : * @n: index of signal to get
602 : : *
603 : : * Obtain an object type signal at index @n.
604 : : *
605 : : * Returns: (transfer full): The [class@GIRepository.SignalInfo]. Free the
606 : : * struct by calling [method@GIRepository.BaseInfo.unref] when done.
607 : : * Since: 2.80
608 : : */
609 : : GISignalInfo *
610 : 0 : gi_object_info_get_signal (GIObjectInfo *info,
611 : : unsigned int n)
612 : : {
613 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
614 : :
615 : 0 : g_return_val_if_fail (info != NULL, NULL);
616 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
617 : 0 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
618 : :
619 : 0 : return (GISignalInfo *) gi_base_info_new (GI_INFO_TYPE_SIGNAL, (GIBaseInfo*)info,
620 : 0 : rinfo->typelib, object_get_signal_offset (info, n));
621 : 0 : }
622 : :
623 : : static GISignalInfo *
624 : 8 : find_signal (GIRealInfo *rinfo,
625 : : uint32_t offset,
626 : : uint16_t n_signals,
627 : : const char *name)
628 : : {
629 : 8 : Header *header = (Header *) rinfo->typelib->data;
630 : :
631 : 10 : for (uint16_t i = 0; i < n_signals; i++)
632 : : {
633 : 8 : const SignalBlob *sblob = (SignalBlob *) &rinfo->typelib->data[offset];
634 : 8 : const char *sname = gi_typelib_get_string (rinfo->typelib, sblob->name);
635 : :
636 : 8 : if (strcmp (name, sname) == 0)
637 : 9 : return (GISignalInfo *) gi_base_info_new (GI_INFO_TYPE_SIGNAL, (GIBaseInfo *) rinfo,
638 : 3 : rinfo->typelib, offset);
639 : :
640 : 2 : offset += header->signal_blob_size;
641 : 1 : }
642 : :
643 : 2 : return NULL;
644 : 4 : }
645 : :
646 : : /**
647 : : * gi_object_info_find_signal:
648 : : * @info: a #GIObjectInfo
649 : : * @name: name of signal
650 : : *
651 : : * Obtain a signal of the object type given a @name.
652 : : *
653 : : * `NULL` will be returned if there’s no signal available with that name.
654 : : *
655 : : * Returns: (transfer full) (nullable): The [class@GIRepository.SignalInfo],
656 : : * or `NULL` if no signal could be found. Free the struct by calling
657 : : * [method@GIRepository.BaseInfo.unref] when done.
658 : : * Since: 2.80
659 : : */
660 : : GISignalInfo *
661 : 8 : gi_object_info_find_signal (GIObjectInfo *info,
662 : : const char *name)
663 : : {
664 : 8 : GIRealInfo *rinfo = (GIRealInfo *) info;
665 : :
666 : 8 : g_return_val_if_fail (info != NULL, NULL);
667 : 12 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
668 : :
669 : 12 : return find_signal (rinfo, object_get_signal_offset (info, 0),
670 : 8 : gi_object_info_get_n_signals (info), name);
671 : 4 : }
672 : :
673 : :
674 : : /**
675 : : * gi_object_info_get_n_vfuncs:
676 : : * @info: a #GIObjectInfo
677 : : *
678 : : * Obtain the number of virtual functions that this object type has.
679 : : *
680 : : * Returns: number of virtual functions
681 : : * Since: 2.80
682 : : */
683 : : unsigned int
684 : 0 : gi_object_info_get_n_vfuncs (GIObjectInfo *info)
685 : : {
686 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
687 : : ObjectBlob *blob;
688 : :
689 : 0 : g_return_val_if_fail (info != NULL, 0);
690 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
691 : :
692 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
693 : :
694 : 0 : return blob->n_vfuncs;
695 : 0 : }
696 : :
697 : : /**
698 : : * gi_object_info_get_vfunc:
699 : : * @info: a #GIObjectInfo
700 : : * @n: index of virtual function to get
701 : : *
702 : : * Obtain an object type virtual function at index @n.
703 : : *
704 : : * Returns: (transfer full): The [class@GIRepository.VFuncInfo]. Free the struct
705 : : * by calling [method@GIRepository.BaseInfo.unref] when done.
706 : : * Since: 2.80
707 : : */
708 : : GIVFuncInfo *
709 : 0 : gi_object_info_get_vfunc (GIObjectInfo *info,
710 : : unsigned int n)
711 : : {
712 : : size_t offset;
713 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
714 : : Header *header;
715 : : ObjectBlob *blob;
716 : :
717 : 0 : g_return_val_if_fail (info != NULL, NULL);
718 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
719 : 0 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
720 : :
721 : 0 : header = (Header *)rinfo->typelib->data;
722 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
723 : :
724 : 0 : offset = rinfo->offset + header->object_blob_size
725 : 0 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
726 : 0 : + blob->n_fields * header->field_blob_size
727 : 0 : + blob->n_field_callbacks * header->callback_blob_size
728 : 0 : + blob->n_properties * header->property_blob_size
729 : 0 : + blob->n_methods * header->function_blob_size
730 : 0 : + blob->n_signals * header->signal_blob_size
731 : 0 : + n * header->vfunc_blob_size;
732 : :
733 : 0 : return (GIVFuncInfo *) gi_base_info_new (GI_INFO_TYPE_VFUNC, (GIBaseInfo*)info,
734 : 0 : rinfo->typelib, offset);
735 : 0 : }
736 : :
737 : : /**
738 : : * gi_object_info_find_vfunc:
739 : : * @info: a #GIObjectInfo
740 : : * @name: the name of a virtual function to find.
741 : : *
742 : : * Locate a virtual function slot with name @name.
743 : : *
744 : : * Note that the namespace for virtuals is distinct from that of methods; there
745 : : * may or may not be a concrete method associated for a virtual. If there is
746 : : * one, it may be retrieved using [method@GIRepository.VFuncInfo.get_invoker],
747 : : * otherwise that method will return `NULL`.
748 : : *
749 : : * See the documentation for [method@GIRepository.VFuncInfo.get_invoker] for
750 : : * more information on invoking virtuals.
751 : : *
752 : : * Returns: (transfer full) (nullable): The [class@GIRepository.VFuncInfo], or
753 : : * `NULL` if none is found. Free it with [method@GIRepository.BaseInfo.unref]
754 : : * when done.
755 : : * Since: 2.80
756 : : */
757 : : GIVFuncInfo *
758 : 6 : gi_object_info_find_vfunc (GIObjectInfo *info,
759 : : const char *name)
760 : : {
761 : : size_t offset;
762 : 6 : GIRealInfo *rinfo = (GIRealInfo *)info;
763 : : Header *header;
764 : : ObjectBlob *blob;
765 : :
766 : 6 : g_return_val_if_fail (info != NULL, NULL);
767 : 9 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
768 : :
769 : 6 : header = (Header *)rinfo->typelib->data;
770 : 6 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
771 : :
772 : 9 : offset = rinfo->offset + header->object_blob_size
773 : 6 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
774 : 6 : + blob->n_fields * header->field_blob_size
775 : 6 : + blob->n_field_callbacks * header->callback_blob_size
776 : 6 : + blob->n_properties * header->property_blob_size
777 : 6 : + blob->n_methods * header->function_blob_size
778 : 6 : + blob->n_signals * header->signal_blob_size;
779 : :
780 : 6 : return gi_base_info_find_vfunc (rinfo, offset, blob->n_vfuncs, name);
781 : 3 : }
782 : :
783 : : /**
784 : : * gi_object_info_find_vfunc_using_interfaces:
785 : : * @info: a #GIObjectInfo
786 : : * @name: name of vfunc to obtain
787 : : * @declarer: (out) (transfer full) (optional) (nullable): The
788 : : * [class@GIRepository.ObjectInfo] or [class@GIRepository.InterfaceInfo] which
789 : : * declares the vfunc, or `NULL` to ignore. If no vfunc is found, this will
790 : : * return `NULL`.
791 : : *
792 : : * Locate a virtual function slot with name @name, searching both the object
793 : : * @info and any interfaces it implements.
794 : : *
795 : : * `NULL` will be returned if there’s no vfunc available with that name.
796 : : *
797 : : * Note that the namespace for virtuals is distinct from that of methods; there
798 : : * may or may not be a concrete method associated for a virtual. If there is
799 : : * one, it may be retrieved using [method@GIRepository.VFuncInfo.get_invoker],
800 : : * otherwise that method will return `NULL`.
801 : : *
802 : : * Note that this function does *not* search parent classes; you will have
803 : : * to chain up if that’s desired.
804 : : *
805 : : * Returns: (transfer full) (nullable): The [class@GIRepository.VFuncInfo],
806 : : * or `NULL` if none was found. Free the struct by calling
807 : : * [method@GIRepository.BaseInfo.unref] when done.
808 : : * Since: 2.80
809 : : */
810 : : GIVFuncInfo *
811 : 2 : gi_object_info_find_vfunc_using_interfaces (GIObjectInfo *info,
812 : : const char *name,
813 : : GIBaseInfo **declarer)
814 : : {
815 : 2 : GIVFuncInfo *result = NULL;
816 : 2 : GIBaseInfo *declarer_result = NULL;
817 : :
818 : 2 : result = gi_object_info_find_vfunc (info, name);
819 : 2 : if (result)
820 : 2 : declarer_result = gi_base_info_ref (info);
821 : :
822 : 2 : if (result == NULL)
823 : : {
824 : : unsigned int n_interfaces, i;
825 : :
826 : 0 : n_interfaces = gi_object_info_get_n_interfaces (info);
827 : 0 : for (i = 0; i < n_interfaces; ++i)
828 : : {
829 : : GIInterfaceInfo *iface_info;
830 : :
831 : 0 : iface_info = gi_object_info_get_interface (info, i);
832 : :
833 : 0 : result = gi_interface_info_find_vfunc (iface_info, name);
834 : :
835 : 0 : if (result != NULL)
836 : : {
837 : 0 : declarer_result = GI_BASE_INFO (g_steal_pointer (&iface_info));
838 : 0 : break;
839 : : }
840 : 0 : gi_base_info_unref ((GIBaseInfo*) iface_info);
841 : 0 : }
842 : 0 : }
843 : :
844 : 2 : if (declarer)
845 : 2 : *declarer = g_steal_pointer (&declarer_result);
846 : :
847 : 2 : g_clear_pointer (&declarer_result, gi_base_info_unref);
848 : :
849 : 2 : return g_steal_pointer (&result);
850 : : }
851 : :
852 : : /**
853 : : * gi_object_info_get_n_constants:
854 : : * @info: a #GIObjectInfo
855 : : *
856 : : * Obtain the number of constants that this object type has.
857 : : *
858 : : * Returns: number of constants
859 : : * Since: 2.80
860 : : */
861 : : unsigned int
862 : 0 : gi_object_info_get_n_constants (GIObjectInfo *info)
863 : : {
864 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
865 : : ObjectBlob *blob;
866 : :
867 : 0 : g_return_val_if_fail (info != NULL, 0);
868 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), 0);
869 : :
870 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
871 : :
872 : 0 : return blob->n_constants;
873 : 0 : }
874 : :
875 : : /**
876 : : * gi_object_info_get_constant:
877 : : * @info: a #GIObjectInfo
878 : : * @n: index of constant to get
879 : : *
880 : : * Obtain an object type constant at index @n.
881 : : *
882 : : * Returns: (transfer full): The [class@GIRepository.ConstantInfo]. Free the
883 : : * struct by calling [method@GIRepository.BaseInfo.unref] when done.
884 : : * Since: 2.80
885 : : */
886 : : GIConstantInfo *
887 : 0 : gi_object_info_get_constant (GIObjectInfo *info,
888 : : unsigned int n)
889 : : {
890 : : size_t offset;
891 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
892 : : Header *header;
893 : : ObjectBlob *blob;
894 : :
895 : 0 : g_return_val_if_fail (info != NULL, NULL);
896 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
897 : 0 : g_return_val_if_fail (n <= G_MAXUINT16, NULL);
898 : :
899 : 0 : header = (Header *)rinfo->typelib->data;
900 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
901 : :
902 : 0 : offset = rinfo->offset + header->object_blob_size
903 : 0 : + (blob->n_interfaces + blob->n_interfaces % 2u) * 2u
904 : 0 : + blob->n_fields * header->field_blob_size
905 : 0 : + blob->n_field_callbacks * header->callback_blob_size
906 : 0 : + blob->n_properties * header->property_blob_size
907 : 0 : + blob->n_methods * header->function_blob_size
908 : 0 : + blob->n_signals * header->signal_blob_size
909 : 0 : + blob->n_vfuncs * header->vfunc_blob_size
910 : 0 : + n * header->constant_blob_size;
911 : :
912 : 0 : return (GIConstantInfo *) gi_base_info_new (GI_INFO_TYPE_CONSTANT, (GIBaseInfo*)info,
913 : 0 : rinfo->typelib, offset);
914 : 0 : }
915 : :
916 : : /**
917 : : * gi_object_info_get_class_struct:
918 : : * @info: a #GIObjectInfo
919 : : *
920 : : * Every [class@GObject.Object] has two structures; an instance structure and a
921 : : * class structure. This function returns the metadata for the class structure.
922 : : *
923 : : * Returns: (transfer full) (nullable): The [class@GIRepository.StructInfo] or
924 : : * `NULL` if it’s unknown. Free with [method@GIRepository.BaseInfo.unref] when
925 : : * done.
926 : : * Since: 2.80
927 : : */
928 : : GIStructInfo *
929 : 0 : gi_object_info_get_class_struct (GIObjectInfo *info)
930 : : {
931 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
932 : : ObjectBlob *blob;
933 : :
934 : 0 : g_return_val_if_fail (info != NULL, NULL);
935 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
936 : :
937 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
938 : :
939 : 0 : if (blob->gtype_struct)
940 : 0 : return (GIStructInfo *) gi_info_from_entry (rinfo->repository,
941 : 0 : rinfo->typelib, blob->gtype_struct);
942 : : else
943 : 0 : return NULL;
944 : 0 : }
945 : :
946 : : typedef const char* (*SymbolGetter) (GIObjectInfo *info);
947 : :
948 : : static void *
949 : 2 : _get_func(GIObjectInfo *info,
950 : : SymbolGetter getter)
951 : : {
952 : : const char* symbol;
953 : 2 : GSList *parents = NULL, *l;
954 : : GIObjectInfo *parent_info;
955 : 2 : void *func = NULL;
956 : :
957 : 2 : parent_info = (GIObjectInfo *) gi_base_info_ref ((GIBaseInfo *) info);
958 : 4 : while (parent_info != NULL)
959 : : {
960 : 2 : parents = g_slist_prepend (parents, parent_info);
961 : 2 : parent_info = gi_object_info_get_parent (parent_info);
962 : : }
963 : :
964 : 2 : for (l = parents; l; l = l->next)
965 : : {
966 : 2 : parent_info = l->data;
967 : 2 : symbol = getter (parent_info);
968 : 2 : if (symbol == NULL)
969 : 0 : continue;
970 : :
971 : 2 : gi_typelib_symbol (((GIRealInfo *)parent_info)->typelib, symbol, (gpointer*) &func);
972 : 2 : if (func)
973 : 2 : break;
974 : 0 : }
975 : :
976 : 2 : g_slist_free_full (parents, (GDestroyNotify) gi_base_info_unref);
977 : 2 : return func;
978 : : }
979 : :
980 : : /**
981 : : * gi_object_info_get_ref_function_name:
982 : : * @info: a #GIObjectInfo
983 : : *
984 : : * Obtain the symbol name of the function that should be called to ref this
985 : : * object type.
986 : : *
987 : : * It’s mainly used for fundamental types. The type signature for
988 : : * the symbol is [type@GIRepository.ObjectInfoRefFunction]. To fetch the
989 : : * function pointer see
990 : : * [method@GIRepository.ObjectInfo.get_ref_function_pointer].
991 : : *
992 : : * Returns: (nullable): the symbol, or `NULL` if the object type has no ref
993 : : * function
994 : : * Since: 2.80
995 : : */
996 : : const char *
997 : 2 : gi_object_info_get_ref_function_name (GIObjectInfo *info)
998 : : {
999 : 2 : GIRealInfo *rinfo = (GIRealInfo *)info;
1000 : : ObjectBlob *blob;
1001 : :
1002 : 2 : g_return_val_if_fail (info != NULL, NULL);
1003 : 3 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1004 : :
1005 : 2 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
1006 : :
1007 : 2 : if (blob->ref_func)
1008 : 2 : return gi_typelib_get_string (rinfo->typelib, blob->ref_func);
1009 : :
1010 : 0 : return NULL;
1011 : 1 : }
1012 : :
1013 : : /**
1014 : : * gi_object_info_get_ref_function_pointer: (skip)
1015 : : * @info: a #GIObjectInfo
1016 : : *
1017 : : * Obtain a pointer to a function which can be used to
1018 : : * increase the reference count an instance of this object type.
1019 : : *
1020 : : * This takes derivation into account and will reversely traverse
1021 : : * the base classes of this type, starting at the top type.
1022 : : *
1023 : : * Returns: (nullable): the function pointer, or `NULL` if the object type has
1024 : : * no ref function
1025 : : * Since: 2.80
1026 : : */
1027 : : GIObjectInfoRefFunction
1028 : 2 : gi_object_info_get_ref_function_pointer (GIObjectInfo *info)
1029 : : {
1030 : 2 : g_return_val_if_fail (info != NULL, NULL);
1031 : 3 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1032 : :
1033 : 2 : return (GIObjectInfoRefFunction)_get_func(info, (SymbolGetter)gi_object_info_get_ref_function_name);
1034 : 1 : }
1035 : :
1036 : : /**
1037 : : * gi_object_info_get_unref_function_name:
1038 : : * @info: a #GIObjectInfo
1039 : : *
1040 : : * Obtain the symbol name of the function that should be called to unref this
1041 : : * object type.
1042 : : *
1043 : : * It’s mainly used for fundamental types. The type signature for the symbol is
1044 : : * [type@GIRepository.ObjectInfoUnrefFunction]. To fetch the function pointer
1045 : : * see [method@GIRepository.ObjectInfo.get_unref_function_pointer].
1046 : : *
1047 : : * Returns: (nullable): the symbol, or `NULL` if the object type has no unref
1048 : : * function
1049 : : * Since: 2.80
1050 : : */
1051 : : const char *
1052 : 0 : gi_object_info_get_unref_function_name (GIObjectInfo *info)
1053 : : {
1054 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
1055 : : ObjectBlob *blob;
1056 : :
1057 : 0 : g_return_val_if_fail (info != NULL, NULL);
1058 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1059 : :
1060 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
1061 : :
1062 : 0 : if (blob->unref_func)
1063 : 0 : return gi_typelib_get_string (rinfo->typelib, blob->unref_func);
1064 : :
1065 : 0 : return NULL;
1066 : 0 : }
1067 : :
1068 : : /**
1069 : : * gi_object_info_get_unref_function_pointer: (skip)
1070 : : * @info: a #GIObjectInfo
1071 : : *
1072 : : * Obtain a pointer to a function which can be used to
1073 : : * decrease the reference count an instance of this object type.
1074 : : *
1075 : : * This takes derivation into account and will reversely traverse
1076 : : * the base classes of this type, starting at the top type.
1077 : : *
1078 : : * Returns: (nullable): the function pointer, or `NULL` if the object type has
1079 : : * no unref function
1080 : : * Since: 2.80
1081 : : */
1082 : : GIObjectInfoUnrefFunction
1083 : 0 : gi_object_info_get_unref_function_pointer (GIObjectInfo *info)
1084 : : {
1085 : 0 : g_return_val_if_fail (info != NULL, NULL);
1086 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1087 : :
1088 : 0 : return (GIObjectInfoUnrefFunction)_get_func(info, (SymbolGetter)gi_object_info_get_unref_function_name);
1089 : 0 : }
1090 : :
1091 : : /**
1092 : : * gi_object_info_get_set_value_function_name:
1093 : : * @info: a #GIObjectInfo
1094 : : *
1095 : : * Obtain the symbol name of the function that should be called to set a
1096 : : * [type@GObject.Value], given an object instance pointer of this object type.
1097 : : *
1098 : : * It’s mainly used for fundamental types. The type signature for the symbol
1099 : : * is [type@GIRepository.ObjectInfoSetValueFunction]. To fetch the function
1100 : : * pointer see [method@GIRepository.ObjectInfo.get_set_value_function_pointer].
1101 : : *
1102 : : * Returns: (nullable): the symbol, or `NULL` if the object type has no
1103 : : * set-value function
1104 : : * Since: 2.80
1105 : : */
1106 : : const char *
1107 : 0 : gi_object_info_get_set_value_function_name (GIObjectInfo *info)
1108 : : {
1109 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
1110 : : ObjectBlob *blob;
1111 : :
1112 : 0 : g_return_val_if_fail (info != NULL, NULL);
1113 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1114 : :
1115 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
1116 : :
1117 : 0 : if (blob->set_value_func)
1118 : 0 : return gi_typelib_get_string (rinfo->typelib, blob->set_value_func);
1119 : :
1120 : 0 : return NULL;
1121 : 0 : }
1122 : :
1123 : : /**
1124 : : * gi_object_info_get_set_value_function_pointer: (skip)
1125 : : * @info: a #GIObjectInfo
1126 : : *
1127 : : * Obtain a pointer to a function which can be used to set a
1128 : : * [type@GObject.Value], given an instance of this object type.
1129 : : *
1130 : : * This takes derivation into account and will reversely traverse
1131 : : * the base classes of this type, starting at the top type.
1132 : : *
1133 : : * Returns: (nullable): the function pointer, or `NULL` if the object type has
1134 : : * no set-value function
1135 : : * Since: 2.80
1136 : : */
1137 : : GIObjectInfoSetValueFunction
1138 : 0 : gi_object_info_get_set_value_function_pointer (GIObjectInfo *info)
1139 : : {
1140 : 0 : g_return_val_if_fail (info != NULL, NULL);
1141 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1142 : :
1143 : 0 : return (GIObjectInfoSetValueFunction)_get_func(info, (SymbolGetter)gi_object_info_get_set_value_function_name);
1144 : 0 : }
1145 : :
1146 : : /**
1147 : : * gi_object_info_get_get_value_function_name:
1148 : : * @info: a #GIObjectInfo
1149 : : *
1150 : : * Obtain the symbol name of the function that should be called to convert
1151 : : * an object instance pointer of this object type to a [type@GObject.Value].
1152 : : *
1153 : : * It’s mainly used for fundamental types. The type signature for the symbol
1154 : : * is [type@GIRepository.ObjectInfoGetValueFunction]. To fetch the function
1155 : : * pointer see [method@GIRepository.ObjectInfo.get_get_value_function_pointer].
1156 : : *
1157 : : * Returns: (nullable): the symbol, or `NULL` if the object type has no
1158 : : * get-value function
1159 : : * Since: 2.80
1160 : : */
1161 : : const char *
1162 : 0 : gi_object_info_get_get_value_function_name (GIObjectInfo *info)
1163 : : {
1164 : 0 : GIRealInfo *rinfo = (GIRealInfo *)info;
1165 : : ObjectBlob *blob;
1166 : :
1167 : 0 : g_return_val_if_fail (info != NULL, NULL);
1168 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1169 : :
1170 : 0 : blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
1171 : :
1172 : 0 : if (blob->get_value_func)
1173 : 0 : return gi_typelib_get_string (rinfo->typelib, blob->get_value_func);
1174 : :
1175 : 0 : return NULL;
1176 : 0 : }
1177 : :
1178 : : /**
1179 : : * gi_object_info_get_get_value_function_pointer: (skip)
1180 : : * @info: a #GIObjectInfo
1181 : : *
1182 : : * Obtain a pointer to a function which can be used to extract an instance of
1183 : : * this object type out of a [type@GObject.Value].
1184 : : *
1185 : : * This takes derivation into account and will reversely traverse
1186 : : * the base classes of this type, starting at the top type.
1187 : : *
1188 : : * Returns: (nullable): the function pointer, or `NULL` if the object type has
1189 : : * no get-value function
1190 : : * Since: 2.80
1191 : : */
1192 : : GIObjectInfoGetValueFunction
1193 : 0 : gi_object_info_get_get_value_function_pointer (GIObjectInfo *info)
1194 : : {
1195 : 0 : g_return_val_if_fail (info != NULL, NULL);
1196 : 0 : g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
1197 : :
1198 : 0 : return (GIObjectInfoGetValueFunction)_get_func(info, (SymbolGetter)gi_object_info_get_get_value_function_name);
1199 : 0 : }
1200 : :
1201 : : void
1202 : 10 : gi_object_info_class_init (gpointer g_class,
1203 : : gpointer class_data)
1204 : : {
1205 : 10 : GIBaseInfoClass *info_class = g_class;
1206 : :
1207 : 10 : info_class->info_type = GI_INFO_TYPE_OBJECT;
1208 : 10 : }
|