From 949436ffac9e46649398e1bc9f0ddf567c88dd1c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 17 Jun 2005 14:29:48 +0000 Subject: 2005-06-17 Colin Walters * glib/dbus-gproxy.c (dbus_g_proxy_emit_remote_signal): Don't spew warnings if we get malformed remote signals. * glib/dbus-gobject.c (propsig_iterate): New function. (lookup_object_info): New function, extracted from lookup_object_and_method. (introspect_properties, introspect_signals): Delete; these are merged into write_interface. (write_interface): Write out signals and properties here; dump the org.gtk.object stuff and use the interface given in the introspection data blob. Also fix up property XML. (lookup_values): New function. (introspect_interfaces): Gather a mapping from interface to a list of its methods, signals, and properties, then write out each interface. (lookup_object_and_method): Use lookup_object_info. (struct DBusGSignalClosure): Add interface. (dbus_g_signal_closure_new): Add interface. Don't dup signame; we can just use the constant data. (dbus_g_signal_closure_finalize): Don't free signal name. (signal_emitter_marshaller): Use interface from signal closure. (export_signals): Only export signals mentioned in introspection blob. (dbus_g_connection_register_g_object): Warn if we have no introspection data for an object. (funcsig_equal): Remove unused variable. (dbus_g_object_register_marshaller): Take varargs instead of list. (dbus_g_object_register_marshaller_array): New function, extracted from old dbus_g_object_register_marshaller. * glib/dbus-binding-tool-glib.c (struct DBusBindingToolCData): Add signals and property data. (write_quoted_string): New function, extracted from generate_glue. (generate_glue): Write signals and properties to introspection blob. * dbus/dbus-glib.h (struct DBusGObjectInfo): Include exported_signals and exported_properties. (dbus_g_object_register_marshaller): Update prototype. (dbus_g_object_register_marshaller_array): Prototype. * test/glib/test-dbus-glib.c: Extend testing to cover new signals. * test/glib/test-service-glib.c: Add new test signals and method to emit them. * test/glib/test-service-glib.xml: Add some test signals. * test/glib/Makefile.am (BUILT_SOURCES): Add my-object-marshal.c and my-object-marshal.h (test_service_glib_SOURCES, test_dbus_glib_SOURCES): Add my-object-marshal.c. (my-object-marshal.c, my-object-marshal.h): Implement. * test/glib/.cvsignore: Update. * doc/TODO: Remove two GLib TODO items fixed by this patch. --- test/glib/.cvsignore | 2 + test/glib/Makefile.am | 17 ++++-- test/glib/my-object-marshal.list | 2 + test/glib/test-dbus-glib.c | 128 +++++++++++++++++++++++++++++++++++---- test/glib/test-service-glib.c | 38 +++++++++++- test/glib/test-service-glib.xml | 11 ++++ 6 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 test/glib/my-object-marshal.list (limited to 'test') diff --git a/test/glib/.cvsignore b/test/glib/.cvsignore index cdaabeb9..a0cd5e95 100644 --- a/test/glib/.cvsignore +++ b/test/glib/.cvsignore @@ -11,3 +11,5 @@ run-test.conf test-service-glib-bindings.h test-service-glib-glue.h run-with-tmp-session-bus.conf +my-object-marshal.h +my-object-marshal.c diff --git a/test/glib/Makefile.am b/test/glib/Makefile.am index 568dab3d..77ee1906 100644 --- a/test/glib/Makefile.am +++ b/test/glib/Makefile.am @@ -35,14 +35,16 @@ endif noinst_PROGRAMS= test-dbus-glib test-service-glib $(THREAD_APPS) test_dbus_glib_SOURCES= \ + my-object-marshal.c \ test-dbus-glib.c test_dbus_glib_LDADD= $(DBUS_GLIB_TOOL_LIBS) $(top_builddir)/glib/libdbus-glib-1.la $(top_builddir)/glib/libdbus-gtool.la -test_service_glib_SOURCES= \ - test-service-glib.c +BUILT_SOURCES = test-service-glib-glue.h test-service-glib-bindings.h my-object-marshal.c my-object-marshal.h -BUILT_SOURCES = test-service-glib-glue.h test-service-glib-bindings.h +test_service_glib_SOURCES= \ + my-object-marshal.c \ + test-service-glib.c test-service-glib-glue.h: test-service-glib.xml $(top_builddir)/glib/dbus-binding-tool $(top_builddir)/glib/dbus-binding-tool --prefix=my_object --mode=glib-server --output=test-service-glib-glue.h $(srcdir)/test-service-glib.xml @@ -50,7 +52,14 @@ test-service-glib-glue.h: test-service-glib.xml $(top_builddir)/glib/dbus-bindin test-service-glib-bindings.h: test-service-glib.xml $(top_builddir)/glib/dbus-binding-tool $(top_builddir)/glib/dbus-binding-tool --prefix=my_object --mode=glib-client --output=test-service-glib-bindings.h $(srcdir)/test-service-glib.xml -CLEANFILES = test-service-glib-glue.h test-service-glib-bindings.h +my-object-marshal.c: Makefile my-object-marshal.list + @GLIB_GENMARSHAL@ --prefix=my_object_marshal $(srcdir)/my-object-marshal.list --header --body > my-object-marshal.c + +my-object-marshal.h: Makefile my-object-marshal.list + @GLIB_GENMARSHAL@ --prefix=my_object_marshal $(srcdir)/my-object-marshal.list --header > my-object-marshal.h + + +CLEANFILES = $(BUILT_SOURCES) test_service_glib_LDADD= $(top_builddir)/glib/libdbus-glib-1.la diff --git a/test/glib/my-object-marshal.list b/test/glib/my-object-marshal.list new file mode 100644 index 00000000..48cbfad4 --- /dev/null +++ b/test/glib/my-object-marshal.list @@ -0,0 +1,2 @@ +NONE:STRING,INT,STRING +NONE:STRING,BOXED diff --git a/test/glib/test-dbus-glib.c b/test/glib/test-dbus-glib.c index 2fc8665b..1f979a27 100644 --- a/test/glib/test-dbus-glib.c +++ b/test/glib/test-dbus-glib.c @@ -7,10 +7,14 @@ #include #include #include +#include "my-object-marshal.h" static GMainLoop *loop = NULL; static int n_times_foo_received = 0; static int n_times_frobnicate_received = 0; +static int n_times_sig0_received = 0; +static int n_times_sig1_received = 0; +static guint exit_timeout = 0; static gboolean timed_exit (gpointer loop) @@ -27,6 +31,7 @@ foo_signal_handler (DBusGProxy *proxy, n_times_foo_received += 1; g_main_loop_quit (loop); + g_source_remove (exit_timeout); } static void @@ -39,6 +44,44 @@ frobnicate_signal_handler (DBusGProxy *proxy, g_assert (val == 42); g_main_loop_quit (loop); + g_source_remove (exit_timeout); +} + +static void +sig0_signal_handler (DBusGProxy *proxy, + const char *str0, + int val, + const char *str1, + void *user_data) +{ + n_times_sig0_received += 1; + + g_assert (!strcmp (str0, "foo")); + + g_assert (val == 22); + + g_assert (!strcmp (str1, "moo")); + + g_main_loop_quit (loop); + g_source_remove (exit_timeout); +} + +static void +sig1_signal_handler (DBusGProxy *proxy, + const char *str0, + GValue *value, + void *user_data) +{ + n_times_sig1_received += 1; + + g_assert (!strcmp (str0, "baz")); + + g_assert (G_VALUE_HOLDS_STRING (value)); + + g_assert (!strcmp (g_value_get_string (value), "bar")); + + g_main_loop_quit (loop); + g_source_remove (exit_timeout); } static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2); @@ -216,9 +259,7 @@ main (int argc, char **argv) G_TYPE_INVALID); dbus_g_connection_flush (connection); - - g_timeout_add (5000, timed_exit, loop); - + exit_timeout = g_timeout_add (5000, timed_exit, loop); g_main_loop_run (loop); if (n_times_foo_received != 1) @@ -643,16 +684,81 @@ main (int argc, char **argv) dbus_g_connection_flush (connection); - -#if 0 - g_timeout_add (5000, timed_exit, loop); - + exit_timeout = g_timeout_add (5000, timed_exit, loop); g_main_loop_run (loop); if (n_times_frobnicate_received != 1) lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received); -#endif + if (!dbus_g_proxy_invoke (proxy, "EmitFrobnicate", &error, + G_TYPE_INVALID, G_TYPE_INVALID)) + lose_gerror ("Failed to complete EmitFrobnicate call", error); + + dbus_g_connection_flush (connection); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + + if (n_times_frobnicate_received != 2) + lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received); + + g_object_unref (G_OBJECT (proxy)); + + proxy = dbus_g_proxy_new_for_name_owner (connection, + "org.freedesktop.DBus.TestSuiteGLibService", + "/org/freedesktop/DBus/Tests/MyTestObject", + "org.freedesktop.DBus.Tests.FooObject", + &error); + + if (proxy == NULL) + lose_gerror ("Failed to create proxy for name owner", error); + + dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); + + dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); + + dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE); + + dbus_g_proxy_connect_signal (proxy, "Sig0", + G_CALLBACK (sig0_signal_handler), + NULL, NULL); + dbus_g_proxy_connect_signal (proxy, "Sig1", + G_CALLBACK (sig1_signal_handler), + NULL, NULL); + + dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); + + dbus_g_connection_flush (connection); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + + if (n_times_sig0_received != 1) + lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received); + if (n_times_sig1_received != 1) + lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received); + + dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); + dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); + + dbus_g_connection_flush (connection); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + exit_timeout = g_timeout_add (5000, timed_exit, loop); + g_main_loop_run (loop); + + if (n_times_sig0_received != 3) + lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received); + if (n_times_sig1_received != 3) + lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received); + g_object_unref (G_OBJECT (proxy)); proxy = dbus_g_proxy_new_for_name_owner (connection, @@ -680,7 +786,6 @@ main (int argc, char **argv) gboolean found_properties; gboolean found_myobject; gboolean found_fooobject; - gboolean found_gtk_myobject; node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error); if (!node) @@ -688,7 +793,6 @@ main (int argc, char **argv) found_introspectable = FALSE; found_properties = FALSE; - found_gtk_myobject = FALSE; found_myobject = FALSE; found_fooobject = FALSE; for (elt = node_info_get_interfaces (node); elt ; elt = elt->next) @@ -699,8 +803,6 @@ main (int argc, char **argv) found_introspectable = TRUE; else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0) found_properties = TRUE; - else if (strcmp (interface_info_get_name (iface), "org.gtk.objects.MyObject") == 0) - found_gtk_myobject = TRUE; else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0) { GSList *elt; @@ -729,7 +831,7 @@ main (int argc, char **argv) lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface)); } - if (!(found_introspectable && found_gtk_myobject && found_myobject && found_properties)) + if (!(found_introspectable && found_myobject && found_properties)) lose ("Missing interface"); } g_free (v_STRING_2); diff --git a/test/glib/test-service-glib.c b/test/glib/test-service-glib.c index 208bfb24..6089367e 100644 --- a/test/glib/test-service-glib.c +++ b/test/glib/test-service-glib.c @@ -10,6 +10,7 @@ #include #include #include +#include "my-object-marshal.h" typedef struct MyObject MyObject; typedef struct MyObjectClass MyObjectClass; @@ -77,6 +78,8 @@ gboolean my_object_get_val (MyObject *obj, guint *ret, GError **error); gboolean my_object_get_value (MyObject *obj, guint *ret, GError **error); +gboolean my_object_emit_signals (MyObject *obj, GError **error); + gboolean my_object_emit_frobnicate (MyObject *obj, GError **error); #include "test-service-glib-glue.h" @@ -93,10 +96,11 @@ enum enum { FROBNICATE, + SIG0, + SIG1, LAST_SIGNAL }; -static void *parent_class; static guint signals[LAST_SIGNAL] = { 0 }; static void @@ -185,6 +189,23 @@ my_object_class_init (MyObjectClass *mobject_class) g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + signals[SIG0] = + g_signal_new ("sig0", + G_OBJECT_CLASS_TYPE (mobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, + 0, + NULL, NULL, + my_object_marshal_VOID__STRING_INT_STRING, + G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); + + signals[SIG1] = + g_signal_new ("sig1", + G_OBJECT_CLASS_TYPE (mobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, + 0, + NULL, NULL, + my_object_marshal_VOID__STRING_BOXED, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); } GQuark @@ -403,6 +424,21 @@ my_object_emit_frobnicate (MyObject *obj, GError **error) return TRUE; } +gboolean +my_object_emit_signals (MyObject *obj, GError **error) +{ + GValue val = {0, }; + + g_signal_emit (obj, signals[SIG0], 0, "foo", 22, "moo"); + + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, "bar"); + g_signal_emit (obj, signals[SIG1], 0, "baz", &val); + g_value_unset (&val); + + return TRUE; +} + static GMainLoop *loop; #define TEST_SERVICE_NAME "org.freedesktop.DBus.TestSuiteGLibService" diff --git a/test/glib/test-service-glib.xml b/test/glib/test-service-glib.xml index f976572b..05cb5abd 100644 --- a/test/glib/test-service-glib.xml +++ b/test/glib/test-service-glib.xml @@ -84,13 +84,24 @@ + + + + + + + + + + + -- cgit