diff options
author | David Zeuthen <davidz@redhat.com> | 2010-05-05 23:19:41 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2010-05-05 23:19:41 -0400 |
commit | 1a6dd00e3fd28ba461956835b1ddf13a2a622ed2 (patch) | |
tree | 6e906c4ba5d27cdc01a074d906e1c0d834a3db8d | |
parent | 15141b79dfab78900d35c08a5a815056de561d27 (diff) |
Slightly rework introspection data structures
In particular, add reference counting.
-rw-r--r-- | docs/reference/gdbus/gdbus-standalone-sections.txt | 15 | ||||
-rw-r--r-- | gdbus/example-peer.c | 4 | ||||
-rw-r--r-- | gdbus/example-server.c | 4 | ||||
-rw-r--r-- | gdbus/example-subtree.c | 2 | ||||
-rw-r--r-- | gdbus/gdbus.c | 93 | ||||
-rw-r--r-- | gdbus/gdbusconnection.c | 4 | ||||
-rw-r--r-- | gdbus/gdbusintrospection.c | 897 | ||||
-rw-r--r-- | gdbus/gdbusintrospection.h | 192 | ||||
-rw-r--r-- | gdbus/gdbusproxy.c | 31 | ||||
-rw-r--r-- | gdbus/gdbusproxy.h | 10 | ||||
-rw-r--r-- | gdbus/tests/export.c | 141 | ||||
-rw-r--r-- | gdbus/tests/introspection.c | 9 | ||||
-rw-r--r-- | gdbus/tests/peer.c | 94 | ||||
-rw-r--r-- | gdbus/tests/proxy.c | 99 |
14 files changed, 862 insertions, 733 deletions
diff --git a/docs/reference/gdbus/gdbus-standalone-sections.txt b/docs/reference/gdbus/gdbus-standalone-sections.txt index 4eac680..09fd542 100644 --- a/docs/reference/gdbus/gdbus-standalone-sections.txt +++ b/docs/reference/gdbus/gdbus-standalone-sections.txt @@ -364,7 +364,6 @@ g_dbus_interface_info_lookup_property g_dbus_interface_info_generate_xml g_dbus_node_info_new_for_xml g_dbus_node_info_lookup_interface -g_dbus_node_info_free g_dbus_node_info_generate_xml G_TYPE_DBUS_NODE_INFO G_TYPE_DBUS_INTERFACE_INFO @@ -373,5 +372,19 @@ G_TYPE_DBUS_SIGNAL_INFO G_TYPE_DBUS_PROPERTY_INFO G_TYPE_DBUS_ARG_INFO G_TYPE_DBUS_ANNOTATION_INFO +g_dbus_node_info_ref +g_dbus_interface_info_ref +g_dbus_method_info_ref +g_dbus_signal_info_ref +g_dbus_property_info_ref +g_dbus_arg_info_ref +g_dbus_annotation_info_ref +g_dbus_node_info_unref +g_dbus_interface_info_unref +g_dbus_method_info_unref +g_dbus_signal_info_unref +g_dbus_property_info_unref +g_dbus_arg_info_unref +g_dbus_annotation_info_unref </SECTION> diff --git a/gdbus/example-peer.c b/gdbus/example-peer.c index 564ed1a..c120568 100644 --- a/gdbus/example-peer.c +++ b/gdbus/example-peer.c @@ -160,7 +160,7 @@ on_new_connection (GDBusServer *server, registration_id = g_dbus_connection_register_object (connection, "/org/gtk/GDBus/TestObject", "org.gtk.GDBus.TestPeerInterface", - &introspection_data->interfaces[0], + introspection_data->interfaces[0], &interface_vtable, NULL, /* user_data */ NULL, /* user_data_free_func */ @@ -309,7 +309,7 @@ main (int argc, char *argv[]) g_object_unref (connection); } - g_dbus_node_info_free (introspection_data); + g_dbus_node_info_unref (introspection_data); ret = 0; diff --git a/gdbus/example-server.c b/gdbus/example-server.c index 363ae2a..ddc1981 100644 --- a/gdbus/example-server.c +++ b/gdbus/example-server.c @@ -325,7 +325,7 @@ on_bus_acquired (GDBusConnection *connection, registration_id = g_dbus_connection_register_object (connection, "/org/gtk/GDBus/TestObject", "org.gtk.GDBus.TestInterface", - &introspection_data->interfaces[0], + introspection_data->interfaces[0], &interface_vtable, NULL, /* user_data */ NULL, /* user_data_free_func */ @@ -382,7 +382,7 @@ main (int argc, char *argv[]) g_bus_unown_name (owner_id); - g_dbus_node_info_free (introspection_data); + g_dbus_node_info_unref (introspection_data); return 0; } diff --git a/gdbus/example-subtree.c b/gdbus/example-subtree.c index f646416..4134930 100644 --- a/gdbus/example-subtree.c +++ b/gdbus/example-subtree.c @@ -404,7 +404,7 @@ main (int argc, char *argv[]) g_bus_unown_name (owner_id); - g_dbus_node_info_free (introspection_data); + g_dbus_node_info_unref (introspection_data); return 0; } diff --git a/gdbus/gdbus.c b/gdbus/gdbus.c index c7dc6bf..2c16280 100644 --- a/gdbus/gdbus.c +++ b/gdbus/gdbus.c @@ -177,16 +177,16 @@ print_methods (GDBusConnection *c, goto out; } - for (n = 0; n < node->num_interfaces; n++) + for (n = 0; node->interfaces != NULL && node->interfaces[n] != NULL; n++) { - const GDBusInterfaceInfo *iface = node->interfaces + n; - for (m = 0; m < iface->num_methods; m++) + const GDBusInterfaceInfo *iface = node->interfaces[n]; + for (m = 0; iface->methods != NULL && iface->methods[m] != NULL; m++) { - const GDBusMethodInfo *method = iface->methods + m; + const GDBusMethodInfo *method = iface->methods[m]; g_print ("%s.%s \n", iface->name, method->name); } } - g_dbus_node_info_free (node); + g_dbus_node_info_unref (node); out: ; @@ -243,25 +243,25 @@ print_paths (GDBusConnection *c, //g_printerr ("bar `%s'\n", path); - if (node->num_interfaces > 0) + if (node->interfaces != NULL) g_print ("%s \n", path); - for (n = 0; n < node->num_nodes; n++) + for (n = 0; node->nodes != NULL && node->nodes[n] != NULL; n++) { gchar *s; //g_printerr ("foo `%s'\n", node->nodes[n].path); if (g_strcmp0 (path, "/") == 0) - s = g_strdup_printf ("/%s", node->nodes[n].path); + s = g_strdup_printf ("/%s", node->nodes[n]->path); else - s = g_strdup_printf ("%s/%s", path, node->nodes[n].path); + s = g_strdup_printf ("%s/%s", path, node->nodes[n]->path); print_paths (c, name, s); g_free (s); } - g_dbus_node_info_free (node); + g_dbus_node_info_unref (node); out: ; @@ -498,14 +498,14 @@ call_helper_get_method_in_signature (GDBusConnection *c, } ret = g_ptr_array_new_with_free_func ((GDestroyNotify) g_variant_type_free); - for (n = 0; n < method_info->in_num_args; n++) + for (n = 0; method_info->in_args != NULL && method_info->in_args[n] != NULL; n++) { - g_ptr_array_add (ret, g_variant_type_new (method_info->in_args[n].signature)); + g_ptr_array_add (ret, g_variant_type_new (method_info->in_args[n]->signature)); } out: if (node_info != NULL) - g_dbus_node_info_free (node_info); + g_dbus_node_info_unref (node_info); if (result != NULL) g_variant_unref (result); @@ -895,6 +895,19 @@ dump_arg (const GDBusArgInfo *o, include_newline ? ",\n" : ""); } +static guint +count_args (GDBusArgInfo **args) +{ + guint n; + n = 0; + if (args == NULL) + goto out; + while (args[n] != NULL) + n++; + out: + return n; +} + static void dump_method (const GDBusMethodInfo *o, guint indent) @@ -902,23 +915,25 @@ dump_method (const GDBusMethodInfo *o, guint n; guint m; guint name_len; + guint total_num_args; g_print ("%*s%s(", indent, "", o->name); name_len = strlen (o->name); - for (n = 0, m = 0; n < o->in_num_args; n++, m++) + total_num_args = count_args (o->in_args) + count_args (o->out_args); + for (n = 0, m = 0; o->in_args != NULL && o->in_args[n] != NULL; n++, m++) { gboolean ignore_indent = (m == 0); - gboolean include_newline = (m != o->in_num_args + o->out_num_args - 1); - dump_arg (&o->in_args[n], + gboolean include_newline = (m != total_num_args - 1); + dump_arg (o->in_args[n], indent + name_len + 1, "in ", ignore_indent, include_newline); } - for (n = 0; n < o->out_num_args; n++, m++) + for (n = 0; o->out_args != NULL && o->out_args[n] != NULL; n++, m++) { gboolean ignore_indent = (m == 0); - gboolean include_newline = (m != o->in_num_args + o->out_num_args - 1); - dump_arg (&o->out_args[n], + gboolean include_newline = (m != total_num_args - 1); + dump_arg (o->out_args[n], indent + name_len + 1, "out ", ignore_indent, @@ -933,13 +948,15 @@ dump_signal (const GDBusSignalInfo *o, { guint n; guint name_len; + guint total_num_args; g_print ("%*s%s(", indent, "", o->name); name_len = strlen (o->name); - for (n = 0; n < o->num_args; n++) + total_num_args = count_args (o->args); + for (n = 0; o->args != NULL && o->args[n] != NULL; n++) { gboolean ignore_indent = (n == 0); - gboolean include_newline = (n != o->num_args - 1); - dump_arg (&o->args[n], + gboolean include_newline = (n != total_num_args - 1); + dump_arg (o->args[n], indent + name_len + 1, "", ignore_indent, @@ -1029,26 +1046,26 @@ dump_interface (GDBusConnection *c, } g_print ("%*sinterface %s {\n", indent, "", o->name); - if (o->num_methods > 0) + if (o->methods != NULL) { g_print ("%*s methods:\n", indent, ""); - for (n = 0; n < o->num_methods; n++) - dump_method (&o->methods[n], indent + 4); + for (n = 0; o->methods[n] != NULL; n++) + dump_method (o->methods[n], indent + 4); } - if (o->num_signals > 0) + if (o->signals != NULL) { g_print ("%*s signals:\n", indent, ""); - for (n = 0; n < o->num_signals; n++) - dump_signal (&o->signals[n], indent + 4); + for (n = 0; o->signals[n] != NULL; n++) + dump_signal (o->signals[n], indent + 4); } - if (o->num_properties > 0) + if (o->properties != NULL) { g_print ("%*s properties:\n", indent, ""); - for (n = 0; n < o->num_properties; n++) + for (n = 0; o->properties[n] != NULL; n++) { - dump_property (&o->properties[n], + dump_property (o->properties[n], indent + 4, - g_hash_table_lookup (properties, (&o->properties[n])->name)); + g_hash_table_lookup (properties, (o->properties[n])->name)); } } g_print ("%*s};\n", @@ -1072,13 +1089,13 @@ dump_node (GDBusConnection *c, object_path_to_print = o->path; g_print ("%*snode %s", indent, "", object_path_to_print != NULL ? object_path_to_print : "(not set)"); - if (o->num_interfaces > 0 || o->num_nodes > 0) + if (o->interfaces != NULL || o->nodes != NULL) { g_print (" {\n"); - for (n = 0; n < o->num_interfaces; n++) - dump_interface (c, name, &o->interfaces[n], indent + 2, object_path); - for (n = 0; n < o->num_nodes; n++) - dump_node (NULL, NULL, &o->nodes[n], indent + 2, NULL); + for (n = 0; o->interfaces != NULL && o->interfaces[n] != NULL; n++) + dump_interface (c, name, o->interfaces[n], indent + 2, object_path); + for (n = 0; o->nodes != NULL && o->nodes[n] != NULL; n++) + dump_node (NULL, NULL, o->nodes[n], indent + 2, NULL); g_print ("%*s};\n", indent, ""); } @@ -1280,7 +1297,7 @@ handle_introspect (gint *argc, out: if (node != NULL) - g_dbus_node_info_free (node); + g_dbus_node_info_unref (node); if (result != NULL) g_variant_unref (result); if (c != NULL) diff --git a/gdbus/gdbusconnection.c b/gdbus/gdbusconnection.c index e921d8f..9f625db 100644 --- a/gdbus/gdbusconnection.c +++ b/gdbus/gdbusconnection.c @@ -3238,9 +3238,9 @@ invoke_get_all_properties_in_idle_cb (gpointer _data) * returns an error. We need clarification in the D-Bus spec about this. */ builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); - for (n = 0; n < data->interface_info->num_properties; n++) + for (n = 0; data->interface_info->properties != NULL && data->interface_info->properties[n] != NULL; n++) { - const GDBusPropertyInfo *property_info = data->interface_info->properties + n; + const GDBusPropertyInfo *property_info = data->interface_info->properties[n]; GVariant *value; if (!(property_info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)) diff --git a/gdbus/gdbusintrospection.c b/gdbus/gdbusintrospection.c index db43e56..3f39c8a 100644 --- a/gdbus/gdbusintrospection.c +++ b/gdbus/gdbusintrospection.c @@ -40,18 +40,6 @@ /* ---------------------------------------------------------------------------------------------------- */ -static gpointer -my_const_copy_func (gpointer boxed) -{ - return boxed; -} - -static void -my_const_free_func (gpointer boxed) -{ - /* do nothing */ -} - /* See also https://bugzilla.gnome.org/show_bug.cgi?id=449565 ... */ #define _MY_DEFINE_BOXED_TYPE(TypeName, type_name) \ GType \ @@ -60,9 +48,9 @@ my_const_free_func (gpointer boxed) static volatile gsize type_volatile = 0; \ if (g_once_init_enter (&type_volatile)) \ { \ - GType type = g_boxed_type_register_static (g_intern_static_string (#TypeName), \ - my_const_copy_func, \ - my_const_free_func); \ + GType type = g_boxed_type_register_static (g_intern_static_string (#TypeName), \ + (GBoxedCopyFunc) type_name##_ref, \ + (GBoxedFreeFunc) type_name##_unref); \ g_once_init_leave (&type_volatile, type); \ } \ return (GType) type_volatile; \ @@ -80,22 +68,22 @@ _MY_DEFINE_BOXED_TYPE (GDBusAnnotationInfo, g_dbus_annotation_info); typedef struct { /* stuff we are currently collecting */ - GArray *args; - GArray *out_args; - GArray *methods; - GArray *signals; - GArray *properties; - GArray *interfaces; - GArray *nodes; - GArray *annotations; - - /* A list of GArray's containing annotations */ + GPtrArray *args; + GPtrArray *out_args; + GPtrArray *methods; + GPtrArray *signals; + GPtrArray *properties; + GPtrArray *interfaces; + GPtrArray *nodes; + GPtrArray *annotations; + + /* A list of GPtrArray's containing annotations */ GSList *annotations_stack; - /* A list of GArray's containing interfaces */ + /* A list of GPtrArray's containing interfaces */ GSList *interfaces_stack; - /* A list of GArray's containing nodes */ + /* A list of GPtrArray's containing nodes */ GSList *nodes_stack; /* Whether the direction was "in" for last parsed arg */ @@ -110,132 +98,318 @@ typedef struct /* ---------------------------------------------------------------------------------------------------- */ -static void g_dbus_annotation_info_free (GDBusAnnotationInfo *info); - -static void -g_dbus_introspector_free_annotation_array (GDBusAnnotationInfo *annotations) +/** + * g_dbus_node_info_ref: + * @info: A #GDBusNodeInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusNodeInfo * +g_dbus_node_info_ref (GDBusNodeInfo *info) { - guint n; - for (n = 0; annotations != NULL && annotations[n].key != NULL; n++) - g_dbus_annotation_info_free (&(annotations[n])); - g_free (annotations); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } -static void -g_dbus_annotation_info_free (GDBusAnnotationInfo *info) +/** + * g_dbus_interface_info_ref: + * @info: A #GDBusInterfaceInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusInterfaceInfo * +g_dbus_interface_info_ref (GDBusInterfaceInfo *info) { - g_free ((gpointer) info->key); - g_free ((gpointer) info->value); - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } -static void -g_dbus_arg_info_free (GDBusArgInfo *info) +/** + * g_dbus_method_info_ref: + * @info: A #GDBusMethodInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusMethodInfo * +g_dbus_method_info_ref (GDBusMethodInfo *info) { - g_free ((gpointer) info->name); - g_free ((gpointer) info->signature); - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } -static void -g_dbus_method_info_free (GDBusMethodInfo *info) +/** + * g_dbus_signal_info_ref: + * @info: A #GDBusSignalInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusSignalInfo * +g_dbus_signal_info_ref (GDBusSignalInfo *info) { - guint n; - - g_free ((gpointer) info->name); - - g_free ((gpointer) info->in_signature); - for (n = 0; n < info->in_num_args; n++) - g_dbus_arg_info_free ((GDBusArgInfo *) &(info->in_args[n])); - g_free ((gpointer) info->in_args); - - g_free ((gpointer) info->out_signature); - for (n = 0; n < info->out_num_args; n++) - g_dbus_arg_info_free ((GDBusArgInfo *) &(info->out_args[n])); - g_free ((gpointer) info->out_args); - - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } -static void -g_dbus_signal_info_free (GDBusSignalInfo *info) +/** + * g_dbus_property_info_ref: + * @info: A #GDBusPropertyInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusPropertyInfo * +g_dbus_property_info_ref (GDBusPropertyInfo *info) { - guint n; - - g_free ((gpointer) info->name); - - g_free ((gpointer) info->signature); - for (n = 0; n < info->num_args; n++) - g_dbus_arg_info_free ((GDBusArgInfo *) &(info->args[n])); - g_free ((gpointer) info->args); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; +} - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); +/** + * g_dbus_arg_info_ref: + * @info: A #GDBusArgInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusArgInfo * +g_dbus_arg_info_ref (GDBusArgInfo *info) +{ + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } -static void -g_dbus_property_info_free (GDBusPropertyInfo *info) +/** + * g_dbus_node_info_ref: + * @info: A #GDBusNodeInfo + * + * If @info is statically allocated does nothing. Otherwise increases + * the reference count. + * + * Returns: The same @info. + */ +GDBusAnnotationInfo * +g_dbus_annotation_info_ref (GDBusAnnotationInfo *info) { - g_free ((gpointer) info->name); - g_free ((gpointer) info->signature); - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); + if (info->ref_count == -1) + return info; + g_atomic_int_inc (&info->ref_count); + return info; } +/* ---------------------------------------------------------------------------------------------------- */ + static void -g_dbus_interface_info_free (GDBusInterfaceInfo *info) +free_null_terminated_array (gpointer array, GDestroyNotify unref_func) { guint n; + gpointer *p = array; + if (p == NULL) + return; + for (n = 0; p[n] != NULL; n++) + unref_func (p[n]); + g_free (p); +} - g_free ((gpointer) info->name); - - for (n = 0; n < info->num_methods; n++) - g_dbus_method_info_free ((GDBusMethodInfo *) &(info->methods[n])); - g_free ((gpointer) info->methods); - - for (n = 0; n < info->num_signals; n++) - g_dbus_signal_info_free ((GDBusSignalInfo *) &(info->signals[n])); - g_free ((gpointer) info->signals); - - for (n = 0; n < info->num_properties; n++) - g_dbus_property_info_free ((GDBusPropertyInfo *) &(info->properties[n])); - g_free ((gpointer) info->properties); +/** + * g_dbus_annotation_info_unref: + * @info: A #GDBusAnnotationInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_annotation_info_unref (GDBusAnnotationInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->key); + g_free (info->value); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } +} - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) info->annotations); +/** + * g_dbus_arg_info_unref: + * @info: A #GDBusArgInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_arg_info_unref (GDBusArgInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->name); + g_free (info->signature); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } } /** - * g_dbus_node_info_free: - * @node_info: A #GDBusNodeInfo. + * g_dbus_method_info_unref: + * @info: A #GDBusMethodInfo. * - * Frees @node_info. This is a deep free, all nodes of @node_info and - * its children will be freed as well. + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. */ void -g_dbus_node_info_free (GDBusNodeInfo *node_info) +g_dbus_method_info_unref (GDBusMethodInfo *info) { - guint n; + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->name); + g_free (info->in_signature); + free_null_terminated_array (info->in_args, (GDestroyNotify) g_dbus_arg_info_unref); + g_free (info->out_signature); + free_null_terminated_array (info->out_args, (GDestroyNotify) g_dbus_arg_info_unref); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } +} - g_free ((gpointer) node_info->path); +/** + * g_dbus_signal_info_unref: + * @info: A #GDBusSignalInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_signal_info_unref (GDBusSignalInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->name); + g_free (info->signature); + free_null_terminated_array (info->args, (GDestroyNotify) g_dbus_arg_info_unref); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } +} - for (n = 0; n < node_info->num_interfaces; n++) - g_dbus_interface_info_free ((GDBusInterfaceInfo *) &(node_info->interfaces[n])); - g_free ((gpointer) node_info->interfaces); +/** + * g_dbus_property_info_unref: + * @info: A #GDBusPropertyInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_property_info_unref (GDBusPropertyInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->name); + g_free (info->signature); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } +} - for (n = 0; n < node_info->num_nodes; n++) - g_dbus_node_info_free ((GDBusNodeInfo *) &(node_info->nodes[n])); - g_free ((gpointer) node_info->nodes); +/** + * g_dbus_interface_info_unref: + * @info: A #GDBusInterfaceInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_interface_info_unref (GDBusInterfaceInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->name); + free_null_terminated_array (info->methods, (GDestroyNotify) g_dbus_method_info_unref); + free_null_terminated_array (info->signals, (GDestroyNotify) g_dbus_signal_info_unref); + free_null_terminated_array (info->properties, (GDestroyNotify) g_dbus_property_info_unref); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } +} - g_dbus_introspector_free_annotation_array ((GDBusAnnotationInfo *) node_info->annotations); +/** + * g_dbus_node_info_unref: + * @info: A #GDBusNodeInfo. + * + * If @info is statically allocated, does nothing. Otherwise decreases + * the reference count of @info. When its reference count drops to 0, + * the memory used is freed. + */ +void +g_dbus_node_info_unref (GDBusNodeInfo *info) +{ + if (info->ref_count == -1) + return; + if (g_atomic_int_dec_and_test (&info->ref_count)) + { + g_free (info->path); + free_null_terminated_array (info->interfaces, (GDestroyNotify) g_dbus_interface_info_unref); + free_null_terminated_array (info->nodes, (GDestroyNotify) g_dbus_node_info_unref); + free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref); + g_free (info); + } } /* ---------------------------------------------------------------------------------------------------- */ static void g_dbus_annotation_info_set (ParseData *data, - GDBusAnnotationInfo *info, - const gchar *key, - const gchar *value, - GDBusAnnotationInfo *embedded_annotations) + GDBusAnnotationInfo *info, + const gchar *key, + const gchar *value, + GDBusAnnotationInfo **embedded_annotations) { + info->ref_count = 1; + if (key != NULL) info->key = g_strdup (key); @@ -247,12 +421,14 @@ g_dbus_annotation_info_set (ParseData *data, } static void -g_dbus_arg_info_set (ParseData *data, - GDBusArgInfo *info, - const gchar *name, - const gchar *signature, - GDBusAnnotationInfo *annotations) +g_dbus_arg_info_set (ParseData *data, + GDBusArgInfo *info, + const gchar *name, + const gchar *signature, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + /* name may be NULL - TODO: compute name? */ if (name != NULL) info->name = g_strdup (name); @@ -265,7 +441,7 @@ g_dbus_arg_info_set (ParseData *data, } static gchar * -compute_signature (GDBusArgInfo *args, +compute_signature (GDBusArgInfo **args, guint num_args) { GString *s; @@ -273,38 +449,40 @@ compute_signature (GDBusArgInfo *args, s = g_string_new (""); for (n = 0; n < num_args; n++) - g_string_append (s, args[n].signature); + g_string_append (s, args[n]->signature); return g_string_free (s, FALSE); } static void -g_dbus_method_info_set (ParseData *data, - GDBusMethodInfo *info, - const gchar *name, - guint in_num_args, - GDBusArgInfo *in_args, - guint out_num_args, - GDBusArgInfo *out_args, - GDBusAnnotationInfo *annotations) +g_dbus_method_info_set (ParseData *data, + GDBusMethodInfo *info, + const gchar *name, + guint in_num_args, + GDBusArgInfo **in_args, + guint out_num_args, + GDBusArgInfo **out_args, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + if (name != NULL) info->name = g_strdup (name); if (in_num_args != 0) { - info->in_num_args = in_num_args; + //info->in_num_args = in_num_args; info->in_args = in_args; } - g_free ((gpointer) info->in_signature); + g_free (info->in_signature); info->in_signature = compute_signature (in_args, in_num_args); if (out_num_args != 0) { - info->out_num_args = out_num_args; + //info->out_num_args = out_num_args; info->out_args = out_args; } - g_free ((gpointer) info->out_signature); + g_free (info->out_signature); info->out_signature = compute_signature (out_args, out_num_args); if (annotations != NULL) @@ -312,22 +490,24 @@ g_dbus_method_info_set (ParseData *data, } static void -g_dbus_signal_info_set (ParseData *data, - GDBusSignalInfo *info, - const gchar *name, - guint num_args, - GDBusArgInfo *args, - GDBusAnnotationInfo *annotations) +g_dbus_signal_info_set (ParseData *data, + GDBusSignalInfo *info, + const gchar *name, + guint num_args, + GDBusArgInfo **args, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + if (name != NULL) info->name = g_strdup (name); if (num_args != 0) { - info->num_args = num_args; + //info->num_args = num_args; info->args = args; } - g_free ((gpointer) info->signature); + g_free (info->signature); info->signature = compute_signature (args, num_args); if (annotations != NULL) @@ -337,13 +517,15 @@ g_dbus_signal_info_set (ParseData *data, } static void -g_dbus_property_info_set (ParseData *data, - GDBusPropertyInfo *info, - const gchar *name, - const gchar *signature, - GDBusPropertyInfoFlags flags, - GDBusAnnotationInfo *annotations) +g_dbus_property_info_set (ParseData *data, + GDBusPropertyInfo *info, + const gchar *name, + const gchar *signature, + GDBusPropertyInfoFlags flags, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + if (name != NULL) info->name = g_strdup (name); @@ -362,17 +544,19 @@ g_dbus_property_info_set (ParseData *data, } static void -g_dbus_interface_info_set (ParseData *data, - GDBusInterfaceInfo *info, - const gchar *name, - guint num_methods, - GDBusMethodInfo *methods, - guint num_signals, - GDBusSignalInfo *signals, - guint num_properties, - GDBusPropertyInfo *properties, - GDBusAnnotationInfo *annotations) +g_dbus_interface_info_set (ParseData *data, + GDBusInterfaceInfo *info, + const gchar *name, + guint num_methods, + GDBusMethodInfo **methods, + guint num_signals, + GDBusSignalInfo **signals, + guint num_properties, + GDBusPropertyInfo **properties, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + if (name != NULL) { info->name = g_strdup (name); @@ -380,19 +564,19 @@ g_dbus_interface_info_set (ParseData *data, if (num_methods != 0) { - info->num_methods = num_methods; + //info->num_methods = num_methods; info->methods = methods; } if (num_signals != 0) { - info->num_signals = num_signals; + //info->num_signals = num_signals; info->signals = signals; } if (num_properties != 0) { - info->num_properties = num_properties; + //info->num_properties = num_properties; info->properties = properties; } @@ -403,15 +587,17 @@ g_dbus_interface_info_set (ParseData *data, } static void -g_dbus_node_info_set (ParseData *data, - GDBusNodeInfo *info, - const gchar *path, - guint num_interfaces, - GDBusInterfaceInfo *interfaces, - guint num_nodes, - GDBusNodeInfo *nodes, - GDBusAnnotationInfo *annotations) +g_dbus_node_info_set (ParseData *data, + GDBusNodeInfo *info, + const gchar *path, + guint num_interfaces, + GDBusInterfaceInfo **interfaces, + guint num_nodes, + GDBusNodeInfo **nodes, + GDBusAnnotationInfo **annotations) { + info->ref_count = 1; + if (path != NULL) { info->path = g_strdup (path); @@ -420,13 +606,13 @@ g_dbus_node_info_set (ParseData *data, if (num_interfaces != 0) { - info->num_interfaces = num_interfaces; + //info->num_interfaces = num_interfaces; info->interfaces = interfaces; } if (num_nodes != 0) { - info->num_nodes = num_nodes; + //info->num_nodes = num_nodes; info->nodes = nodes; } @@ -459,8 +645,8 @@ g_dbus_annotation_info_generate_xml (const GDBusAnnotationInfo *info, { g_string_append (string_builder, ">\n"); - for (n = 0; info->annotations != NULL && info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); @@ -496,8 +682,8 @@ g_dbus_arg_info_generate_xml (const GDBusArgInfo *info, { g_string_append (string_builder, ">\n"); - for (n = 0; info->annotations != NULL && info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); @@ -517,7 +703,7 @@ g_dbus_method_info_generate_xml (const GDBusMethodInfo *info, indent, "", info->name); - if (info->annotations == NULL && info->in_num_args == 0 && info->out_num_args == 0) + if (info->annotations == NULL && info->in_args == NULL && info->out_args == NULL) { g_string_append (string_builder, "/>\n"); } @@ -525,19 +711,19 @@ g_dbus_method_info_generate_xml (const GDBusMethodInfo *info, { g_string_append (string_builder, ">\n"); - for (n = 0; info->annotations != NULL && info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); - for (n = 0; n < info->in_num_args; n++) - g_dbus_arg_info_generate_xml (&(info->in_args[n]), + for (n = 0; info->in_args != NULL && info->in_args[n] != NULL; n++) + g_dbus_arg_info_generate_xml (info->in_args[n], indent + 2, "direction=\"in\"", string_builder); - for (n = 0; n < info->out_num_args; n++) - g_dbus_arg_info_generate_xml (&(info->out_args[n]), + for (n = 0; info->out_args != NULL && info->out_args[n] != NULL; n++) + g_dbus_arg_info_generate_xml (info->out_args[n], indent + 2, "direction=\"out\"", string_builder); @@ -557,7 +743,7 @@ g_dbus_signal_info_generate_xml (const GDBusSignalInfo *info, indent, "", info->name); - if (info->annotations == NULL && info->num_args == 0) + if (info->annotations == NULL && info->args == NULL) { g_string_append (string_builder, "/>\n"); } @@ -565,13 +751,13 @@ g_dbus_signal_info_generate_xml (const GDBusSignalInfo *info, { g_string_append (string_builder, ">\n"); - for (n = 0; info->annotations != NULL && info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); - for (n = 0; n < info->num_args; n++) - g_dbus_arg_info_generate_xml (&(info->args[n]), + for (n = 0; info->args != NULL && info->args[n] != NULL; n++) + g_dbus_arg_info_generate_xml (info->args[n], indent + 2, NULL, string_builder); @@ -620,8 +806,8 @@ g_dbus_property_info_generate_xml (const GDBusPropertyInfo *info, { g_string_append (string_builder, ">\n"); - for (n = 0; info->annotations != NULL && info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); @@ -632,11 +818,11 @@ g_dbus_property_info_generate_xml (const GDBusPropertyInfo *info, /** * g_dbus_interface_info_generate_xml: - * @interface_info: A #GDBusNodeInfo + * @info: A #GDBusNodeInfo * @indent: Indentation level. * @string_builder: A #GString to to append XML data to. * - * Appends an XML representation of @interface_info (and its children) to @string_builder. + * Appends an XML representation of @info (and its children) to @string_builder. * * This function is typically used for generating introspection XML * documents at run-time for handling the @@ -644,7 +830,7 @@ g_dbus_property_info_generate_xml (const GDBusPropertyInfo *info, * method. */ void -g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *interface_info, +g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *info, guint indent, GString *string_builder) { @@ -652,25 +838,25 @@ g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *interface_info, g_string_append_printf (string_builder, "%*s<interface name=\"%s\">\n", indent, "", - interface_info->name); + info->name); - for (n = 0; interface_info->annotations != NULL && interface_info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(interface_info->annotations[n]), + for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (info->annotations[n], indent + 2, string_builder); - for (n = 0; n < interface_info->num_methods; n++) - g_dbus_method_info_generate_xml (&(interface_info->methods[n]), + for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++) + g_dbus_method_info_generate_xml (info->methods[n], indent + 2, string_builder); - for (n = 0; n < interface_info->num_signals; n++) - g_dbus_signal_info_generate_xml (&(interface_info->signals[n]), + for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++) + g_dbus_signal_info_generate_xml (info->signals[n], indent + 2, string_builder); - for (n = 0; n < interface_info->num_properties; n++) - g_dbus_property_info_generate_xml (&(interface_info->properties[n]), + for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++) + g_dbus_property_info_generate_xml (info->properties[n], indent + 2, string_builder); @@ -699,7 +885,7 @@ g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info, if (node_info->path != NULL) g_string_append_printf (string_builder, " name=\"%s\"", node_info->path); - if (node_info->num_interfaces == 0 && node_info->num_nodes == 0 && node_info->annotations == NULL) + if (node_info->interfaces == NULL && node_info->nodes == NULL && node_info->annotations == NULL) { g_string_append (string_builder, "/>\n"); } @@ -707,18 +893,18 @@ g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info, { g_string_append (string_builder, ">\n"); - for (n = 0; node_info->annotations != NULL && node_info->annotations[n].key != NULL; n++) - g_dbus_annotation_info_generate_xml (&(node_info->annotations[n]), + for (n = 0; node_info->annotations != NULL && node_info->annotations[n] != NULL; n++) + g_dbus_annotation_info_generate_xml (node_info->annotations[n], indent + 2, string_builder); - for (n = 0; n < node_info->num_interfaces; n++) - g_dbus_interface_info_generate_xml (&(node_info->interfaces[n]), + for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++) + g_dbus_interface_info_generate_xml (node_info->interfaces[n], indent + 2, string_builder); - for (n = 0; n < node_info->num_nodes; n++) - g_dbus_node_info_generate_xml (&(node_info->nodes[n]), + for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++) + g_dbus_node_info_generate_xml (node_info->nodes[n], indent + 2, string_builder); @@ -728,115 +914,139 @@ g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info, /* ---------------------------------------------------------------------------------------------------- */ -static GDBusAnnotationInfo * +static GDBusAnnotationInfo ** parse_data_steal_annotations (ParseData *data, guint *out_num_elements) { - GDBusAnnotationInfo *ret; + GDBusAnnotationInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->annotations->len; if (data->annotations == NULL) ret = NULL; else - ret = (GDBusAnnotationInfo *) g_array_free (data->annotations, FALSE); - data->annotations = g_array_new (FALSE, TRUE, sizeof (GDBusAnnotationInfo)); + { + g_ptr_array_add (data->annotations, NULL); + ret = (GDBusAnnotationInfo **) g_ptr_array_free (data->annotations, FALSE); + } + data->annotations = g_ptr_array_new (); return ret; } -static GDBusArgInfo * +static GDBusArgInfo ** parse_data_steal_args (ParseData *data, guint *out_num_elements) { - GDBusArgInfo *ret; + GDBusArgInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->args->len; if (data->args == NULL) ret = NULL; else - ret = (GDBusArgInfo *) g_array_free (data->args, FALSE); - data->args = g_array_new (FALSE, TRUE, sizeof (GDBusArgInfo)); + { + g_ptr_array_add (data->args, NULL); + ret = (GDBusArgInfo **) g_ptr_array_free (data->args, FALSE); + } + data->args = g_ptr_array_new (); return ret; } -static GDBusArgInfo * +static GDBusArgInfo ** parse_data_steal_out_args (ParseData *data, guint *out_num_elements) { - GDBusArgInfo *ret; + GDBusArgInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->out_args->len; if (data->out_args == NULL) ret = NULL; else - ret = (GDBusArgInfo *) g_array_free (data->out_args, FALSE); - data->out_args = g_array_new (FALSE, TRUE, sizeof (GDBusArgInfo)); + { + g_ptr_array_add (data->out_args, NULL); + ret = (GDBusArgInfo **) g_ptr_array_free (data->out_args, FALSE); + } + data->out_args = g_ptr_array_new (); return ret; } -static GDBusMethodInfo * +static GDBusMethodInfo ** parse_data_steal_methods (ParseData *data, guint *out_num_elements) { - GDBusMethodInfo *ret; + GDBusMethodInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->methods->len; if (data->methods == NULL) ret = NULL; else - ret = (GDBusMethodInfo *) g_array_free (data->methods, FALSE); - data->methods = g_array_new (FALSE, TRUE, sizeof (GDBusMethodInfo)); + { + g_ptr_array_add (data->methods, NULL); + ret = (GDBusMethodInfo **) g_ptr_array_free (data->methods, FALSE); + } + data->methods = g_ptr_array_new (); return ret; } -static GDBusSignalInfo * +static GDBusSignalInfo ** parse_data_steal_signals (ParseData *data, guint *out_num_elements) { - GDBusSignalInfo *ret; + GDBusSignalInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->signals->len; if (data->signals == NULL) ret = NULL; else - ret = (GDBusSignalInfo *) g_array_free (data->signals, FALSE); - data->signals = g_array_new (FALSE, TRUE, sizeof (GDBusSignalInfo)); + { + g_ptr_array_add (data->signals, NULL); + ret = (GDBusSignalInfo **) g_ptr_array_free (data->signals, FALSE); + } + data->signals = g_ptr_array_new (); return ret; } -static GDBusPropertyInfo * +static GDBusPropertyInfo ** parse_data_steal_properties (ParseData *data, guint *out_num_elements) { - GDBusPropertyInfo *ret; + GDBusPropertyInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->properties->len; if (data->properties == NULL) ret = NULL; else - ret = (GDBusPropertyInfo *) g_array_free (data->properties, FALSE); - data->properties = g_array_new (FALSE, TRUE, sizeof (GDBusPropertyInfo)); + { + g_ptr_array_add (data->properties, NULL); + ret = (GDBusPropertyInfo **) g_ptr_array_free (data->properties, FALSE); + } + data->properties = g_ptr_array_new (); return ret; } -static GDBusInterfaceInfo * +static GDBusInterfaceInfo ** parse_data_steal_interfaces (ParseData *data, guint *out_num_elements) { - GDBusInterfaceInfo *ret; + GDBusInterfaceInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->interfaces->len; if (data->interfaces == NULL) ret = NULL; else - ret = (GDBusInterfaceInfo *) g_array_free (data->interfaces, FALSE); - data->interfaces = g_array_new (FALSE, TRUE, sizeof (GDBusInterfaceInfo)); + { + g_ptr_array_add (data->interfaces, NULL); + ret = (GDBusInterfaceInfo **) g_ptr_array_free (data->interfaces, FALSE); + } + data->interfaces = g_ptr_array_new (); return ret; } -static GDBusNodeInfo * +static GDBusNodeInfo ** parse_data_steal_nodes (ParseData *data, guint *out_num_elements) { - GDBusNodeInfo *ret; + GDBusNodeInfo **ret; if (out_num_elements != NULL) *out_num_elements = data->nodes->len; if (data->nodes == NULL) ret = NULL; else - ret = (GDBusNodeInfo *) g_array_free (data->nodes, FALSE); - data->nodes = g_array_new (FALSE, TRUE, sizeof (GDBusNodeInfo)); + { + g_ptr_array_add (data->nodes, NULL); + ret = (GDBusNodeInfo **) g_ptr_array_free (data->nodes, FALSE); + } + data->nodes = g_ptr_array_new (); return ret; } @@ -845,96 +1055,80 @@ parse_data_steal_nodes (ParseData *data, guint *out_num_elements) static void parse_data_free_annotations (ParseData *data) { - guint n; if (data->annotations == NULL) return; - for (n = 0; n < data->annotations->len; n++) - g_dbus_annotation_info_free (&g_array_index (data->annotations, GDBusAnnotationInfo, n)); - g_array_free (data->annotations, TRUE); + g_ptr_array_foreach (data->annotations, (GFunc) g_dbus_annotation_info_unref, NULL); + g_ptr_array_free (data->annotations, TRUE); data->annotations = NULL; } static void parse_data_free_args (ParseData *data) { - guint n; if (data->args == NULL) return; - for (n = 0; n < data->args->len; n++) - g_dbus_arg_info_free (&g_array_index (data->args, GDBusArgInfo, n)); - g_array_free (data->args, TRUE); + g_ptr_array_foreach (data->args, (GFunc) g_dbus_arg_info_unref, NULL); + g_ptr_array_free (data->args, TRUE); data->args = NULL; } static void parse_data_free_out_args (ParseData *data) { - guint n; if (data->out_args == NULL) return; - for (n = 0; n < data->out_args->len; n++) - g_dbus_arg_info_free (&g_array_index (data->out_args, GDBusArgInfo, n)); - g_array_free (data->out_args, TRUE); + g_ptr_array_foreach (data->out_args, (GFunc) g_dbus_arg_info_unref, NULL); + g_ptr_array_free (data->out_args, TRUE); data->out_args = NULL; } static void parse_data_free_methods (ParseData *data) { - guint n; if (data->methods == NULL) return; - for (n = 0; n < data->methods->len; n++) - g_dbus_method_info_free (&g_array_index (data->methods, GDBusMethodInfo, n)); - g_array_free (data->methods, TRUE); + g_ptr_array_foreach (data->methods, (GFunc) g_dbus_method_info_unref, NULL); + g_ptr_array_free (data->methods, TRUE); data->methods = NULL; } static void parse_data_free_signals (ParseData *data) { - guint n; if (data->signals == NULL) return; - for (n = 0; n < data->signals->len; n++) - g_dbus_signal_info_free (&g_array_index (data->signals, GDBusSignalInfo, n)); - g_array_free (data->signals, TRUE); + g_ptr_array_foreach (data->signals, (GFunc) g_dbus_signal_info_unref, NULL); + g_ptr_array_free (data->signals, TRUE); data->signals = NULL; } static void parse_data_free_properties (ParseData *data) { - guint n; if (data->properties == NULL) return; - for (n = 0; n < data->properties->len; n++) - g_dbus_property_info_free (&g_array_index (data->properties, GDBusPropertyInfo, n)); - g_array_free (data->properties, TRUE); + g_ptr_array_foreach (data->properties, (GFunc) g_dbus_property_info_unref, NULL); + g_ptr_array_free (data->properties, TRUE); data->properties = NULL; } static void parse_data_free_interfaces (ParseData *data) { - guint n; if (data->interfaces == NULL) return; - for (n = 0; n < data->interfaces->len; n++) - g_dbus_interface_info_free (&g_array_index (data->interfaces, GDBusInterfaceInfo, n)); - g_array_free (data->interfaces, TRUE); + g_ptr_array_foreach (data->interfaces, (GFunc) g_dbus_interface_info_unref, NULL); + g_ptr_array_free (data->interfaces, TRUE); data->interfaces = NULL; } static void parse_data_free_nodes (ParseData *data) { - guint n; if (data->nodes == NULL) return; - for (n = 0; n < data->nodes->len; n++) - g_dbus_node_info_free (&g_array_index (data->nodes, GDBusNodeInfo, n)); - g_array_free (data->nodes, TRUE); + g_ptr_array_foreach (data->nodes, (GFunc) g_dbus_node_info_unref, NULL); + g_ptr_array_free (data->nodes, TRUE); data->nodes = NULL; } @@ -944,64 +1138,64 @@ static GDBusAnnotationInfo * parse_data_get_annotation (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->annotations, data->annotations->len + 1); - return &g_array_index (data->annotations, GDBusAnnotationInfo, data->annotations->len - 1); + g_ptr_array_add (data->annotations, g_new0 (GDBusAnnotationInfo, 1)); + return data->annotations->pdata[data->annotations->len - 1]; } static GDBusArgInfo * parse_data_get_arg (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->args, data->args->len + 1); - return &g_array_index (data->args, GDBusArgInfo, data->args->len - 1); + g_ptr_array_add (data->args, g_new0 (GDBusArgInfo, 1)); + return data->args->pdata[data->args->len - 1]; } static GDBusArgInfo * parse_data_get_out_arg (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->out_args, data->out_args->len + 1); - return &g_array_index (data->out_args, GDBusArgInfo, data->out_args->len - 1); + g_ptr_array_add (data->out_args, g_new0 (GDBusArgInfo, 1)); + return data->out_args->pdata[data->out_args->len - 1]; } static GDBusMethodInfo * parse_data_get_method (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->methods, data->methods->len + 1); - return &g_array_index (data->methods, GDBusMethodInfo, data->methods->len - 1); + g_ptr_array_add (data->methods, g_new0 (GDBusMethodInfo, 1)); + return data->methods->pdata[data->methods->len - 1]; } static GDBusSignalInfo * parse_data_get_signal (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->signals, data->signals->len + 1); - return &g_array_index (data->signals, GDBusSignalInfo, data->signals->len - 1); + g_ptr_array_add (data->signals, g_new0 (GDBusSignalInfo, 1)); + return data->signals->pdata[data->signals->len - 1]; } static GDBusPropertyInfo * parse_data_get_property (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->properties, data->properties->len + 1); - return &g_array_index (data->properties, GDBusPropertyInfo, data->properties->len - 1); + g_ptr_array_add (data->properties, g_new0 (GDBusPropertyInfo, 1)); + return data->properties->pdata[data->properties->len - 1]; } static GDBusInterfaceInfo * parse_data_get_interface (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->interfaces, data->interfaces->len + 1); - return &g_array_index (data->interfaces, GDBusInterfaceInfo, data->interfaces->len - 1); + g_ptr_array_add (data->interfaces, g_new0 (GDBusInterfaceInfo, 1)); + return data->interfaces->pdata[data->interfaces->len - 1]; } static GDBusNodeInfo * parse_data_get_node (ParseData *data, gboolean create_new) { if (create_new) - g_array_set_size (data->nodes, data->nodes->len + 1); - return &g_array_index (data->nodes, GDBusNodeInfo, data->nodes->len - 1); + g_ptr_array_add (data->nodes, g_new0 (GDBusNodeInfo, 1)); + return data->nodes->pdata[data->nodes->len - 1]; } /* ---------------------------------------------------------------------------------------------------- */ @@ -1034,36 +1228,27 @@ parse_data_free (ParseData *data) /* free stack of annotation arrays */ for (l = data->annotations_stack; l != NULL; l = l->next) { - GArray *annotations = l->data; - guint n; - - for (n = 0; n < annotations->len; n++) - g_dbus_annotation_info_free (&g_array_index (annotations, GDBusAnnotationInfo, n)); - g_array_free (annotations, TRUE); + GPtrArray *annotations = l->data; + g_ptr_array_foreach (annotations, (GFunc) g_dbus_annotation_info_unref, NULL); + g_ptr_array_free (annotations, TRUE); } g_slist_free (data->annotations_stack); /* free stack of interface arrays */ for (l = data->interfaces_stack; l != NULL; l = l->next) { - GArray *interfaces = l->data; - guint n; - - for (n = 0; n < interfaces->len; n++) - g_dbus_interface_info_free (&g_array_index (interfaces, GDBusInterfaceInfo, n)); - g_array_free (interfaces, TRUE); + GPtrArray *interfaces = l->data; + g_ptr_array_foreach (interfaces, (GFunc) g_dbus_interface_info_unref, NULL); + g_ptr_array_free (interfaces, TRUE); } g_slist_free (data->interfaces_stack); /* free stack of node arrays */ for (l = data->nodes_stack; l != NULL; l = l->next) { - GArray *nodes = l->data; - guint n; - - for (n = 0; n < nodes->len; n++) - g_dbus_node_info_free (&g_array_index (nodes, GDBusNodeInfo, n)); - g_array_free (nodes, TRUE); + GPtrArray *nodes = l->data; + g_ptr_array_foreach (nodes, (GFunc) g_dbus_node_info_unref, NULL); + g_ptr_array_free (nodes, TRUE); } g_slist_free (data->nodes_stack); @@ -1412,29 +1597,10 @@ parser_start_element (GMarkupParseContext *context, /* ---------------------------------------------------------------------------------------------------- */ -static GDBusAnnotationInfo * +static GDBusAnnotationInfo ** steal_annotations (ParseData *data) { - GDBusAnnotationInfo *annotations; - guint num_annotations; - - if (data->annotations->len == 0) - { - annotations = parse_data_steal_annotations (data, &num_annotations); - g_free (annotations); - annotations = NULL; - } - else - { - /* NULL terminate */ - g_dbus_annotation_info_set (data, - parse_data_get_annotation (data, TRUE), - NULL, - NULL, - NULL); - annotations = parse_data_steal_annotations (data, &num_annotations); - } - return annotations; + return parse_data_steal_annotations (data, NULL); } @@ -1453,8 +1619,8 @@ parser_end_element (GMarkupParseContext *context, { guint num_nodes; guint num_interfaces; - GDBusNodeInfo *nodes; - GDBusInterfaceInfo *interfaces; + GDBusNodeInfo **nodes; + GDBusInterfaceInfo **interfaces; nodes = parse_data_steal_nodes (data, &num_nodes); interfaces = parse_data_steal_interfaces (data, &num_interfaces); @@ -1463,11 +1629,11 @@ parser_end_element (GMarkupParseContext *context, * scope we're reentering */ parse_data_free_interfaces (data); - data->interfaces = (GArray *) data->interfaces_stack->data; + data->interfaces = (GPtrArray *) data->interfaces_stack->data; data->interfaces_stack = g_slist_remove (data->interfaces_stack, data->interfaces_stack->data); parse_data_free_nodes (data); - data->nodes = (GArray *) data->nodes_stack->data; + data->nodes = (GPtrArray *) data->nodes_stack->data; data->nodes_stack = g_slist_remove (data->nodes_stack, data->nodes_stack->data); g_dbus_node_info_set (data, @@ -1485,9 +1651,9 @@ parser_end_element (GMarkupParseContext *context, guint num_methods; guint num_signals; guint num_properties; - GDBusMethodInfo *methods; - GDBusSignalInfo *signals; - GDBusPropertyInfo *properties; + GDBusMethodInfo **methods; + GDBusSignalInfo **signals; + GDBusPropertyInfo **properties; methods = parse_data_steal_methods (data, &num_methods); signals = parse_data_steal_signals (data, &num_signals); @@ -1509,8 +1675,8 @@ parser_end_element (GMarkupParseContext *context, { guint in_num_args; guint out_num_args; - GDBusArgInfo *in_args; - GDBusArgInfo *out_args; + GDBusArgInfo **in_args; + GDBusArgInfo **out_args; in_args = parse_data_steal_args (data, &in_num_args); out_args = parse_data_steal_out_args (data, &out_num_args); @@ -1527,7 +1693,7 @@ parser_end_element (GMarkupParseContext *context, else if (strcmp (element_name, "signal") == 0) { guint num_args; - GDBusArgInfo *args; + GDBusArgInfo **args; args = parse_data_steal_out_args (data, &num_args); @@ -1557,13 +1723,13 @@ parser_end_element (GMarkupParseContext *context, } else if (strcmp (element_name, "annotation") == 0) { - GDBusAnnotationInfo *embedded_annotations; + GDBusAnnotationInfo **embedded_annotations; embedded_annotations = steal_annotations (data); /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */ parse_data_free_annotations (data); - data->annotations = (GArray *) data->annotations_stack->data; + data->annotations = (GPtrArray *) data->annotations_stack->data; data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data); have_popped_annotations = TRUE; @@ -1583,7 +1749,7 @@ parser_end_element (GMarkupParseContext *context, { /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */ parse_data_free_annotations (data); - data->annotations = (GArray *) data->annotations_stack->data; + data->annotations = (GPtrArray *) data->annotations_stack->data; data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data); } } @@ -1615,7 +1781,7 @@ parser_error (GMarkupParseContext *context, * Parses @xml_data and returns a #GDBusNodeInfo representing the data. * * Returns: A #GDBusNodeInfo structure or %NULL if @error is set. Free - * with g_dbus_node_info_free(). + * with g_dbus_node_info_unref(). */ GDBusNodeInfo * g_dbus_node_info_new_for_xml (const gchar *xml_data, @@ -1648,7 +1814,8 @@ g_dbus_node_info_new_for_xml (const gchar *xml_data, error)) goto out; - ret = parse_data_steal_nodes (data, &num_nodes); + GDBusNodeInfo **ughret; + ughret = parse_data_steal_nodes (data, &num_nodes); if (num_nodes != 1) { @@ -1664,12 +1831,15 @@ g_dbus_node_info_new_for_xml (const gchar *xml_data, for (n = 0; n < num_nodes; n++) { for (n = 0; n < num_nodes; n++) - g_dbus_node_info_free (&(ret[n])); + g_dbus_node_info_unref (&(ret[n])); } g_free (ret); ret = NULL; } + ret = ughret[0]; + g_free (ughret); + out: if (parser != NULL) g_free (parser); @@ -1683,7 +1853,7 @@ g_dbus_node_info_new_for_xml (const gchar *xml_data, /** * g_dbus_annotation_info_lookup: - * @annotations: An array of annotations. + * @annotations: A %NULL-terminated array of annotations or %NULL. * @name: The name of the annotation to look up. * * Looks up the value of an annotation. @@ -1691,21 +1861,20 @@ g_dbus_node_info_new_for_xml (const gchar *xml_data, * This cost of this function is O(n) in number of annotations. * * Returns: The value or %NULL if not found. Do not free, it is owned by @annotations. - **/ + */ const gchar * -g_dbus_annotation_info_lookup (const GDBusAnnotationInfo *annotations, - const gchar *name) +g_dbus_annotation_info_lookup (const GDBusAnnotationInfo **annotations, + const gchar *name) { guint n; const gchar *ret; ret = NULL; - - for (n = 0; annotations != NULL && annotations[n].key != NULL; n++) + for (n = 0; annotations != NULL && annotations[n]->key != NULL; n++) { - if (g_strcmp0 (annotations[n].key, name) == 0) + if (g_strcmp0 (annotations[n]->key, name) == 0) { - ret = annotations[n].value; + ret = annotations[n]->value; goto out; } } @@ -1718,25 +1887,25 @@ g_dbus_annotation_info_lookup (const GDBusAnnotationInfo *annotations, /** * g_dbus_interface_info_lookup_method: - * @interface_info: A #GDBusInterfaceInfo. + * @info: A #GDBusInterfaceInfo. * @name: A D-Bus method name (typically in CamelCase) * * Looks up information about a method. * * This cost of this function is O(n) in number of methods. * - * Returns: A #GDBusMethodInfo or %NULL if not found. Do not free, it is owned by @interface_info. + * Returns: A #GDBusMethodInfo or %NULL if not found. Do not free, it is owned by @info. **/ const GDBusMethodInfo * -g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *interface_info, +g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *info, const gchar *name) { guint n; const GDBusMethodInfo *result; - for (n = 0; n < interface_info->num_methods; n++) + for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++) { - const GDBusMethodInfo *i = interface_info->methods + n; + const GDBusMethodInfo *i = info->methods[n]; if (g_strcmp0 (i->name, name) == 0) { @@ -1755,25 +1924,25 @@ g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *interface_info, /** * g_dbus_interface_info_lookup_signal: - * @interface_info: A #GDBusInterfaceInfo. + * @info: A #GDBusInterfaceInfo. * @name: A D-Bus signal name (typically in CamelCase) * * Looks up information about a signal. * * This cost of this function is O(n) in number of signals. * - * Returns: A #GDBusSignalInfo or %NULL if not found. Do not free, it is owned by @interface_info. + * Returns: A #GDBusSignalInfo or %NULL if not found. Do not free, it is owned by @info. **/ const GDBusSignalInfo * -g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *interface_info, +g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *info, const gchar *name) { guint n; const GDBusSignalInfo *result; - for (n = 0; n < interface_info->num_signals; n++) + for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++) { - const GDBusSignalInfo *i = interface_info->signals + n; + const GDBusSignalInfo *i = info->signals[n]; if (g_strcmp0 (i->name, name) == 0) { @@ -1792,25 +1961,25 @@ g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *interface_info, /** * g_dbus_interface_info_lookup_property: - * @interface_info: A #GDBusInterfaceInfo. + * @info: A #GDBusInterfaceInfo. * @name: A D-Bus property name (typically in CamelCase). * * Looks up information about a property. * * This cost of this function is O(n) in number of properties. * - * Returns: A #GDBusPropertyInfo or %NULL if not found. Do not free, it is owned by @interface_info. + * Returns: A #GDBusPropertyInfo or %NULL if not found. Do not free, it is owned by @info. **/ const GDBusPropertyInfo * -g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *interface_info, +g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *info, const gchar *name) { guint n; const GDBusPropertyInfo *result; - for (n = 0; n < interface_info->num_properties; n++) + for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++) { - const GDBusPropertyInfo *i = interface_info->properties + n; + const GDBusPropertyInfo *i = info->properties[n]; if (g_strcmp0 (i->name, name) == 0) { @@ -1845,9 +2014,9 @@ g_dbus_node_info_lookup_interface (const GDBusNodeInfo *node_info, guint n; const GDBusInterfaceInfo *result; - for (n = 0; n < node_info->num_interfaces; n++) + for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++) { - const GDBusInterfaceInfo *i = node_info->interfaces + n; + const GDBusInterfaceInfo *i = node_info->interfaces[n]; if (g_strcmp0 (i->name, name) == 0) { diff --git a/gdbus/gdbusintrospection.h b/gdbus/gdbusintrospection.h index e798a6d..4c35b8a 100644 --- a/gdbus/gdbusintrospection.h +++ b/gdbus/gdbusintrospection.h @@ -33,224 +33,222 @@ G_BEGIN_DECLS /** * GDBusAnnotationInfo: - * @key: The name of the annotation, e.g. <literal>org.freedesktop.DBus.Deprecated</literal> + * @ref_count: The reference count or -1 if statically allocated. + * @key: The name of the annotation, e.g. "org.freedesktop.DBus.Deprecated". * @value: The value of the annotation. - * @annotations: A pointer to an array of annotations for the annotation or %NULL if there are no annotations. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about an annotation. - * - * By convention, an array of annotations is always terminated by an element - * where @key is %NULL. */ struct _GDBusAnnotationInfo { - const gchar *key; - const gchar *value; - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *key; + gchar *value; + GDBusAnnotationInfo **annotations; }; /** * GDBusArgInfo: + * @ref_count: The reference count or -1 if statically allocated. * @name: Name of the argument, e.g. @unix_user_id. * @signature: D-Bus signature of the argument (a single complete type). - * @annotations: A pointer to an array of annotations for the argument or %NULL if there are no annotations. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about an argument for a method or a signal. */ struct _GDBusArgInfo { - const gchar *name; - const gchar *signature; - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *name; + gchar *signature; + GDBusAnnotationInfo **annotations; }; /** * GDBusMethodInfo: + * @ref_count: The reference count or -1 if statically allocated. * @name: The name of the D-Bus method, e.g. @RequestName. - * @in_signature: The combined D-Bus signature of all arguments passed to the method (@in_num_args complete types). - * @in_num_args: Number of arguments passed to the method. - * @in_args: A pointer to an array of @in_num_args #GDBusArgInfo structures or %NULL if @in_num_args is 0. - * @out_signature: The combined D-Bus signature of all arguments the method returns (@out_num_args complete types). - * @out_num_args: Number of arguments the method returns. - * @out_args: A pointer to an array of @out_num_args #GDBusArgInfo structures or %NULL if @out_num_args is 0. - * @annotations: A pointer to an array of annotations for the method or %NULL if there are no annotations. + * @in_signature: The combined D-Bus signature of all arguments passed to the method. + * @in_args: A pointer to a %NULL-terminated array of pointers to #GDBusArgInfo structures or %NULL if there are no in arguments. + * @out_signature: The combined D-Bus signature of all arguments the method returns. + * @out_args: A pointer to a %NULL-terminated array of pointers to #GDBusArgInfo structures or %NULL if there are no out arguments. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about a method on an D-Bus interface. */ struct _GDBusMethodInfo { - const gchar *name; - - const gchar *in_signature; - guint in_num_args; - const GDBusArgInfo *in_args; - - const gchar *out_signature; - guint out_num_args; - const GDBusArgInfo *out_args; - - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *name; + gchar *in_signature; + GDBusArgInfo **in_args; + gchar *out_signature; + GDBusArgInfo **out_args; + GDBusAnnotationInfo **annotations; }; /** * GDBusSignalInfo: - * @name: The name of the D-Bus signal, e.g. @NameOwnerChanged. - * @signature: The combined D-Bus signature of all arguments of the signal (@num_args complete types). - * @num_args: Number of arguments of the signal. - * @args: A pointer to an array of @num_args #GDBusArgInfo structures or %NULL if @num_args is 0. - * @annotations: A pointer to an array of annotations for the signal or %NULL if there are no annotations. + * @ref_count: The reference count or -1 if statically allocated. + * @name: The name of the D-Bus signal, e.g. "NameOwnerChanged". + * @signature: The combined D-Bus signature of all arguments of the signal. + * @args: A pointer to a %NULL-terminated array of pointers to #GDBusArgInfo structures or %NULL if there are no arguments. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about a signal on a D-Bus interface. */ struct _GDBusSignalInfo { - const gchar *name; - - const gchar *signature; - guint num_args; - const GDBusArgInfo *args; - - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *name; + gchar *signature; + GDBusArgInfo **args; + GDBusAnnotationInfo **annotations; }; /** * GDBusPropertyInfo: - * @name: The name of the D-Bus property, e.g. @SupportedFilesystems. + * @ref_count: The reference count or -1 if statically allocated. + * @name: The name of the D-Bus property, e.g. "SupportedFilesystems". * @signature: The D-Bus signature of the property (a single complete type). * @flags: Access control flags for the property. - * @annotations: A pointer to an array of annotations for the property or %NULL if there are no annotations. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about a D-Bus property on a D-Bus interface. */ struct _GDBusPropertyInfo { - const gchar *name; - const gchar *signature; - GDBusPropertyInfoFlags flags; - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *name; + gchar *signature; + GDBusPropertyInfoFlags flags; + GDBusAnnotationInfo **annotations; }; /** * GDBusInterfaceInfo: - * @name: The name of the D-Bus interface, e.g. <literal>org.freedesktop.DBus.Properties</literal>. - * @num_methods: Number of methods on the interface. - * @methods: A pointer to an array of @num_methods #GDBusMethodInfo structures or %NULL if @num_methods is 0. - * @num_signals: Number of signals on the interface. - * @signals: A pointer to an array of @num_signals #GDBusSignalInfo structures or %NULL if @num_signals is 0. - * @num_properties: Number of properties on the interface. - * @properties: A pointer to an array of @num_properties #GDBusPropertyInfo structures or %NULL if @num_properties is 0. - * @annotations: A pointer to an array of annotations for the interface or %NULL if there are no annotations. + * @ref_count: The reference count or -1 if statically allocated. + * @name: The name of the D-Bus interface, e.g. "org.freedesktop.DBus.Properties". + * @methods: A pointer to a %NULL-terminated array of pointers to #GDBusMethodInfo structures or %NULL if there are no methods. + * @signals: A pointer to a %NULL-terminated array of pointers to #GDBusSignalInfo structures or %NULL if there are no signals. + * @properties: A pointer to a %NULL-terminated array of pointers to #GDBusPropertyInfo structures or %NULL if there are no properties. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about a D-Bus interface. */ struct _GDBusInterfaceInfo { - const gchar *name; - - guint num_methods; - const GDBusMethodInfo *methods; - - guint num_signals; - const GDBusSignalInfo *signals; - - guint num_properties; - const GDBusPropertyInfo *properties; - - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *name; + GDBusMethodInfo **methods; + GDBusSignalInfo **signals; + GDBusPropertyInfo **properties; + GDBusAnnotationInfo **annotations; }; /** * GDBusNodeInfo: + * @ref_count: The reference count or -1 if statically allocated. * @path: The path of the node or %NULL if omitted. Note that this may be a relative path. See the D-Bus specification for more details. - * @num_interfaces: Number of interfaces of the node. - * @interfaces: A pointer to an array of @num_interfaces #GDBusInterfaceInfo structures or %NULL if @num_interfaces is 0. - * @num_nodes: Number of child nodes. - * @nodes: A pointer to an array of @num_nodes #GDBusNodeInfo structures or %NULL if @num_nodes is 0. - * @annotations: A pointer to an array of annotations for the node or %NULL if there are no annotations. + * @interfaces: A pointer to a %NULL-terminated array of pointers to #GDBusInterfaceInfo structures or %NULL if there are no interfaces. + * @nodes: A pointer to a %NULL-terminated array of pointers to #GDBusNodeInfo structures or %NULL if there are no nodes. + * @annotations: A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations. * * Information about nodes in a remote object hierarchy. */ struct _GDBusNodeInfo { - const gchar *path; - - guint num_interfaces; - const GDBusInterfaceInfo *interfaces; - - guint num_nodes; - const GDBusNodeInfo *nodes; - - const GDBusAnnotationInfo *annotations; + volatile gint ref_count; + gchar *path; + GDBusInterfaceInfo **interfaces; + GDBusNodeInfo **nodes; + GDBusAnnotationInfo **annotations; }; -const gchar *g_dbus_annotation_info_lookup (const GDBusAnnotationInfo *annotations, +const gchar *g_dbus_annotation_info_lookup (const GDBusAnnotationInfo **annotations, const gchar *name); -const GDBusMethodInfo *g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *interface_info, +const GDBusMethodInfo *g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *info, const gchar *name); -const GDBusSignalInfo *g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *interface_info, +const GDBusSignalInfo *g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *info, const gchar *name); -const GDBusPropertyInfo *g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *interface_info, +const GDBusPropertyInfo *g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *info, const gchar *name); -void g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *interface_info, +void g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *info, guint indent, GString *string_builder); GDBusNodeInfo *g_dbus_node_info_new_for_xml (const gchar *xml_data, GError **error); -const GDBusInterfaceInfo *g_dbus_node_info_lookup_interface (const GDBusNodeInfo *node_info, +const GDBusInterfaceInfo *g_dbus_node_info_lookup_interface (const GDBusNodeInfo *info, const gchar *name); -void g_dbus_node_info_free (GDBusNodeInfo *node_info); -void g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info, +void g_dbus_node_info_generate_xml (const GDBusNodeInfo *info, guint indent, GString *string_builder); +GDBusNodeInfo *g_dbus_node_info_ref (GDBusNodeInfo *info); +GDBusInterfaceInfo *g_dbus_interface_info_ref (GDBusInterfaceInfo *info); +GDBusMethodInfo *g_dbus_method_info_ref (GDBusMethodInfo *info); +GDBusSignalInfo *g_dbus_signal_info_ref (GDBusSignalInfo *info); +GDBusPropertyInfo *g_dbus_property_info_ref (GDBusPropertyInfo *info); +GDBusArgInfo *g_dbus_arg_info_ref (GDBusArgInfo *info); +GDBusAnnotationInfo *g_dbus_annotation_info_ref (GDBusAnnotationInfo *info); + +void g_dbus_node_info_unref (GDBusNodeInfo *info); +void g_dbus_interface_info_unref (GDBusInterfaceInfo *info); +void g_dbus_method_info_unref (GDBusMethodInfo *info); +void g_dbus_signal_info_unref (GDBusSignalInfo *info); +void g_dbus_property_info_unref (GDBusPropertyInfo *info); +void g_dbus_arg_info_unref (GDBusArgInfo *info); +void g_dbus_annotation_info_unref (GDBusAnnotationInfo *info); + /** * G_TYPE_DBUS_NODE_INFO: * - * The #GType for a boxed type holding a const #GDBusNodeInfo. + * The #GType for a boxed type holding a #GDBusNodeInfo. */ #define G_TYPE_DBUS_NODE_INFO (g_dbus_node_info_get_type ()) /** * G_TYPE_DBUS_INTERFACE_INFO: * - * The #GType for a boxed type holding a const #GDBusInterfaceInfo. + * The #GType for a boxed type holding a #GDBusInterfaceInfo. */ #define G_TYPE_DBUS_INTERFACE_INFO (g_dbus_interface_info_get_type ()) /** * G_TYPE_DBUS_METHOD_INFO: * - * The #GType for a boxed type holding a const #GDBusMethodInfo. + * The #GType for a boxed type holding a #GDBusMethodInfo. */ #define G_TYPE_DBUS_METHOD_INFO (g_dbus_method_info_get_type ()) /** * G_TYPE_DBUS_SIGNAL_INFO: * - * The #GType for a boxed type holding a const #GDBusSignalInfo. + * The #GType for a boxed type holding a #GDBusSignalInfo. */ #define G_TYPE_DBUS_SIGNAL_INFO (g_dbus_signal_info_get_type ()) /** * G_TYPE_DBUS_PROPERTY_INFO: * - * The #GType for a boxed type holding a const #GDBusPropertyInfo. + * The #GType for a boxed type holding a #GDBusPropertyInfo. */ #define G_TYPE_DBUS_PROPERTY_INFO (g_dbus_property_info_get_type ()) /** * G_TYPE_DBUS_ARG_INFO: * - * The #GType for a boxed type holding a const #GDBusArgInfo. + * The #GType for a boxed type holding a #GDBusArgInfo. */ #define G_TYPE_DBUS_ARG_INFO (g_dbus_arg_info_get_type ()) /** * G_TYPE_DBUS_ANNOTATION_INFO: * - * The #GType for a boxed type holding a const #GDBusAnnotationInfo. + * The #GType for a boxed type holding a #GDBusAnnotationInfo. */ #define G_TYPE_DBUS_ANNOTATION_INFO (g_dbus_annotation_info_get_type ()) diff --git a/gdbus/gdbusproxy.c b/gdbus/gdbusproxy.c index ecff9b1..58e77bf 100644 --- a/gdbus/gdbusproxy.c +++ b/gdbus/gdbusproxy.c @@ -58,7 +58,7 @@ struct _GDBusProxyPrivate /* gchar* -> GVariant* */ GHashTable *properties; - const GDBusInterfaceInfo *expected_interface; + GDBusInterfaceInfo *expected_interface; guint properties_changed_subscriber_id; guint signals_subscriber_id; @@ -119,6 +119,9 @@ g_dbus_proxy_finalize (GObject *object) if (proxy->priv->properties != NULL) g_hash_table_unref (proxy->priv->properties); + if (proxy->priv->expected_interface != NULL) + g_dbus_interface_info_unref (proxy->priv->expected_interface); + if (G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize != NULL) G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object); } @@ -232,9 +235,6 @@ g_dbus_proxy_class_init (GDBusProxyClass *klass) * type signature of the message isn't what's expected, the given * #GError is set. Signals that have a type signature mismatch are * simply dropped. - * - * Note that data set in this property must not be invalidated or - * changed - it is expected to live in static storage. */ g_object_class_install_property (gobject_class, PROP_G_INTERFACE_INFO, @@ -903,7 +903,7 @@ void g_dbus_proxy_new (GDBusConnection *connection, GType object_type, GDBusProxyFlags flags, - const GDBusInterfaceInfo *info, + GDBusInterfaceInfo *info, const gchar *unique_bus_name, const gchar *object_path, const gchar *interface_name, @@ -994,7 +994,7 @@ GDBusProxy * g_dbus_proxy_new_sync (GDBusConnection *connection, GType object_type, GDBusProxyFlags flags, - const GDBusInterfaceInfo *info, + GDBusInterfaceInfo *info, const gchar *unique_bus_name, const gchar *object_path, const gchar *interface_name, @@ -1157,9 +1157,10 @@ g_dbus_proxy_set_default_timeout (GDBusProxy *proxy, * * See the #GDBusProxy:g-interface-info property for more details. * - * Returns: A #GDBusInterfaceInfo or %NULL. + * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned + * object, it is owned by @proxy. */ -const GDBusInterfaceInfo * +GDBusInterfaceInfo * g_dbus_proxy_get_interface_info (GDBusProxy *proxy) { g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL); @@ -1169,7 +1170,7 @@ g_dbus_proxy_get_interface_info (GDBusProxy *proxy) /** * g_dbus_proxy_set_interface_info: * @proxy: A #GDBusProxy - * @info: Minimum interface this proxy conforms to + * @info: Minimum interface this proxy conforms to or %NULL to unset. * * Ensure that interactions with @proxy conform to the given * interface. For example, when completing a method call, if the type @@ -1177,18 +1178,16 @@ g_dbus_proxy_get_interface_info (GDBusProxy *proxy) * is set. Signals that have a type signature mismatch are simply * dropped. * - * Note that while this function takes a constant @info, it's expected - * to live in static storage, so must not be invalidated or changed - * after having been passed to this function. - * * See the #GDBusProxy:g-interface-info property for more details. */ void -g_dbus_proxy_set_interface_info (GDBusProxy *proxy, - const GDBusInterfaceInfo *info) +g_dbus_proxy_set_interface_info (GDBusProxy *proxy, + GDBusInterfaceInfo *info) { g_return_if_fail (G_IS_DBUS_PROXY (proxy)); - proxy->priv->expected_interface = info; + if (proxy->priv->expected_interface != NULL) + g_dbus_interface_info_unref (proxy->priv->expected_interface); + proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL; } /* ---------------------------------------------------------------------------------------------------- */ diff --git a/gdbus/gdbusproxy.h b/gdbus/gdbusproxy.h index b68e7f8..cedd140 100644 --- a/gdbus/gdbusproxy.h +++ b/gdbus/gdbusproxy.h @@ -92,7 +92,7 @@ GType g_dbus_proxy_get_type (void) G_GNUC_CONST; void g_dbus_proxy_new (GDBusConnection *connection, GType object_type, GDBusProxyFlags flags, - const GDBusInterfaceInfo *info, + GDBusInterfaceInfo *info, const gchar *unique_bus_name, const gchar *object_path, const gchar *interface_name, @@ -104,7 +104,7 @@ GDBusProxy *g_dbus_proxy_new_finish (GAsyncResult *re GDBusProxy *g_dbus_proxy_new_sync (GDBusConnection *connection, GType object_type, GDBusProxyFlags flags, - const GDBusInterfaceInfo *info, + GDBusInterfaceInfo *info, const gchar *unique_bus_name, const gchar *object_path, const gchar *interface_name, @@ -118,9 +118,9 @@ const gchar *g_dbus_proxy_get_interface_name (GDBusProxy *pr gint g_dbus_proxy_get_default_timeout (GDBusProxy *proxy); void g_dbus_proxy_set_default_timeout (GDBusProxy *proxy, gint timeout_msec); -const GDBusInterfaceInfo *g_dbus_proxy_get_interface_info (GDBusProxy *proxy); -void g_dbus_proxy_set_interface_info (GDBusProxy *proxy, - const GDBusInterfaceInfo *info); +GDBusInterfaceInfo *g_dbus_proxy_get_interface_info (GDBusProxy *proxy); +void g_dbus_proxy_set_interface_info (GDBusProxy *proxy, + GDBusInterfaceInfo *info); GVariant *g_dbus_proxy_get_cached_property (GDBusProxy *proxy, const gchar *property_name, GError **error); diff --git a/gdbus/tests/export.c b/gdbus/tests/export.c index e93a610..d98a57e 100644 --- a/gdbus/tests/export.c +++ b/gdbus/tests/export.c @@ -35,80 +35,90 @@ static GDBusConnection *c = NULL; /* Test that we can export objects, the hierarchy is correct and the right handlers are invoked */ /* ---------------------------------------------------------------------------------------------------- */ -static const GDBusArgInfo foo_method1_in_args[] = +static const GDBusArgInfo foo_method1_in_args = { - { - "an_input_string", - "s", - NULL - } + -1, + "an_input_string", + "s", + NULL }; +static const GDBusArgInfo *foo_method1_in_arg_pointers[] = {&foo_method1_in_args, NULL}; -static const GDBusArgInfo foo_method1_out_args[] = +static const GDBusArgInfo foo_method1_out_args = { - { - "an_output_string", - "s", - NULL - } + -1, + "an_output_string", + "s", + NULL }; +static const GDBusArgInfo *foo_method1_out_arg_pointers[] = {&foo_method1_out_args, NULL}; -static const GDBusMethodInfo foo_method_info[] = +static const GDBusMethodInfo foo_method_info_method1 = { - { - "Method1", - "s", 1, foo_method1_in_args, - "s", 1, foo_method1_out_args, - NULL - }, - { - "Method2", - "", 0, NULL, - "", 0, NULL, - NULL - } + -1, + "Method1", + "s", (GDBusArgInfo **) &foo_method1_in_arg_pointers, + "s", (GDBusArgInfo **) &foo_method1_out_arg_pointers, + NULL }; +static const GDBusMethodInfo foo_method_info_method2 = +{ + -1, + "Method2", + "", NULL, + "", NULL, + NULL +}; +static const GDBusMethodInfo *foo_method_info_pointers[] = {&foo_method_info_method1, &foo_method_info_method2, NULL}; -static const GDBusSignalInfo foo_signal_info[] = +static const GDBusSignalInfo foo_signal_info = { - { - "SignalAlpha", - "", 0, NULL, - NULL - } + -1, + "SignalAlpha", + "", NULL, + NULL }; +static const GDBusSignalInfo *foo_signal_info_pointers[] = {&foo_signal_info, NULL}; static const GDBusPropertyInfo foo_property_info[] = { { + -1, "PropertyUno", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL }, { + -1, "NotWritable", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE, NULL }, { + -1, "NotReadable", "s", G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL } }; +static const GDBusPropertyInfo *foo_property_info_pointers[] = +{ + &foo_property_info[0], + &foo_property_info[1], + &foo_property_info[2], + NULL +}; static const GDBusInterfaceInfo foo_interface_info = { + -1, "org.example.Foo", - 2, - foo_method_info, - 1, - foo_signal_info, - 3, - foo_property_info, + (GDBusMethodInfo **) &foo_method_info_pointers, + (GDBusSignalInfo **) &foo_signal_info_pointers, + (GDBusPropertyInfo **)&foo_property_info_pointers, NULL, }; @@ -189,47 +199,52 @@ static GDBusInterfaceVTable foo_vtable = static const GDBusMethodInfo bar_method_info[] = { { + -1, "MethodA", - "", 0, NULL, - "", 0, NULL, + "", NULL, + "", NULL, NULL }, { + -1, "MethodB", - "", 0, NULL, - "", 0, NULL, + "", NULL, + "", NULL, NULL } }; +static const GDBusMethodInfo *bar_method_info_pointers[] = {&bar_method_info[0], &bar_method_info[1], NULL}; static const GDBusSignalInfo bar_signal_info[] = { { + -1, "SignalMars", - "", 0, NULL, + "", NULL, NULL } }; +static const GDBusSignalInfo *bar_signal_info_pointers[] = {&bar_signal_info[0], NULL}; static const GDBusPropertyInfo bar_property_info[] = { { + -1, "PropertyDuo", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE, NULL } }; +static const GDBusPropertyInfo *bar_property_info_pointers[] = {&bar_property_info[0], NULL}; static const GDBusInterfaceInfo bar_interface_info = { + -1, "org.example.Bar", - 2, - bar_method_info, - 1, - bar_signal_info, - 1, - bar_property_info, + (GDBusMethodInfo **) bar_method_info_pointers, + (GDBusSignalInfo **) bar_signal_info_pointers, + (GDBusPropertyInfo **) bar_property_info_pointers, NULL, }; @@ -238,22 +253,22 @@ static const GDBusInterfaceInfo bar_interface_info = static const GDBusMethodInfo dyna_method_info[] = { { + -1, "DynaCyber", - "", 0, NULL, - "", 0, NULL, + "", NULL, + "", NULL, NULL } }; +static const GDBusMethodInfo *dyna_method_info_pointers[] = {&dyna_method_info[0], NULL}; static const GDBusInterfaceInfo dyna_interface_info = { + -1, "org.example.Dyna", - 1, /* 1 method*/ - dyna_method_info, - 0, /* 0 signals */ - NULL, - 0, /* 0 properties */ - NULL, + (GDBusMethodInfo **) dyna_method_info_pointers, + NULL, /* no signals */ + NULL, /* no properties */ NULL, }; @@ -360,16 +375,16 @@ get_nodes_at (GDBusConnection *c, g_assert (node_info != NULL); p = g_ptr_array_new (); - for (n = 0; n < node_info->num_nodes; n++) + for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++) { - const GDBusNodeInfo *sub_node_info = node_info->nodes + n; + const GDBusNodeInfo *sub_node_info = node_info->nodes[n]; g_ptr_array_add (p, g_strdup (sub_node_info->path)); } g_ptr_array_add (p, NULL); g_object_unref (proxy); g_free (xml_data); - g_dbus_node_info_free (node_info); + g_dbus_node_info_unref (node_info); return (gchar **) g_ptr_array_free (p, FALSE); } @@ -420,7 +435,7 @@ has_interface (GDBusConnection *c, g_object_unref (proxy); g_free (xml_data); - g_dbus_node_info_free (node_info); + g_dbus_node_info_unref (node_info); return ret; } @@ -466,11 +481,13 @@ count_interfaces (GDBusConnection *c, g_assert_no_error (error); g_assert (node_info != NULL); - ret = node_info->num_interfaces; + ret = 0; + while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL) + ret++; g_object_unref (proxy); g_free (xml_data); - g_dbus_node_info_free (node_info); + g_dbus_node_info_unref (node_info); return ret; } diff --git a/gdbus/tests/introspection.c b/gdbus/tests/introspection.c index b16bb1b..77bd566 100644 --- a/gdbus/tests/introspection.c +++ b/gdbus/tests/introspection.c @@ -80,13 +80,12 @@ introspection_on_proxy_appeared (GDBusConnection *connection, method_info = g_dbus_interface_info_lookup_method (interface_info, "Introspect"); g_assert (method_info != NULL); g_assert_cmpstr (method_info->in_signature, ==, ""); - g_assert_cmpint (method_info->in_num_args, ==, 0); g_assert (method_info->in_args == NULL); g_assert_cmpstr (method_info->out_signature, ==, "s"); - g_assert_cmpint (method_info->out_num_args, ==, 1); g_assert (method_info->out_args != NULL); - g_assert (method_info->out_args[0].name != NULL); - g_assert_cmpstr (method_info->out_args[0].signature, ==, "s"); + g_assert (method_info->out_args[0] != NULL); + g_assert (method_info->out_args[1] == NULL); + g_assert_cmpstr (method_info->out_args[0]->signature, ==, "s"); interface_info = g_dbus_node_info_lookup_interface (node_info, "com.example.Frob"); g_assert (interface_info != NULL); @@ -94,7 +93,7 @@ introspection_on_proxy_appeared (GDBusConnection *connection, g_assert (signal_info != NULL); g_assert_cmpstr (signal_info->signature, ==, "sov"); - g_dbus_node_info_free (node_info); + g_dbus_node_info_unref (node_info); g_variant_unref (result); g_main_loop_quit (loop); diff --git a/gdbus/tests/peer.c b/gdbus/tests/peer.c index 084d809..d8ddfb1 100644 --- a/gdbus/tests/peer.c +++ b/gdbus/tests/peer.c @@ -59,74 +59,24 @@ typedef struct gboolean signal_received; } PeerData; -static const GDBusArgInfo test_interface_hello_peer_method_in_args[] = -{ - {"greeting", "s", NULL} -}; - -static const GDBusArgInfo test_interface_hello_peer_method_out_args[] = -{ - {"response", "s", NULL} -}; - -static const GDBusArgInfo test_interface_open_file_method_in_args[] = -{ - {"path", "s", NULL} -}; - -static const GDBusMethodInfo test_interface_method_info[] = -{ - { - "HelloPeer", - "s", 1, test_interface_hello_peer_method_in_args, - "s", 1, test_interface_hello_peer_method_out_args, - NULL - }, - { - "EmitSignal", - "", 0, NULL, - "", 0, NULL, - NULL - }, - { - "OpenFile", - "s", 1, test_interface_open_file_method_in_args, - "", 0, NULL, - NULL - } -}; - -static const GDBusArgInfo test_interface_peer_signal_args[] = -{ - {"a_string", "s", NULL} -}; - -static const GDBusSignalInfo test_interface_signal_info[] = -{ - { - "PeerSignal", - "s", 1, test_interface_peer_signal_args, - NULL - } -}; - -static const GDBusPropertyInfo test_interface_property_info[] = -{ - { - "PeerProperty", - "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE, - NULL - } -}; - -static const GDBusInterfaceInfo test_interface_introspection_data = -{ - "org.gtk.GDBus.PeerTestInterface", - 3, test_interface_method_info, - 1, test_interface_signal_info, - 1, test_interface_property_info, - NULL, -}; +static const gchar *test_interface_introspection_xml = + "<node>" + " <interface name='org.gtk.GDBus.PeerTestInterface'>" + " <method name='HelloPeer'>" + " <arg type='s' name='greeting' direction='in'/>" + " <arg type='s' name='response' direction='out'/>" + " </method>" + " <method name='EmitSignal'/>" + " <method name='OpenFile'>" + " <arg type='s' name='path' direction='in'/>" + " </method>" + " <signal name='PeerSignal'>" + " <arg type='s' name='a_string'/>" + " </signal>" + " <property type='s' name='PeerProperty' access='read'/>" + " </interface>" + "</node>"; +static const GDBusInterfaceInfo *test_interface_introspection_data = NULL; static void test_interface_method_call (GDBusConnection *connection, @@ -294,7 +244,7 @@ on_new_connection (GDBusServer *server, reg_id = g_dbus_connection_register_object (connection, "/org/gtk/GDBus/PeerTestObject", "org.gtk.GDBus.PeerTestInterface", - &test_interface_introspection_data, + test_interface_introspection_data, &test_interface_vtable, data, NULL, /* GDestroyNotify for data */ @@ -769,11 +719,16 @@ main (int argc, char *argv[]) { gint ret; + GDBusNodeInfo *introspection_data = NULL; g_type_init (); g_thread_init (NULL); g_test_init (&argc, &argv, NULL); + introspection_data = g_dbus_node_info_new_for_xml (test_interface_introspection_xml, NULL); + g_assert (introspection_data != NULL); + test_interface_introspection_data = introspection_data->interfaces[0]; + test_guid = g_dbus_generate_guid (); /* all the tests rely on a shared main loop */ @@ -785,6 +740,7 @@ main (int argc, g_main_loop_unref (loop); g_free (test_guid); + g_dbus_node_info_unref (introspection_data); return ret; } diff --git a/gdbus/tests/proxy.c b/gdbus/tests/proxy.c index c516358..6991ca0 100644 --- a/gdbus/tests/proxy.c +++ b/gdbus/tests/proxy.c @@ -337,74 +337,24 @@ test_bogus_method_return (GDBusConnection *connection, /* ---------------------------------------------------------------------------------------------------- */ - -static const GDBusArgInfo frob_dbus_pair_return_out_args[] = -{ +static const gchar *frob_dbus_interface_xml = + "<node>" + " <interface name='com.example.Frob'>" /* Deliberately different from testserver.py's definition */ - { - "somenumber", - "u", - NULL - }, - { - "somestring", - "s", - NULL - } -}; - -static const GDBusArgInfo frob_dbus_hello_world_args[] = -{ - { - "somestring", - "s", - NULL - } -}; - -static const GDBusArgInfo frob_dbus_sleep_in_args[] = -{ - { - "timeout", - "i", - NULL - } -}; - -static const GDBusMethodInfo frob_dbus_method_info[] = -{ - { - "PairReturn", - "", 0, NULL, - /* Deliberately different from testserver.py's definition */ - "us", 2, frob_dbus_pair_return_out_args, - NULL - }, - { - "HelloWorld", - "s", 1, frob_dbus_hello_world_args, - "s", 1, frob_dbus_hello_world_args, - NULL - }, - { - "Sleep", - "i", 1, frob_dbus_sleep_in_args, - "", 0, NULL, - NULL - } -}; - -static const GDBusInterfaceInfo frob_dbus_interface_info = -{ - "com.example.Frob", - 3, - frob_dbus_method_info, - 0, - NULL, - 0, - NULL, - NULL, -}; + " <method name='PairReturn'>" + " <arg type='u' name='somenumber' direction='in'/>" + " <arg type='s' name='somestring' direction='out'/>" + " </method>" + " <method name='HelloWorld'>" + " <arg type='s' name='somestring' direction='in'/>" + " <arg type='s' name='somestring' direction='out'/>" + " </method>" + " <method name='Sleep'>" + " <arg type='i' name='timeout' direction='in'/>" + " </method>" + " </interface>" + "</node>"; +static GDBusInterfaceInfo *frob_dbus_interface_info; static void on_proxy_appeared (GDBusConnection *connection, @@ -418,7 +368,7 @@ on_proxy_appeared (GDBusConnection *connection, test_signals (connection, name, name_owner, proxy); /* Now repeat the method tests, with an expected interface set */ - g_dbus_proxy_set_interface_info (proxy, &frob_dbus_interface_info); + g_dbus_proxy_set_interface_info (proxy, frob_dbus_interface_info); test_methods (connection, name, name_owner, proxy); /* And now one more test where we deliberately set the expected @@ -477,9 +427,16 @@ int main (int argc, char *argv[]) { + gint ret; + GDBusNodeInfo *introspection_data = NULL; + g_type_init (); g_test_init (&argc, &argv, NULL); + introspection_data = g_dbus_node_info_new_for_xml (frob_dbus_interface_xml, NULL); + g_assert (introspection_data != NULL); + frob_dbus_interface_info = introspection_data->interfaces[0]; + /* all the tests rely on a shared main loop */ loop = g_main_loop_new (NULL, FALSE); @@ -490,5 +447,9 @@ main (int argc, g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE); g_test_add_func ("/gdbus/proxy", test_proxy); - return g_test_run(); + + ret = g_test_run(); + + g_dbus_node_info_unref (introspection_data); + return ret; } |