]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dbusgen: Add DBus signature attribute if type is not supported yet
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 19 Sep 2018 17:13:18 +0000 (19:13 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 29 Apr 2023 19:00:17 +0000 (21:00 +0200)
dbusgen/valadbusparser.vala
dbusgen/valadbusvariantmodule.vala

index e265d08a87286b18ca8ac0328a4c68010875d926..fa1e4b0e838a958808710dd082f9f5f11833401e 100644 (file)
@@ -347,7 +347,12 @@ public class Vala.DBusParser : CodeVisitor {
                        return;
                }
 
+               var needs_signature = false;
                var data_type = dbus_module.get_dbus_type (type);
+               if (data_type == null) {
+                       data_type = dbus_module.gvariant_type.copy ();
+                       needs_signature = true;
+               }
 
                PropertyAccessor get_access = null;
                PropertyAccessor set_access = null;
@@ -369,6 +374,10 @@ public class Vala.DBusParser : CodeVisitor {
                current_property.access = SymbolAccessibility.PUBLIC;
                current_iface.add_property (current_property);
 
+               if (needs_signature) {
+                       current_node.set_attribute_string ("DBus", "signature", type);
+               }
+
                next ();
 
                while (current_token == MarkupTokenType.START_ELEMENT) {
@@ -396,12 +405,21 @@ public class Vala.DBusParser : CodeVisitor {
                        return;
                }
 
+               var needs_signature = false;
                var data_type = dbus_module.get_dbus_type (type);
+               if (data_type == null) {
+                       data_type = dbus_module.gvariant_type.copy ();
+                       needs_signature = true;
+               }
                data_type.value_owned = false;
 
                current_node = current_param = new Parameter (name, data_type, get_current_src ());
                current_method.add_parameter (current_param);
 
+               if (needs_signature) {
+                       current_node.set_attribute_string ("DBus", "signature", type);
+               }
+
                if (current_method is Method) {
                        string? direction = reader.get_attribute ("direction");
                        if (direction == "out") {
index df69a2c156ba4de6928bb21eee18368c17cfe12c..fdb57f7c25bab7d981de0c9777d216d8f15b2e7e 100644 (file)
@@ -120,7 +120,7 @@ public class Vala.DBusVariantModule {
                }
        }
 
-       private DataType get_variant_type (VariantType type) {
+       private DataType? get_variant_type (VariantType type) {
                if (type.is_basic ()) {
                        if (type.equal (VariantType.BOOLEAN)) {
                                return bool_type.copy ();
@@ -155,16 +155,26 @@ public class Vala.DBusVariantModule {
                return get_complex_type (type);
        }
 
-       private DataType get_complex_type (VariantType type) {
+       private DataType? get_complex_type (VariantType type) {
                if (type.is_array ()) {
                        var element = type.element ();
                        if (element.equal (VariantType.DICTIONARY) || element.is_dict_entry ()) {
                                var res = dictionary_type.copy ();
-                               res.add_type_argument (get_variant_type (element.key ()));
-                               res.add_type_argument (get_variant_type (element.value ()));
-                               return res;
+                               var key = get_variant_type (element.key ());
+                               var value = get_variant_type (element.value ());
+                               if (key != null && value != null) {
+                                       res.add_type_argument (key);
+                                       res.add_type_argument (value);
+                                       return res;
+                               }
+                       } else {
+                               var element_type = get_variant_type (element);
+                               if (element != null && !(element_type is ArrayType)) {
+                                       var array = new ArrayType (element_type, 1, null);
+                                       array.value_owned = true;
+                                       return array;
+                               }
                        }
-                       return new ArrayType (get_variant_type (element), 1, null);
                } else if (type.equal (VariantType.BYTESTRING)) {
                        return string_type.copy (); //new ArrayType (uchar_type.copy (), 1, null);
                } else if (type.equal (VariantType.BYTESTRING_ARRAY)) {
@@ -177,7 +187,7 @@ public class Vala.DBusVariantModule {
 
                Report.warning (null, "Unresolved type: %s".printf ((string) type.peek_string ()));
 
-               return gvariant_type.copy ();
+               return null;
 
                if (type.equal (VariantType.DICT_ENTRY) || type.is_dict_entry ()) {
                        return dictionary_type.copy ();