]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Add get_dbus_name helper method
authorJürg Billeter <j@bitron.ch>
Mon, 14 Sep 2009 19:55:08 +0000 (21:55 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 14 Sep 2009 21:44:01 +0000 (23:44 +0200)
codegen/valadbusclientmodule.vala
codegen/valadbusmodule.vala
codegen/valadbusservermodule.vala

index 1ab4bac1466f7999bd4399db98b2bd1c61685cb3..c5f25f4c221c58fdd070aaf1ca37b774dc674606 100644 (file)
@@ -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;
 
index 87f60b5f609ec64cd3c7aba55f3e0f1f0848f9a3..1e9cb1f9b67608f07fde6f1bd63aa9df645d9b5f 100644 (file)
@@ -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) {
index d29f27ec0d72b4fc084e1446086c4afb5e7291cd..46bf7bf12aac6e1f147ee29f3856e13dd3ec809d 100644 (file)
@@ -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 ();