1 /* valainterfaceregisterfunction.vala
3 * Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <rasa@gmx.ch>
27 * C function to register an interface at runtime.
29 public class Vala
.InterfaceRegisterFunction
: TypeRegisterFunction
{
31 * Specifies the interface to be registered.
33 public Interface
! interface_reference
{ get; set construct; }
35 public InterfaceRegisterFunction (Interface
! iface
) {
36 interface_reference
= iface
;
39 public override DataType
! get_type_declaration () {
40 return interface_reference
;
43 public override string! get_type_struct_name () {
44 return interface_reference
.get_type_cname ();
47 public override string! get_base_init_func_name () {
48 return "%s_base_init".printf (interface_reference
.get_lower_case_cname (null));
51 public override string! get_class_init_func_name () {
55 public override string! get_instance_struct_size () {
59 public override string! get_instance_init_func_name () {
63 public override string! get_parent_type_name () {
64 return "G_TYPE_INTERFACE";
67 public override CCodeFragment
! get_type_interface_init_statements () {
68 var frag
= new
CCodeFragment ();
70 /* register all prerequisites */
71 foreach (TypeReference prereq_ref
in interface_reference
.get_prerequisites ()) {
72 var prereq
= prereq_ref
.data_type
;
74 var func
= new
CCodeFunctionCall (new
CCodeIdentifier ("g_type_interface_add_prerequisite"));
75 func
.add_argument (new
CCodeIdentifier ("%s_type_id".printf (interface_reference
.get_lower_case_cname (null))));
76 func
.add_argument (new
CCodeIdentifier (prereq
.get_type_id()));
78 frag
.append (new
CCodeExpressionStatement (func
));