Release 0.41.92
[vala-gnome.git] / vala / valasignaltype.vala
blob4a36816f0896748c8ae8b098df9ce770a5bf366d
1 /* valasignaltype.vala
3 * Copyright (C) 2007-2011 Jürg Billeter
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>
23 using GLib;
25 /**
26 * The type of a signal referencea.
28 public class Vala.SignalType : CallableType {
29 public weak Signal signal_symbol { get; set; }
31 Method? connect_method;
32 Method? connect_after_method;
33 Method? disconnect_method;
35 public SignalType (Signal signal_symbol) {
36 this.signal_symbol = signal_symbol;
39 public override bool is_invokable () {
40 return true;
43 public override DataType? get_return_type () {
44 return signal_symbol.return_type;
47 public override List<Parameter>? get_parameters () {
48 return signal_symbol.get_parameters ();
51 public override DataType copy () {
52 return new SignalType (signal_symbol);
55 public override bool compatible (DataType target_type) {
56 return false;
59 public override string to_qualified_string (Scope? scope) {
60 return signal_symbol.get_full_name ();
63 public DelegateType get_handler_type () {
64 var type_sym = (ObjectTypeSymbol) signal_symbol.parent_symbol;
65 var sender_type = SemanticAnalyzer.get_data_type_for_symbol (type_sym);
66 var result = new DelegateType (signal_symbol.get_delegate (sender_type, this));
67 result.value_owned = true;
69 if (result.delegate_symbol.get_type_parameters ().size > 0) {
70 foreach (var type_param in type_sym.get_type_parameters ()) {
71 var type_arg = new GenericType (type_param);
72 type_arg.value_owned = true;
73 result.add_type_argument (type_arg);
77 return result;
80 Method get_connect_method () {
81 if (connect_method == null) {
82 var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
83 connect_method = new Method ("connect", ulong_type);
84 connect_method.access = SymbolAccessibility.PUBLIC;
85 connect_method.external = true;
86 connect_method.owner = signal_symbol.scope;
87 connect_method.add_parameter (new Parameter ("handler", get_handler_type ()));
89 return connect_method;
92 Method get_connect_after_method () {
93 if (connect_after_method == null) {
94 var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
95 connect_after_method = new Method ("connect_after", ulong_type);
96 connect_after_method.access = SymbolAccessibility.PUBLIC;
97 connect_after_method.external = true;
98 connect_after_method.owner = signal_symbol.scope;
99 connect_after_method.add_parameter (new Parameter ("handler", get_handler_type ()));
101 return connect_after_method;
104 Method get_disconnect_method () {
105 if (disconnect_method == null) {
106 disconnect_method = new Method ("disconnect", new VoidType ());
107 disconnect_method.access = SymbolAccessibility.PUBLIC;
108 disconnect_method.external = true;
109 disconnect_method.owner = signal_symbol.scope;
110 disconnect_method.add_parameter (new Parameter ("handler", get_handler_type ()));
112 return disconnect_method;
115 public override Symbol? get_member (string member_name) {
116 if (member_name == "connect") {
117 return get_connect_method ();
118 } else if (member_name == "connect_after") {
119 return get_connect_after_method ();
120 } else if (member_name == "disconnect") {
121 return get_disconnect_method ();
123 return null;
126 public override bool is_accessible (Symbol sym) {
127 return signal_symbol.is_accessible (sym);