From: Didier 'Ptitjes Date: Thu, 30 Apr 2009 14:34:20 +0000 (+0200) Subject: D-Bus: Register client proxy class with interface X-Git-Tag: 0.7.5~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a97fc200f56bf7a1679f34230c4255af9dd3d7c;p=thirdparty%2Fvala.git D-Bus: Register client proxy class with interface Fixes part of bug 571831. Signed-off-by: Didier 'Ptitjes --- diff --git a/codegen/Makefile.am b/codegen/Makefile.am index f97596417..5a6dc0fee 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 6d65fb164..1767bcd88 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 000000000..2eec9488d --- /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 + */ + +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; + } +} +