update for 0.3.3 release
[vala-lang.git] / gobject / valainterfaceregisterfunction.vala
blob3be408ceb37e95beb0b05b50af0780ca2d6a6784
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.1 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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
24 using GLib;
26 /**
27 * C function to register an interface at runtime.
29 public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
30 /**
31 * Specifies the interface to be registered.
33 public weak Interface interface_reference { get; set; }
35 public InterfaceRegisterFunction (Interface iface) {
36 interface_reference = iface;
39 public override TypeSymbol 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 () {
52 return "NULL";
55 public override string get_instance_struct_size () {
56 return "0";
59 public override string get_instance_init_func_name () {
60 return "NULL";
63 public override string get_parent_type_name () {
64 return "G_TYPE_INTERFACE";
67 public override SymbolAccessibility get_accessibility () {
68 return interface_reference.access;
71 public override CCodeFragment get_type_interface_init_statements () {
72 var frag = new CCodeFragment ();
74 /* register all prerequisites */
75 foreach (DataType prereq_ref in interface_reference.get_prerequisites ()) {
76 var prereq = prereq_ref.data_type;
78 var func = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_add_prerequisite"));
79 func.add_argument (new CCodeIdentifier ("%s_type_id".printf (interface_reference.get_lower_case_cname (null))));
80 func.add_argument (new CCodeIdentifier (prereq.get_type_id()));
82 frag.append (new CCodeExpressionStatement (func));
85 return frag;