]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Register client proxy class with interface
authorDidier 'Ptitjes <ptitjes@free.fr>
Thu, 30 Apr 2009 14:34:20 +0000 (16:34 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 28 Jul 2009 18:55:13 +0000 (20:55 +0200)
Fixes part of bug 571831.

Signed-off-by: Didier 'Ptitjes <ptitjes@free.fr>
codegen/Makefile.am
codegen/valadbusclientmodule.vala
codegen/valadbusinterfaceregisterfunction.vala [new file with mode: 0644]

index f97596417948aa383c95a9594be743a28d03b42b..5a6dc0fee57e71c07aa46508ebc224da92370108 100644 (file)
@@ -29,6 +29,7 @@ libvala_la_VALASOURCES = \
        valaccodestructmodule.vala \
        valaclassregisterfunction.vala \
        valadbusclientmodule.vala \
+       valadbusinterfaceregisterfunction.vala \
        valadbusmodule.vala \
        valadbusservermodule.vala \
        valagerrormodule.vala \
index 6d65fb164704582d9ac81bd9e30c714b64601b73..1767bcd880559a92faf601455f5bac984a7999b4 100644 (file)
@@ -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 (file)
index 0000000..2eec948
--- /dev/null
@@ -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;
+       }
+}
+