1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 * GObject introspection: Interface implementation
4 * Copyright (C) 2005 Matthias Clasen
5 * Copyright (C) 2008,2009 Red Hat, Inc.
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.
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.
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.
25 #include <girepository.h>
26 #include "girepository-private.h"
27 #include "gitypelib-internal.h"
30 * SECTION:giinterfaceinfo
31 * @Short_description: Struct representing a GInterface
32 * @Title: GIInterfaceInfo
34 * GIInterfaceInfo represents a #GInterface type.
36 * A GInterface has methods, fields, properties, signals, interfaces, constants,
37 * virtual functions and prerequisites.
39 * <refsect1 id="gi-giinterfaceinfo.struct-hierarchy" role="struct_hierarchy">
40 * <title role="struct_hierarchy.title">Struct hierarchy</title>
42 * <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
43 * +----<link linkend="gi-GIRegisteredTypeInfo">GIRegisteredTypeInfo</link>
44 * +----GIInterfaceInfo
50 * g_interface_info_get_n_prerequisites:
51 * @info: a #GIInterfaceInfo
53 * Obtain the number of prerequisites for this interface type.
54 * A prerequisites is another interface that needs to be implemented for
55 * interface, similar to an base class for GObjects.
57 * Returns: number of prerequisites
60 g_interface_info_get_n_prerequisites (GIInterfaceInfo *info)
62 GIRealInfo *rinfo = (GIRealInfo *)info;
65 g_return_val_if_fail (info != NULL, 0);
66 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
68 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
70 return blob->n_prerequisites;
74 * g_interface_info_get_prerequisite:
75 * @info: a #GIInterfaceInfo
76 * @n: index of prerequisites to get
78 * Obtain an interface type prerequisites index @n.
80 * Returns: (transfer full): the prerequisites as a #GIBaseInfo. Free the struct by calling
81 * g_base_info_unref() when done.
84 g_interface_info_get_prerequisite (GIInterfaceInfo *info,
87 GIRealInfo *rinfo = (GIRealInfo *)info;
90 g_return_val_if_fail (info != NULL, NULL);
91 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
93 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
95 return _g_info_from_entry (rinfo->repository,
96 rinfo->typelib, blob->prerequisites[n]);
101 * g_interface_info_get_n_properties:
102 * @info: a #GIInterfaceInfo
104 * Obtain the number of properties that this interface type has.
106 * Returns: number of properties
109 g_interface_info_get_n_properties (GIInterfaceInfo *info)
111 GIRealInfo *rinfo = (GIRealInfo *)info;
114 g_return_val_if_fail (info != NULL, 0);
115 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
117 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
119 return blob->n_properties;
123 * g_interface_info_get_property:
124 * @info: a #GIInterfaceInfo
125 * @n: index of property to get
127 * Obtain an interface type property at index @n.
129 * Returns: (transfer full): the #GIPropertyInfo. Free the struct by calling
130 * g_base_info_unref() when done.
133 g_interface_info_get_property (GIInterfaceInfo *info,
137 GIRealInfo *rinfo = (GIRealInfo *)info;
141 g_return_val_if_fail (info != NULL, NULL);
142 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
144 header = (Header *)rinfo->typelib->data;
145 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
147 offset = rinfo->offset + header->interface_blob_size
148 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
149 + n * header->property_blob_size;
151 return (GIPropertyInfo *) g_info_new (GI_INFO_TYPE_PROPERTY, (GIBaseInfo*)info,
152 rinfo->typelib, offset);
156 * g_interface_info_get_n_methods:
157 * @info: a #GIInterfaceInfo
159 * Obtain the number of methods that this interface type has.
161 * Returns: number of methods
164 g_interface_info_get_n_methods (GIInterfaceInfo *info)
166 GIRealInfo *rinfo = (GIRealInfo *)info;
169 g_return_val_if_fail (info != NULL, 0);
170 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
172 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
174 return blob->n_methods;
178 * g_interface_info_get_method:
179 * @info: a #GIInterfaceInfo
180 * @n: index of method to get
182 * Obtain an interface type method at index @n.
184 * Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
185 * g_base_info_unref() when done.
188 g_interface_info_get_method (GIInterfaceInfo *info,
192 GIRealInfo *rinfo = (GIRealInfo *)info;
196 g_return_val_if_fail (info != NULL, NULL);
197 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
199 header = (Header *)rinfo->typelib->data;
200 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
202 offset = rinfo->offset + header->interface_blob_size
203 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
204 + blob->n_properties * header->property_blob_size
205 + n * header->function_blob_size;
207 return (GIFunctionInfo *) g_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
208 rinfo->typelib, offset);
212 * g_interface_info_find_method:
213 * @info: a #GIInterfaceInfo
214 * @name: name of method to obtain
216 * Obtain a method of the interface type given a @name. %NULL will be
217 * returned if there's no method available with that name.
219 * Returns: (transfer full): the #GIFunctionInfo or %NULL if none found.
220 * Free the struct by calling g_base_info_unref() when done.
223 g_interface_info_find_method (GIInterfaceInfo *info,
227 GIRealInfo *rinfo = (GIRealInfo *)info;
228 Header *header = (Header *)rinfo->typelib->data;
229 InterfaceBlob *blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
231 offset = rinfo->offset + header->interface_blob_size
232 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
233 + blob->n_properties * header->property_blob_size;
235 return _g_base_info_find_method ((GIBaseInfo*)info, offset, blob->n_methods, name);
239 * g_interface_info_get_n_signals:
240 * @info: a #GIInterfaceInfo
242 * Obtain the number of signals that this interface type has.
244 * Returns: number of signals
247 g_interface_info_get_n_signals (GIInterfaceInfo *info)
249 GIRealInfo *rinfo = (GIRealInfo *)info;
252 g_return_val_if_fail (info != NULL, 0);
253 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
255 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
257 return blob->n_signals;
261 * g_interface_info_get_signal:
262 * @info: a #GIInterfaceInfo
263 * @n: index of signal to get
265 * Obtain an interface type signal at index @n.
267 * Returns: (transfer full): the #GISignalInfo. Free the struct by calling
268 * g_base_info_unref() when done.
271 g_interface_info_get_signal (GIInterfaceInfo *info,
275 GIRealInfo *rinfo = (GIRealInfo *)info;
279 g_return_val_if_fail (info != NULL, NULL);
280 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
282 header = (Header *)rinfo->typelib->data;
283 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
285 offset = rinfo->offset + header->interface_blob_size
286 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
287 + blob->n_properties * header->property_blob_size
288 + blob->n_methods * header->function_blob_size
289 + n * header->signal_blob_size;
291 return (GISignalInfo *) g_info_new (GI_INFO_TYPE_SIGNAL, (GIBaseInfo*)info,
292 rinfo->typelib, offset);
296 * g_interface_info_get_n_vfuncs:
297 * @info: a #GIInterfaceInfo
299 * Obtain the number of virtual functions that this interface type has.
301 * Returns: number of virtual functions
304 g_interface_info_get_n_vfuncs (GIInterfaceInfo *info)
306 GIRealInfo *rinfo = (GIRealInfo *)info;
309 g_return_val_if_fail (info != NULL, 0);
310 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
312 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
314 return blob->n_vfuncs;
318 * g_interface_info_get_vfunc:
319 * @info: a #GIInterfaceInfo
320 * @n: index of virtual function to get
322 * Obtain an interface type virtual function at index @n.
324 * Returns: (transfer full): the #GIVFuncInfo. Free the struct by calling
325 * g_base_info_unref() when done.
328 g_interface_info_get_vfunc (GIInterfaceInfo *info,
332 GIRealInfo *rinfo = (GIRealInfo *)info;
336 g_return_val_if_fail (info != NULL, NULL);
337 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
339 header = (Header *)rinfo->typelib->data;
340 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
342 offset = rinfo->offset + header->interface_blob_size
343 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
344 + blob->n_properties * header->property_blob_size
345 + blob->n_methods * header->function_blob_size
346 + blob->n_signals * header->signal_blob_size
347 + n * header->vfunc_blob_size;
349 return (GIVFuncInfo *) g_info_new (GI_INFO_TYPE_VFUNC, (GIBaseInfo*)info,
350 rinfo->typelib, offset);
354 * g_interface_info_find_vfunc:
355 * @info: a #GIInterfaceInfo
356 * @name: The name of a virtual function to find.
358 * Locate a virtual function slot with name @name. See the documentation
359 * for g_object_info_find_vfunc() for more information on virtuals.
361 * Returns: (transfer full): the #GIVFuncInfo, or %NULL. Free it with
362 * g_base_info_unref() when done.
365 g_interface_info_find_vfunc (GIInterfaceInfo *info,
369 GIRealInfo *rinfo = (GIRealInfo *)info;
373 g_return_val_if_fail (info != NULL, NULL);
374 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
376 header = (Header *)rinfo->typelib->data;
377 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
379 offset = rinfo->offset + header->interface_blob_size
380 + (blob->n_prerequisites + blob->n_prerequisites % 2) * 2
381 + blob->n_properties * header->property_blob_size
382 + blob->n_methods * header->function_blob_size
383 + blob->n_signals * header->signal_blob_size;
385 return _g_base_info_find_vfunc (rinfo, offset, blob->n_vfuncs, name);
389 * g_interface_info_get_n_constants:
390 * @info: a #GIInterfaceInfo
392 * Obtain the number of constants that this interface type has.
394 * Returns: number of constants
397 g_interface_info_get_n_constants (GIInterfaceInfo *info)
399 GIRealInfo *rinfo = (GIRealInfo *)info;
402 g_return_val_if_fail (info != NULL, 0);
403 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), 0);
405 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
407 return blob->n_constants;
411 * g_interface_info_get_constant:
412 * @info: a #GIInterfaceInfo
413 * @n: index of constant to get
415 * Obtain an interface type constant at index @n.
417 * Returns: (transfer full): the #GIConstantInfo. Free the struct by calling
418 * g_base_info_unref() when done.
421 g_interface_info_get_constant (GIInterfaceInfo *info,
425 GIRealInfo *rinfo = (GIRealInfo *)info;
429 g_return_val_if_fail (info != NULL, NULL);
430 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
432 header = (Header *)rinfo->typelib->data;
433 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
435 offset = rinfo->offset + header->interface_blob_size
436 + (blob->n_prerequisites + (blob->n_prerequisites % 2)) * 2
437 + blob->n_properties * header->property_blob_size
438 + blob->n_methods * header->function_blob_size
439 + blob->n_signals * header->signal_blob_size
440 + blob->n_vfuncs * header->vfunc_blob_size
441 + n * header->constant_blob_size;
443 return (GIConstantInfo *) g_info_new (GI_INFO_TYPE_CONSTANT, (GIBaseInfo*)info,
444 rinfo->typelib, offset);
448 * g_interface_info_get_iface_struct:
449 * @info: a #GIInterfaceInfo
451 * Returns the layout C structure associated with this #GInterface.
453 * Returns: (transfer full): the #GIStructInfo or %NULL. Free it with
454 * g_base_info_unref() when done.
457 g_interface_info_get_iface_struct (GIInterfaceInfo *info)
459 GIRealInfo *rinfo = (GIRealInfo *)info;
462 g_return_val_if_fail (info != NULL, NULL);
463 g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
465 blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
467 if (blob->gtype_struct)
468 return (GIStructInfo *) _g_info_from_entry (rinfo->repository,
469 rinfo->typelib, blob->gtype_struct);