]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Support array properties in servers
authorJürg Billeter <j@bitron.ch>
Sun, 14 Jun 2009 13:47:21 +0000 (15:47 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 14 Jun 2009 14:18:21 +0000 (16:18 +0200)
Fixes bug 585434.

codegen/valadbusmodule.vala
codegen/valadbusservermodule.vala

index 5e7fe11d270f9b94f1622c5a58335c3dc32cb341..81ed0d7b08a2f872638c0023400ad217cb606406 100644 (file)
@@ -62,10 +62,20 @@ internal class Vala.DBusModule : GAsyncModule {
        CCodeExpression? get_array_length (CCodeExpression expr, int dim) {
                var id = expr as CCodeIdentifier;
                var ma = expr as CCodeMemberAccess;
+               var call = expr as CCodeFunctionCall;
                if (id != null) {
                        return new CCodeIdentifier ("%s_length%d".printf (id.name, dim));
                } else if (ma != null) {
                        return new CCodeMemberAccess.pointer (ma.inner, "%s_length%d".printf (ma.member_name, dim));
+               } else if (call != null) {
+                       // array property
+                       var args = call.get_arguments ();
+                       if (args.size > 0) {
+                               var arg = args[args.size - 1] as CCodeUnaryExpression;
+                               if (arg != null && arg.operator == CCodeUnaryOperator.ADDRESS_OF) {
+                                       return arg.inner;
+                               }
+                       }
                }
                return null;
        }
index 51154c965649edc410b7aef80bcd4729c8ce2860..4862f505aa41f56ec18876c32d9623652585927b 100644 (file)
@@ -567,6 +567,19 @@ internal class Vala.DBusServerModule : DBusClientModule {
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (prop.get_accessor.get_cname ()));
                        ccall.add_argument (new CCodeIdentifier ("self"));
 
+                       var array_type = prop.property_type as ArrayType;
+                       if (array_type != null) {
+                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                       string length_name = "_tmp%d_".printf (next_temp_var_id++);
+
+                                       cdecl = new CCodeDeclaration ("int");
+                                       cdecl.add_declarator (new CCodeVariableDeclarator (length_name));
+                                       postfragment.append (cdecl);
+
+                                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (length_name)));
+                               }
+                       }
+
                        write_expression (postfragment, prop.property_type, new CCodeIdentifier ("subiter"), ccall);
 
                        iter_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_message_iter_close_container"));
@@ -733,6 +746,19 @@ internal class Vala.DBusServerModule : DBusClientModule {
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (prop.get_accessor.get_cname ()));
                        ccall.add_argument (new CCodeIdentifier ("self"));
 
+                       var array_type = prop.property_type as ArrayType;
+                       if (array_type != null) {
+                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                       string length_name = "_tmp%d_".printf (next_temp_var_id++);
+
+                                       cdecl = new CCodeDeclaration ("int");
+                                       cdecl.add_declarator (new CCodeVariableDeclarator (length_name));
+                                       postfragment.append (cdecl);
+
+                                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (length_name)));
+                               }
+                       }
+
                        write_expression (postfragment, prop.property_type, new CCodeIdentifier ("value_iter"), ccall);
 
                        iter_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_message_iter_close_container"));
@@ -873,6 +899,17 @@ internal class Vala.DBusServerModule : DBusClientModule {
                        ccall.add_argument (new CCodeIdentifier ("self"));
                        ccall.add_argument (new CCodeIdentifier ("value"));
 
+                       var array_type = prop.property_type as ArrayType;
+                       if (array_type != null) {
+                               for (int dim = 1; dim <= array_type.rank; dim++) {
+                                       cdecl = new CCodeDeclaration ("int");
+                                       cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname ("value", dim)));
+                                       prefragment.append (cdecl);
+
+                                       ccall.add_argument (new CCodeIdentifier (head.get_array_length_cname ("value", dim)));
+                               }
+                       }
+
                        prop_block.add_statement (new CCodeExpressionStatement (ccall));
 
                        var cif = new CCodeIfStatement (ccheck, prop_block);