[glib] gdbus-codegen: Use G_TYPE_STRV/gchar** for GVariant type 'ao'



commit 419bfe325c40604268dbb7fa050e355c9681577e
Author: David Zeuthen <davidz redhat com>
Date:   Thu Jul 21 09:32:38 2011 -0400

    gdbus-codegen: Use G_TYPE_STRV/gchar** for GVariant type 'ao'
    
    This is possible now that we have better support for object path
    arrays, see
    
     http://git.gnome.org/browse/glib/commit/?id=19878998bc386db78614f1c92ff8524a81479c7b
    
    Note that this breaks the ABI of generated code but since
    gdbus-codegen(1) has never yet been in a stable GLib release, this is
    fine.
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 docs/reference/gio/gdbus-codegen.xml |    3 ++-
 gio/gdbus-codegen/codegen.py         |    2 ++
 gio/gdbus-codegen/dbustypes.py       |    8 ++++++++
 gio/gdbusutils.c                     |   15 ++++++++++++++-
 gio/tests/gdbus-test-codegen.c       |   24 +++++++++++++-----------
 5 files changed, 39 insertions(+), 13 deletions(-)
---
diff --git a/docs/reference/gio/gdbus-codegen.xml b/docs/reference/gio/gdbus-codegen.xml
index a5b8068..33c4617 100644
--- a/docs/reference/gio/gdbus-codegen.xml
+++ b/docs/reference/gio/gdbus-codegen.xml
@@ -754,7 +754,8 @@ on_handle_hello_world (MyAppFrobber           *interface,
     <link linkend="G-VARIANT-TYPE-OBJECT-PATH:CAPS">'o'</link> and
     <link linkend="G-VARIANT-TYPE-SIGNATURE:CAPS">'g'</link>) and
     arrays of string (type-strings
-    <link linkend="G-VARIANT-TYPE-STRING-ARRAY:CAPS">'as'</link> and
+    <link linkend="G-VARIANT-TYPE-STRING-ARRAY:CAPS">'as'</link>,
+    <link linkend="G-VARIANT-TYPE-OBJECT-PATH-ARRAY:CAPS">'ao'</link> and
     <link linkend="G-VARIANT-TYPE-BYTESTRING-ARRAY:CAPS">'aay'</link>)
     are mapped to the natural types,
     e.g. #gboolean, #gdouble, #gint, <link linkend="gchararray">gchar*</link>,
diff --git a/gio/gdbus-codegen/codegen.py b/gio/gdbus-codegen/codegen.py
index 6a2d620..3d29e56 100644
--- a/gio/gdbus-codegen/codegen.py
+++ b/gio/gdbus-codegen/codegen.py
@@ -1096,6 +1096,8 @@ class CodeGenerator:
                     s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
                 elif p.arg.signature == 'as':
                     s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
+                elif p.arg.signature == 'ao':
+                    s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
                 elif p.arg.signature == 'aay':
                     s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
                 else:
diff --git a/gio/gdbus-codegen/dbustypes.py b/gio/gdbus-codegen/dbustypes.py
index 3a39f13..1289da4 100644
--- a/gio/gdbus-codegen/dbustypes.py
+++ b/gio/gdbus-codegen/dbustypes.py
@@ -166,6 +166,14 @@ class Arg:
                 self.free_func = 'g_strfreev'
                 self.format_in = '^as'
                 self.format_out = '^as'
+            elif self.signature == 'ao':
+                self.ctype_in_g  = 'const gchar *const *'
+                self.ctype_in  = 'const gchar *const *'
+                self.ctype_out = 'gchar ***'
+                self.gtype = 'G_TYPE_STRV'
+                self.free_func = 'g_strfreev'
+                self.format_in = '^ao'
+                self.format_out = '^ao'
             elif self.signature == 'aay':
                 self.ctype_in_g  = 'const gchar *const *'
                 self.ctype_in  = 'const gchar *const *'
