[vala] D-Bus: GType-based client proxy instantiation



commit 70eec997de972da1bc20f9879da53079cf23aa09
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Thu Apr 30 17:26:02 2009 +0200

    D-Bus: GType-based client proxy instantiation
    
    Add internal DBus.get_object_from_type method to dbus-glib-1 binding,
    fixes bug 571831.
    
    Signed-off-by: Didier 'Ptitjes <ptitjes free fr>

 codegen/valadbusclientmodule.vala |   42 +++++++++++++++++++++++++++++++++++++
 vapi/dbus-glib-1.vapi             |    2 +
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 1767bcd..9dfcaae 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -1146,6 +1146,48 @@ internal class Vala.DBusClientModule : DBusModule {
 		return new DBusInterfaceRegisterFunction (iface, context);
 	}
 
+	public override void visit_method_call (MethodCall expr) {
+		var mtype = expr.call.value_type as MethodType;
+		if (mtype == null || mtype.method_symbol.get_cname () != "dbus_g_proxy_new_from_type") {
+			base.visit_method_call (expr);
+			return;
+		}
+
+		var args = expr.get_argument_list ();
+		Expression connection = ((MemberAccess) expr.call).inner;
+		Expression bus_name = args.get (0);
+		Expression object_path = args.get (1);
+		Expression interface_name = args.get (2);
+		Expression type = args.get (3);
+
+		var quark_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_string"));
+		quark_call.add_argument (new CCodeConstant ("\"ValaDBusInterfaceProxyType\""));
+
+		var qdata_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_get_qdata"));
+		type.accept (codegen);
+		qdata_call.add_argument ((CCodeExpression) type.ccodenode);
+		qdata_call.add_argument (quark_call);
+
+		var get_type_call = new CCodeFunctionCall (new CCodeCastExpression (qdata_call, "GType (*)(void)"));
+
+		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new"));
+		ccall.add_argument (get_type_call);
+		ccall.add_argument (new CCodeConstant ("\"connection\""));
+		connection.accept (codegen);
+		ccall.add_argument ((CCodeExpression) connection.ccodenode);
+		ccall.add_argument (new CCodeConstant ("\"name\""));
+		bus_name.accept (codegen);
+		ccall.add_argument ((CCodeExpression) bus_name.ccodenode);
+		ccall.add_argument (new CCodeConstant ("\"path\""));
+		object_path.accept (codegen);
+		ccall.add_argument ((CCodeExpression) object_path.ccodenode);
+		ccall.add_argument (new CCodeConstant ("\"interface\""));
+		interface_name.accept (codegen);
+		ccall.add_argument ((CCodeExpression) interface_name.ccodenode);
+		ccall.add_argument (new CCodeConstant ("NULL"));
+		expr.ccodenode = ccall;
+	}
+
 	void generate_proxy_filter_function (Interface iface) {
 		string lower_cname = iface.get_lower_case_cprefix () + "dbus_proxy";
 
diff --git a/vapi/dbus-glib-1.vapi b/vapi/dbus-glib-1.vapi
index cda3179..0c921c2 100644
--- a/vapi/dbus-glib-1.vapi
+++ b/vapi/dbus-glib-1.vapi
@@ -101,6 +101,8 @@ namespace DBus {
 	public class Connection {
 		[CCode (cname = "dbus_g_proxy_new_for_name")]
 		public Object get_object (string name, string path, string? interface_ = null);
+		[CCode (cname = "dbus_g_proxy_new_from_type")]
+		public GLib.Object get_object_from_type (string name, string path, string interface_, GLib.Type type);
 		[CCode (cname = "dbus_g_connection_register_g_object")]
 		public void register_object (string at_path, GLib.Object object);
 		[CCode (cname = "dbus_g_connection_lookup_g_object")]



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