G_VARIANT_TYPE_DICT_ENTRY
G_VARIANT_TYPE_DICTIONARY
G_VARIANT_TYPE_STRING_ARRAY
+G_VARIANT_TYPE_OBJECT_PATH_ARRAY
G_VARIANT_TYPE_BYTESTRING
G_VARIANT_TYPE_BYTESTRING_ARRAY
G_VARIANT_TYPE_VARDICT
g_variant_is_signature
g_variant_new_variant
g_variant_new_strv
+g_variant_new_objv
g_variant_new_bytestring
g_variant_new_bytestring_array
g_variant_get_variant
g_variant_get_strv
g_variant_dup_strv
+g_variant_get_objv
+g_variant_dup_objv
g_variant_get_bytestring
g_variant_dup_bytestring
g_variant_get_bytestring_array
<listitem>
<para>
'<literal>&s</literal>' '<literal>&o</literal>', '<literal>&g</literal>', '<literal>^as</literal>',
- '<literal>^a&s</literal>', '<literal>^ay</literal>', '<literal>^&ay</literal>', '<literal>^aay</literal>'
- or '<literal>^a&ay</literal>'.
+ '<literal>^a&s</literal>', '<literal>^ao</literal>', '<literal>^a&o</literal>','<literal>^ay</literal>',
+ '<literal>^&ay</literal>', '<literal>^aay</literal>' or '<literal>^a&ay</literal>'.
</para>
</listitem>
<listitem>
<entry colsep='1' rowsep='1'>
<para>
<emphasis role='strong'>
+ <literal>^ao</literal>
+ </emphasis>
+ </para>
+ </entry>
+ <entry colsep='1' rowsep='1' morerows='1'>
+ <para>
+ equivalent to <link linkend='g-variant-new-objv'><function>g_variant_new_objv()</function></link>
+ </para>
+ </entry>
+ <entry colsep='1' rowsep='1'>
+ <para>
+ equivalent to <link linkend='g-variant-dup-objv'><function>g_variant_dup_objv()</function></link>
+ </para>
+ </entry>
+ </row>
+
+ <row rowsep='1'>
+ <entry colsep='1' rowsep='1'>
+ <para>
+ <emphasis role='strong'>
+ <literal>^a&o</literal>
+ </emphasis>
+ </para>
+ </entry>
+ <entry colsep='1' rowsep='1'>
+ <para>
+ equivalent to <link linkend='g-variant-get-objv'><function>g_variant_get_objv()</function></link>
+ </para>
+ </entry>
+ </row>
+
+ <row rowsep='1'>
+ <entry colsep='1' rowsep='1'>
+ <para>
+ <emphasis role='strong'>
<literal>^ay</literal>
</emphasis>
</para>
g_variant_is_signature
g_variant_new_variant
g_variant_new_strv
+g_variant_new_objv
g_variant_new_bytestring
g_variant_new_bytestring_array
g_variant_get_boolean
g_variant_get_variant
g_variant_get_strv
g_variant_dup_strv
+g_variant_get_objv
+g_variant_dup_objv
g_variant_get_bytestring
g_variant_dup_bytestring
g_variant_get_bytestring_array
}
/**
+ * g_variant_new_objv:
+ * @strv: (array length=length) (element-type utf8): an array of strings
+ * @length: the length of @strv, or -1
+ * @returns: (transfer none): a new floating #GVariant instance
+ *
+ * Constructs an array of object paths #GVariant from the given array of
+ * strings.
+ *
+ * Each string must be a valid #GVariant object path; see
+ * g_variant_is_object_path().
+ *
+ * If @length is -1 then @strv is %NULL-terminated.
+ *
+ * Since: 2.30
+ **/
+GVariant *
+g_variant_new_objv (const gchar * const *strv,
+ gssize length)
+{
+ GVariant **strings;
+ gsize i;
+
+ g_return_val_if_fail (length == 0 || strv != NULL, NULL);
+
+ if (length < 0)
+ length = g_strv_length ((gchar **) strv);
+
+ strings = g_new (GVariant *, length);
+ for (i = 0; i < length; i++)
+ strings[i] = g_variant_ref_sink (g_variant_new_object_path (strv[i]));
+
+ return g_variant_new_from_children (G_VARIANT_TYPE_OBJECT_PATH_ARRAY,
+ strings, length, TRUE);
+}
+
+/**
+ * g_variant_get_objv:
+ * @value: an array of object paths #GVariant
+ * @length: (out) (allow-none): the length of the result, or %NULL
+ * @returns: (array length=length zero-terminated=1) (transfer container): an array of constant
+ * strings
+ *
+ * Gets the contents of an array of object paths #GVariant. This call
+ * makes a shallow copy; the return result should be released with
+ * g_free(), but the individual strings must not be modified.
+ *
+ * If @length is non-%NULL then the number of elements in the result
+ * is stored there. In any case, the resulting array will be
+ * %NULL-terminated.
+ *
+ * For an empty array, @length will be set to 0 and a pointer to a
+ * %NULL pointer will be returned.
+ *
+ * Since: 2.30
+ **/
+const gchar **
+g_variant_get_objv (GVariant *value,
+ gsize *length)
+{
+ const gchar **strv;
+ gsize n;
+ gsize i;
+
+ TYPE_CHECK (value, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, NULL);
+
+ g_variant_get_data (value);
+ n = g_variant_n_children (value);
+ strv = g_new (const gchar *, n + 1);
+
+ for (i = 0; i < n; i++)
+ {
+ GVariant *string;
+
+ string = g_variant_get_child_value (value, i);
+ strv[i] = g_variant_get_string (string, NULL);
+ g_variant_unref (string);
+ }
+ strv[i] = NULL;
+
+ if (length)
+ *length = n;
+
+ return strv;
+}
+
+/**
+ * g_variant_dup_objv:
+ * @value: an array of object paths #GVariant
+ * @length: (out) (allow-none): the length of the result, or %NULL
+ * @returns: (array length=length zero-terminated=1) (transfer full): an array of strings
+ *
+ * Gets the contents of an array of object paths #GVariant. This call
+ * makes a deep copy; the return result should be released with
+ * g_strfreev().
+ *
+ * If @length is non-%NULL then the number of elements in the result
+ * is stored there. In any case, the resulting array will be
+ * %NULL-terminated.
+ *
+ * For an empty array, @length will be set to 0 and a pointer to a
+ * %NULL pointer will be returned.
+ *
+ * Since: 2.30
+ **/
+gchar **
+g_variant_dup_objv (GVariant *value,
+ gsize *length)
+{
+ gchar **strv;
+ gsize n;
+ gsize i;
+
+ TYPE_CHECK (value, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, NULL);
+
+ n = g_variant_n_children (value);
+ strv = g_new (gchar *, n + 1);
+
+ for (i = 0; i < n; i++)
+ {
+ GVariant *string;
+
+ string = g_variant_get_child_value (value, i);
+ strv[i] = g_variant_dup_string (string, NULL);
+ g_variant_unref (string);
+ }
+ strv[i] = NULL;
+
+ if (length)
+ *length = n;
+
+ return strv;
+}
+
+
+/**
* g_variant_new_bytestring:
* @string: (array zero-terminated=1): a normal nul-terminated string in no particular encoding
* @returns: (transfer none): a floating reference to a new bytestring #GVariant instance
break; /* '^a&ay' */
}
- else if (c == 's')
- break; /* '^a&s' */
+ else if (c == 's' || c == 'o')
+ break; /* '^a&s', '^a&o' */
}
else if (c == 'a')
break; /* '^aay' */
}
- else if (c == 's')
- break; /* '^as' */
+ else if (c == 's' || c == 'o')
+ break; /* '^as', '^ao' */
else if (c == 'y')
break; /* '^ay' */
break;
case '^':
- if (str[2] != '&') /* '^as' */
+ if (str[2] != '&') /* '^as', '^ao' */
g_strfreev (ptr);
- else /* '^a&s' */
+ else /* '^a&s', '^a&o' */
g_free (ptr);
break;
{
gboolean constant;
guint arrays;
+ gchar type;
+
+ type = g_variant_scan_convenience (str, &constant, &arrays);
- if (g_variant_scan_convenience (str, &constant, &arrays) == 's')
+ if (type == 's')
return g_variant_new_strv (ptr, -1);
+ if (type == 'o')
+ return g_variant_new_objv (ptr, -1);
+
if (arrays > 1)
return g_variant_new_bytestring_array (ptr, -1);
{
gboolean constant;
guint arrays;
+ gchar type;
+
+ type = g_variant_scan_convenience (str, &constant, &arrays);
- if (g_variant_scan_convenience (str, &constant, &arrays) == 's')
+ if (type == 's')
{
if (constant)
return g_variant_get_strv (value, NULL);
return g_variant_dup_strv (value, NULL);
}
+ else if (type == 'o')
+ {
+ if (constant)
+ return g_variant_get_objv (value, NULL);
+ else
+ return g_variant_dup_objv (value, NULL);
+ }
+
else if (arrays > 1)
{
if (constant)
GVariant * g_variant_new_variant (GVariant *value);
GVariant * g_variant_new_strv (const gchar * const *strv,
gssize length);
+GVariant * g_variant_new_objv (const gchar * const *strv,
+ gssize length);
GVariant * g_variant_new_bytestring (const gchar *string);
GVariant * g_variant_new_bytestring_array (const gchar * const *strv,
gssize length);
gsize *length);
gchar ** g_variant_dup_strv (GVariant *value,
gsize *length);
+const gchar ** g_variant_get_objv (GVariant *value,
+ gsize *length);
+gchar ** g_variant_dup_objv (GVariant *value,
+ gsize *length);
const gchar * g_variant_get_bytestring (GVariant *value);
gchar * g_variant_dup_bytestring (GVariant *value,
gsize *length);
#define G_VARIANT_TYPE_STRING_ARRAY ((const GVariantType *) "as")
/**
+ * G_VARIANT_TYPE_OBJECT_PATH_ARRAY:
+ *
+ * The type of an array of object paths.
+ **/
+#define G_VARIANT_TYPE_OBJECT_PATH_ARRAY ((const GVariantType *) "ao")
+
+/**
* G_VARIANT_TYPE_BYTESTRING:
*
* The type of an array of bytes. This type is commonly used to pass
}
{
+ const gchar *strvector[] = {"/hello", "/world", NULL};
+ const gchar *test_strs[] = {"/foo", "/bar", "/baz" };
+ GVariantBuilder builder;
+ GVariantIter *array;
+ GVariantIter tuple;
+ const gchar **strv;
+ gchar **my_strv;
+ GVariant *value;
+ gchar *str;
+ gint i;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_OBJECT_PATH_ARRAY);
+ g_variant_builder_add (&builder, "o", "/foo");
+ g_variant_builder_add (&builder, "o", "/bar");
+ g_variant_builder_add (&builder, "o", "/baz");
+ value = g_variant_new("(ao^ao^a&o)", &builder, strvector, strvector);
+ g_variant_iter_init (&tuple, value);
+ g_variant_iter_next (&tuple, "ao", &array);
+
+ i = 0;
+ while (g_variant_iter_loop (array, "o", &str))
+ g_assert_cmpstr (str, ==, test_strs[i++]);
+ g_assert (i == 3);
+
+ g_variant_iter_free (array);
+
+ /* start over */
+ g_variant_iter_init (&tuple, value);
+ g_variant_iter_next (&tuple, "ao", &array);
+
+ i = 0;
+ while (g_variant_iter_loop (array, "&o", &str))
+ g_assert_cmpstr (str, ==, test_strs[i++]);
+ g_assert (i == 3);
+
+ g_variant_iter_free (array);
+
+ g_variant_iter_next (&tuple, "^a&o", &strv);
+ g_variant_iter_next (&tuple, "^ao", &my_strv);
+
+ g_assert_cmpstr (strv[0], ==, "/hello");
+ g_assert_cmpstr (strv[1], ==, "/world");
+ g_assert (strv[2] == NULL);
+ g_assert_cmpstr (my_strv[0], ==, "/hello");
+ g_assert_cmpstr (my_strv[1], ==, "/world");
+ g_assert (my_strv[2] == NULL);
+
+ g_variant_unref (value);
+ g_strfreev (my_strv);
+ g_free (strv);
+ }
+
+ {
const gchar *strvector[] = { "i", "ii", "iii", "iv", "v", "vi", NULL };
GVariantBuilder builder;
GVariantIter iter;