From: Jürg Billeter Date: Mon, 14 Sep 2009 19:55:08 +0000 (+0200) Subject: D-Bus: Add get_dbus_name helper method X-Git-Tag: 0.7.6~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6ef48797ef3277c0bb58aa4c9e6fbd577f25569;p=thirdparty%2Fvala.git D-Bus: Add get_dbus_name helper method --- diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala index 1ab4bac14..c5f25f4c2 100644 --- a/codegen/valadbusclientmodule.vala +++ b/codegen/valadbusclientmodule.vala @@ -845,11 +845,7 @@ internal class Vala.DBusClientModule : DBusModule { public override void visit_interface (Interface iface) { base.visit_interface (iface); - var dbus = iface.get_attribute ("DBus"); - if (dbus == null) { - return; - } - string dbus_iface_name = dbus.get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); if (dbus_iface_name == null) { return; } @@ -1143,12 +1139,7 @@ internal class Vala.DBusClientModule : DBusModule { } 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"); + string dbus_iface_name = get_dbus_name (iface); if (dbus_iface_name == null) { return new InterfaceRegisterFunction (iface, context); } @@ -1350,7 +1341,7 @@ internal class Vala.DBusClientModule : DBusModule { } void handle_signals (Interface iface, CCodeBlock block) { - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); CCodeIfStatement clastif = null; foreach (Signal sig in iface.get_signals ()) { @@ -1463,7 +1454,7 @@ internal class Vala.DBusClientModule : DBusModule { string generate_dbus_proxy_method (Interface iface, Method m) { string proxy_name = "%sdbus_proxy_%s".printf (iface.get_lower_case_cprefix (), m.name); - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); CCodeDeclaration cdecl; @@ -1557,7 +1548,7 @@ internal class Vala.DBusClientModule : DBusModule { string generate_async_dbus_proxy_method (Interface iface, Method m) { string proxy_name = "%sdbus_proxy_%s_async".printf (iface.get_lower_case_cprefix (), m.name); - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); CCodeDeclaration cdecl; @@ -1702,7 +1693,7 @@ internal class Vala.DBusClientModule : DBusModule { string generate_finish_dbus_proxy_method (Interface iface, Method m) { string proxy_name = "%sdbus_proxy_%s_finish".printf (iface.get_lower_case_cprefix (), m.name); - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); CCodeDeclaration cdecl; @@ -1762,7 +1753,7 @@ internal class Vala.DBusClientModule : DBusModule { string generate_dbus_proxy_property_get (Interface iface, Property prop) { string proxy_name = "%sdbus_proxy_get_%s".printf (iface.get_lower_case_cprefix (), prop.name); - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); var owned_type = prop.get_accessor.value_type.copy (); owned_type.value_owned = true; @@ -1909,7 +1900,7 @@ internal class Vala.DBusClientModule : DBusModule { string generate_dbus_proxy_property_set (Interface iface, Property prop) { string proxy_name = "%sdbus_proxy_set_%s".printf (iface.get_lower_case_cprefix (), prop.name); - string dbus_iface_name = iface.get_attribute ("DBus").get_string ("name"); + string dbus_iface_name = get_dbus_name (iface); var array_type = prop.set_accessor.value_type as ArrayType; diff --git a/codegen/valadbusmodule.vala b/codegen/valadbusmodule.vala index 87f60b5f6..1e9cb1f9b 100644 --- a/codegen/valadbusmodule.vala +++ b/codegen/valadbusmodule.vala @@ -49,6 +49,15 @@ internal class Vala.DBusModule : GAsyncModule { base (codegen, next); } + public string? get_dbus_name (TypeSymbol symbol) { + var dbus = symbol.get_attribute ("DBus"); + if (dbus == null) { + return null; + } + + return dbus.get_string ("name"); + } + bool get_basic_type_info (string signature, out BasicTypeInfo basic_type) { foreach (BasicTypeInfo info in basic_types) { if (info.signature == signature) { diff --git a/codegen/valadbusservermodule.vala b/codegen/valadbusservermodule.vala index d29f27ec0..46bf7bf12 100644 --- a/codegen/valadbusservermodule.vala +++ b/codegen/valadbusservermodule.vala @@ -1145,11 +1145,7 @@ internal class Vala.DBusServerModule : DBusClientModule { } } - var dbus = sym.get_attribute ("DBus"); - if (dbus == null) { - return result; - } - string dbus_iface_name = dbus.get_string ("name"); + string dbus_iface_name = get_dbus_name (sym); if (dbus_iface_name == null) { return result; } @@ -1350,11 +1346,7 @@ internal class Vala.DBusServerModule : DBusClientModule { } void handle_signals (ObjectTypeSymbol sym, CCodeBlock block) { - var dbus = sym.get_attribute ("DBus"); - if (dbus == null) { - return; - } - string dbus_iface_name = dbus.get_string ("name"); + string dbus_iface_name = get_dbus_name (sym); if (dbus_iface_name == null) { return; } @@ -1403,38 +1395,35 @@ internal class Vala.DBusServerModule : DBusClientModule { handle_method ("org.freedesktop.DBus.Introspectable", "Introspect", generate_dbus_introspect (sym), block, ref clastif); - var dbus = sym.get_attribute ("DBus"); - if (dbus != null) { - string dbus_iface_name = dbus.get_string ("name"); - if (dbus_iface_name != null) { - bool need_property_get = false; - bool need_property_set = false; - foreach (Property prop in sym.get_properties ()) { - if (prop.binding != MemberBinding.INSTANCE - || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) { - continue; - } - if (!is_dbus_visible (prop)) { - continue; - } - if (prop.get_accessor != null) { - need_property_get = true; - } - if (prop.set_accessor != null) { - need_property_set = true; - } + string dbus_iface_name = get_dbus_name (sym); + if (dbus_iface_name != null) { + bool need_property_get = false; + bool need_property_set = false; + foreach (Property prop in sym.get_properties ()) { + if (prop.binding != MemberBinding.INSTANCE + || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) { + continue; } - - if (need_property_get) { - handle_method ("org.freedesktop.DBus.Properties", "Get", generate_dbus_property_get_wrapper (sym, dbus_iface_name), block, ref clastif); + if (!is_dbus_visible (prop)) { + continue; } - if (need_property_set) { - handle_method ("org.freedesktop.DBus.Properties", "Set", generate_dbus_property_set_wrapper (sym, dbus_iface_name), block, ref clastif); + if (prop.get_accessor != null) { + need_property_get = true; } - handle_method ("org.freedesktop.DBus.Properties", "GetAll", generate_dbus_property_get_all_wrapper (sym, dbus_iface_name), block, ref clastif); + if (prop.set_accessor != null) { + need_property_set = true; + } + } - handle_methods (sym, dbus_iface_name, block, ref clastif); + if (need_property_get) { + handle_method ("org.freedesktop.DBus.Properties", "Get", generate_dbus_property_get_wrapper (sym, dbus_iface_name), block, ref clastif); } + if (need_property_set) { + handle_method ("org.freedesktop.DBus.Properties", "Set", generate_dbus_property_set_wrapper (sym, dbus_iface_name), block, ref clastif); + } + handle_method ("org.freedesktop.DBus.Properties", "GetAll", generate_dbus_property_get_all_wrapper (sym, dbus_iface_name), block, ref clastif); + + handle_methods (sym, dbus_iface_name, block, ref clastif); } var resultblock = new CCodeBlock ();