diff --git a/gio/gdbusutils.c b/gio/gdbusutils.c
index 35dc217..7902b00 100644
--- a/gio/gdbusutils.c
+++ b/gio/gdbusutils.c
@@ -461,6 +461,12 @@ g_dbus_gvariant_to_gvalue (GVariant  *value,
           g_value_take_boxed (out_gvalue, array);
           break;
 
+        case G_VARIANT_CLASS_OBJECT_PATH:
+          g_value_init (out_gvalue, G_TYPE_STRV);
+          array = g_variant_dup_objv (value, NULL);
+          g_value_take_boxed (out_gvalue, array);
+          break;
+
         case G_VARIANT_CLASS_ARRAY:
           switch (g_variant_type_peek_string (type)[2])
             {
@@ -519,7 +525,7 @@ g_dbus_gvariant_to_gvalue (GVariant  *value,
  *       </row>
  *       <row>
  *         <entry>#G_TYPE_STRV</entry>
- *         <entry><link linkend="G-VARIANT-TYPE-STRING-ARRAY:CAPS">'as'</link> or <link linkend="G-VARIANT-TYPE-BYTESTRING-ARRAY:CAPS">'aay'</link></entry>
+ *         <entry><link linkend="G-VARIANT-TYPE-STRING-ARRAY:CAPS">'as'</link>, <link linkend="G-VARIANT-TYPE-OBJECT-PATH-ARRAY:CAPS">'ao'</link> or <link linkend="G-VARIANT-TYPE-BYTESTRING-ARRAY:CAPS">'aay'</link></entry>
  *       </row>
  *       <row>
  *         <entry>#G_TYPE_BOOLEAN</entry>
@@ -684,6 +690,13 @@ g_dbus_gvalue_to_gvariant (const GValue       *gvalue,
               ret = g_variant_ref_sink (g_variant_new_strv (as, -1));
               break;
 
+            case G_VARIANT_CLASS_OBJECT_PATH:
+              as = g_value_get_boxed (gvalue);
+              if (as == NULL)
+                as = empty_strv;
+              ret = g_variant_ref_sink (g_variant_new_objv (as, -1));
+              break;
+
             case G_VARIANT_CLASS_ARRAY:
               switch (g_variant_type_peek_string (type)[2])
                 {
diff --git a/gio/tests/gdbus-test-codegen.c b/gio/tests/gdbus-test-codegen.c
index 24c1cae..30906e0 100644
--- a/gio/tests/gdbus-test-codegen.c
+++ b/gio/tests/gdbus-test-codegen.c
@@ -151,7 +151,7 @@ on_handle_test_non_primitive_types (FooBar                *object,
                                     GVariant              *dict_s_to_pairs,
                                     GVariant              *a_struct,
                                     const gchar* const    *array_of_strings,
-                                    GVariant              *array_of_objpaths,
+                                    const gchar* const    *array_of_objpaths,
                                     GVariant              *array_of_signatures,
                                     const gchar* const    *array_of_bytestrings,
                                     gpointer               user_data)
@@ -165,10 +165,10 @@ on_handle_test_non_primitive_types (FooBar                *object,
   s = g_strjoinv (", ", (gchar **) array_of_strings);
   g_string_append_printf (str, "array_of_strings: [%s] ", s);
   g_free (s);
-  s = g_variant_print (array_of_objpaths, TRUE);
-  g_string_append_printf (str, "array_of_objpaths: %s ", s);
+  s = g_strjoinv (", ", (gchar **) array_of_objpaths);
+  g_string_append_printf (str, "array_of_objpaths: [%s] ", s);
   g_free (s);
-  s = g_variant_print (array_of_objpaths, TRUE);
+  s = g_variant_print (array_of_signatures, TRUE);
   g_string_append_printf (str, "array_of_signatures: %s ", s);
   g_free (s);
   s = g_strjoinv (", ", (gchar **) array_of_bytestrings);
@@ -715,7 +715,7 @@ check_bar_proxy (FooBar    *proxy,
   gchar *val_g;
   gchar *val_ay;
   gchar **val_as;
-  GVariant *val_ao;
+  gchar **val_ao;
   GVariant *val_ag;
   gint32 val_unset_i;
   gdouble val_unset_d;
@@ -724,7 +724,7 @@ check_bar_proxy (FooBar    *proxy,
   gchar *val_unset_g;
   gchar *val_unset_ay;
   gchar **val_unset_as;
-  GVariant *val_unset_ao;
+  gchar **val_unset_ao;
   GVariant *val_unset_ag;
   GVariant *val_unset_struct;
   gchar *val_finally_normal_name;
@@ -787,7 +787,7 @@ check_bar_proxy (FooBar    *proxy,
   g_assert_cmpstr (val_ay, ==, "ABCabc");
   g_free (val_ay);
   g_strfreev (val_as);
-  g_variant_unref (val_ao);
+  g_strfreev (val_ao);
   g_variant_unref (val_ag);
   g_free (val_finally_normal_name);
   /* check empty values */
@@ -801,7 +801,7 @@ check_bar_proxy (FooBar    *proxy,
   g_free (val_unset_g);
   g_assert_cmpstr (val_unset_ay, ==, "");
   g_assert (val_unset_as[0] == NULL);
-  g_assert (g_variant_is_of_type (val_unset_ao, G_VARIANT_TYPE ("ao")));
+  g_assert (val_unset_ao[0] == NULL);
   g_assert (g_variant_is_of_type (val_unset_ag, G_VARIANT_TYPE ("ag")));
   g_assert (g_variant_is_of_type (val_unset_struct, G_VARIANT_TYPE ("(idsogayasaoag)")));
   s = g_variant_print (val_unset_struct, TRUE);
@@ -809,7 +809,7 @@ check_bar_proxy (FooBar    *proxy,
   g_free (s);
   g_free (val_unset_ay);
   g_strfreev (val_unset_as);
-  g_variant_unref (val_unset_ao);
+  g_strfreev (val_unset_ao);
   g_variant_unref (val_unset_ag);
   g_variant_unref (val_unset_struct);
 
@@ -825,14 +825,16 @@ check_bar_proxy (FooBar    *proxy,
    * is to exercise the paths that frees the references.
    */
   const gchar *array_of_strings[3] = {"one", "two", NULL};
+  const gchar *array_of_objpaths[3] = {"/one", "/one/two", NULL};
   const gchar *array_of_bytestrings[3] = {"one\xff", "two\xff", NULL};
+
   g_object_set (proxy,
                 "s", "a string",
                 "o", "/a/path",
                 "g", "asig",
                 "ay", g_variant_new_parsed ("[byte 0x65, 0x67]"),
                 "as", array_of_strings,
-                "ao", g_variant_new_parsed ("[ o '/one', '/one/two']"),
+                "ao", array_of_objpaths,
                 "ag", g_variant_new_parsed ("[ g 'ass', 'git']"),
                 NULL);
 
@@ -877,7 +879,7 @@ check_bar_proxy (FooBar    *proxy,
                                                                           "'second': (43, 43)}"),
                                                     g_variant_new_parsed ("(42, 'foo', 'bar')"),
                                                     array_of_strings,
-                                                    g_variant_new_parsed ("[ o '/one', '/one/two']"),
+                                                    array_of_objpaths,
                                                     g_variant_new_parsed ("[ g 'ass', 'git']"),
                                                     array_of_bytestrings,
                                                     &s,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]