[vala] D-Bus: Register client proxy class with interface



commit 5a97fc200f56bf7a1679f34230c4255af9dd3d7c
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Thu Apr 30 16:34:20 2009 +0200

    D-Bus: Register client proxy class with interface
    
    Fixes part of bug 571831.
    
    Signed-off-by: Didier 'Ptitjes <ptitjes free fr>

 codegen/Makefile.am                            |    1 +
 codegen/valadbusclientmodule.vala              |   16 +++++++
 codegen/valadbusinterfaceregisterfunction.vala |   52 ++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index f975964..5a6dc0f 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -29,6 +29,7 @@ libvala_la_VALASOURCES = \
 	valaccodestructmodule.vala \
 	valaclassregisterfunction.vala \
 	valadbusclientmodule.vala \
+	valadbusinterfaceregisterfunction.vala \
 	valadbusmodule.vala \
 	valadbusservermodule.vala \
 	valagerrormodule.vala \
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 6d65fb1..1767bcd 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -863,6 +863,8 @@ internal class Vala.DBusClientModule : DBusModule {
 
 		source_declarations.add_type_definition (instance_struct);
 
+		source_declarations.add_type_member_declaration (new CCodeFunction(lower_cname + "_get_type", "GType"));
+
 		var implement = new CCodeFunctionCall (new CCodeIdentifier ("G_IMPLEMENT_INTERFACE"));
 		implement.add_argument (new CCodeIdentifier (iface.get_upper_case_cname ("TYPE_")));
 		implement.add_argument (new CCodeIdentifier (lower_cname + "_interface_init"));
@@ -1130,6 +1132,20 @@ internal class Vala.DBusClientModule : DBusModule {
 		source_type_member_definition.append (set_prop);
 	}
 
+	public override TypeRegisterFunction create_interface_register_function (Interface iface) {
+		var dbus = iface.get_attribute ("DBus");
+		if (dbus == null) {
+			return new InterfaceRegisterFunction (iface, context);
+		}
+
+		string dbus_iface_name = dbus.get_string ("name");
+		if (dbus_iface_name == null) {
+			return new InterfaceRegisterFunction (iface, context);
+		}
+
+		return new DBusInterfaceRegisterFunction (iface, context);
+	}
+
 	void generate_proxy_filter_function (Interface iface) {
 		string lower_cname = iface.get_lower_case_cprefix () + "dbus_proxy";
 
diff --git a/codegen/valadbusinterfaceregisterfunction.vala b/codegen/valadbusinterfaceregisterfunction.vala
new file mode 100644
index 0000000..2eec948
--- /dev/null
+++ b/codegen/valadbusinterfaceregisterfunction.vala
@@ -0,0 +1,52 @@
+/* valadbusinterfaceregisterfunction.vala
+ *
+ * Copyright (C) 2009 Didier Villevalois
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *	Didier Villevalois <ptitjes free fr>
+ */
+
+using GLib;
+
+/**
+ * C function to register an interface at runtime.
+ */
+public class Vala.DBusInterfaceRegisterFunction : InterfaceRegisterFunction {
+	
+	public DBusInterfaceRegisterFunction (Interface iface, CodeContext context) {
+		base(iface, context);
+	}
+
+	public override CCodeFragment get_type_interface_init_statements () {
+		var frag = base.get_type_interface_init_statements ();
+		
+		var quark_dbus_proxy = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_string"));
+		quark_dbus_proxy.add_argument (new CCodeConstant ("\"ValaDBusInterfaceProxyType\""));
+
+		var func = new CCodeFunctionCall (new CCodeIdentifier ("g_type_set_qdata"));
+		func.add_argument (new CCodeIdentifier ("%s_type_id".printf (interface_reference.get_lower_case_cname 
+(null))));
+		func.add_argument (quark_dbus_proxy);
+		func.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier 
+("%s_dbus_proxy_get_type".printf (interface_reference.get_lower_case_cname (null)))));
+		
+		frag.append (new CCodeExpressionStatement (func));
+		
+		return frag;
+	}
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]