From 030cc1e53c6216853e08e27b92f72db80d001873 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 12 Mar 2005 20:07:21 +0000 Subject: 2005-03-12 Colin Walters * bus/driver.c (write_args_for_direction): New function, parses a type signature into arguments and outputs to XML. (bus_driver_handle_introspect): Use it instead of hardcoding XML for certain signatures. * bus/Makefile.am (dbus-bus-introspect.xml): Add dependency on dbus-daemon. * glib/dbus-glib-tool.c (main): Parse ignore_unsupported argument, pass it to dbus_binding_tool_output_glib_client. * glib/dbus-binding-tool-glib.c (generate_client_glue): Protect against multiple inclusion. (dbus_binding_tool_output_glib_client): Add G_BEGIN_DECLS/G_END_DECLS. * glib/dbus-binding-tool-glib.c (compute_client_method_name): Change to just take iface prefix directly. (write_formal_parameters): Clarify error message. (check_supported_parameters): New function; checks to see type signatures of method parameters are supported. (generate_client_glue): Handle ignore_unsupported flag. (dbus_binding_tool_output_glib_client): Handle ignore_unsupported parameter. * glib/Makefile.am (dbus-glib-bindings.h): Pass --ignore-unsupported by default until glib bindings support arrays. --- ChangeLog | 32 ++++++++++++++ bus/Makefile.am | 2 +- bus/driver.c | 97 ++++++++++++++++--------------------------- glib/Makefile.am | 2 +- glib/dbus-binding-tool-glib.c | 64 ++++++++++++++++++++++++---- glib/dbus-binding-tool-glib.h | 2 +- glib/dbus-glib-tool.c | 6 ++- 7 files changed, 132 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index f35d45ab..e53c2b17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +2005-03-12 Colin Walters + + * bus/driver.c (write_args_for_direction): New function, + parses a type signature into arguments and outputs to + XML. + (bus_driver_handle_introspect): Use it instead of + hardcoding XML for certain signatures. + + * bus/Makefile.am (dbus-bus-introspect.xml): Add + dependency on dbus-daemon. + + * glib/dbus-glib-tool.c (main): Parse ignore_unsupported + argument, pass it to dbus_binding_tool_output_glib_client. + + * glib/dbus-binding-tool-glib.c + (generate_client_glue): Protect against multiple inclusion. + (dbus_binding_tool_output_glib_client): Add + G_BEGIN_DECLS/G_END_DECLS. + + * glib/dbus-binding-tool-glib.c (compute_client_method_name): + Change to just take iface prefix directly. + (write_formal_parameters): Clarify error message. + (check_supported_parameters): New function; checks to see type + signatures of method parameters are supported. + (generate_client_glue): Handle ignore_unsupported flag. + (dbus_binding_tool_output_glib_client): Handle ignore_unsupported + parameter. + + * glib/Makefile.am (dbus-glib-bindings.h): Pass + --ignore-unsupported by default until glib bindings + support arrays. + 2005-03-11 Colin Walters * glib/Makefile.am: Generate dbus-glib-bindings.h and diff --git a/bus/Makefile.am b/bus/Makefile.am index f6e04ee7..a1fb76a0 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -92,7 +92,7 @@ run-with-tmp-session-bus.sh: dbus-daemon all-local: dbus-bus-introspect.xml -dbus-bus-introspect.xml: $(srcdir)/run-with-tmp-session-bus.sh +dbus-bus-introspect.xml: $(srcdir)/run-with-tmp-session-bus.sh dbus-daemon DBUS_TOP_BUILDDIR=$(top_builddir) $(srcdir)/run-with-tmp-session-bus.sh ./print-introspect org.freedesktop.DBus /org/freedesktop/DBus > dbus-bus-introspect.xml.tmp && mv dbus-bus-introspect.xml.tmp dbus-bus-introspect.xml ## mop up the gcov files diff --git a/bus/driver.c b/bus/driver.c index e647fbf3..8f627787 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -31,6 +31,7 @@ #include "utils.h" #include #include +#include #include static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection, @@ -1098,6 +1099,34 @@ struct bus_driver_handle_reload_config } }; +static dbus_bool_t +write_args_for_direction (DBusString *xml, + const char *signature, + dbus_bool_t in) +{ + DBusTypeReader typereader; + DBusString sigstr; + int current_type; + + _dbus_string_init_const (&sigstr, signature); + _dbus_type_reader_init_types_only (&typereader, &sigstr, 0); + + while ((current_type = _dbus_type_reader_get_current_type (&typereader)) != DBUS_TYPE_INVALID) + { + const DBusString *subsig; + int start, len; + + _dbus_type_reader_get_signature (&typereader, &subsig, &start, &len); + if (!_dbus_string_append_printf (xml, " \n", in ? "in" : "out", _dbus_string_get_const_data_len (subsig, start, len))) + goto oom; + + _dbus_type_reader_next (&typereader); + } + return TRUE; + oom: + return FALSE; +} + static dbus_bool_t bus_driver_handle_introspect (DBusConnection *connection, BusTransaction *transaction, @@ -1150,73 +1179,19 @@ bus_driver_handle_introspect (DBusConnection *connection, i = 0; while (i < _DBUS_N_ELEMENTS (message_handlers)) { + if (!_dbus_string_append_printf (&xml, " \n", message_handlers[i].name)) goto oom; - /* This hacky mess can probably get mopped up eventually when the - * introspection format is related to the signature format - */ - - if (strcmp (message_handlers[i].in_args, "") == 0) - ; - else if (strcmp (message_handlers[i].in_args, - DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING) == 0) - { - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_UINT32_AS_STRING)) - goto oom; - } - else if (strcmp (message_handlers[i].in_args, - DBUS_TYPE_STRING_AS_STRING) == 0) - { - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - } - else - { - _dbus_warn ("Lack introspection code for in sig '%s'\n", - message_handlers[i].in_args); - _dbus_assert_not_reached ("FIXME introspection missing"); - } + if (!write_args_for_direction (&xml, message_handlers[i].in_args, TRUE)) + goto oom; + + if (!write_args_for_direction (&xml, message_handlers[i].out_args, FALSE)) + goto oom; - if (strcmp (message_handlers[i].out_args, "") == 0) - ; - else if (strcmp (message_handlers[i].out_args, - DBUS_TYPE_STRING_AS_STRING) == 0) - { - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - } - else if (strcmp (message_handlers[i].out_args, - DBUS_TYPE_BOOLEAN_AS_STRING) == 0) - { - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_BOOLEAN_AS_STRING)) - goto oom; - } - else if (strcmp (message_handlers[i].out_args, - DBUS_TYPE_UINT32_AS_STRING) == 0) - { - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_UINT32_AS_STRING)) - goto oom; - } - else if (strcmp (message_handlers[i].out_args, - DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING) == 0) - { - /* FIXME introspection format doesn't handle arrays yet */ - if (!_dbus_string_append_printf (&xml, " \n", DBUS_TYPE_STRING_AS_STRING)) - goto oom; - } - else - { - _dbus_warn ("Lack introspection code for out sig '%s'\n", - message_handlers[i].out_args); - _dbus_assert_not_reached ("FIXME introspection missing"); - } - if (!_dbus_string_append (&xml, " \n")) - goto oom; + goto oom; ++i; } diff --git a/glib/Makefile.am b/glib/Makefile.am index 4cfea7f0..b4256fac 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -51,7 +51,7 @@ dbus_binding_tool_SOURCES = \ dbus_binding_tool_LDADD= -lexpat libdbus-gtool.la dbus-glib-bindings.h: $(top_builddir)/bus/dbus-bus-introspect.xml dbus-binding-tool - ./dbus-binding-tool --mode=glib-client --output=dbus-glib-bindings.h $(top_builddir)/bus/dbus-bus-introspect.xml + ./dbus-binding-tool --ignore-unsupported --mode=glib-client --output=dbus-glib-bindings.h $(top_builddir)/bus/dbus-bus-introspect.xml # FIXME - remove --ignore-unsupported when we can do arrays BUILT_SOURCES = dbus-glib-bindings.h diff --git a/glib/dbus-binding-tool-glib.c b/glib/dbus-binding-tool-glib.c index 5bd413e1..c78b9d53 100644 --- a/glib/dbus-binding-tool-glib.c +++ b/glib/dbus-binding-tool-glib.c @@ -38,6 +38,7 @@ typedef struct { + gboolean ignore_unsupported; GIOChannel *channel; GError **error; @@ -576,15 +577,12 @@ iface_to_c_prefix (const char *iface) } static char * -compute_client_method_name (InterfaceInfo *iface, MethodInfo *method) +compute_client_method_name (const char *iface_prefix, MethodInfo *method) { GString *ret; char *method_name_uscored; - char *iface_prefix; - iface_prefix = iface_to_c_prefix (interface_info_get_name (iface)); ret = g_string_new (iface_prefix); - g_free (iface_prefix); method_name_uscored = _dbus_gutils_wincaps_to_uscore (method_info_get_name (method)); g_string_append_c (ret, '_'); @@ -617,8 +615,10 @@ write_formal_parameters (InterfaceInfo *iface, MethodInfo *method, GIOChannel *c g_set_error (error, DBUS_BINDING_TOOL_ERROR, DBUS_BINDING_TOOL_ERROR_UNSUPPORTED_CONVERSION, - _("Unsupported conversion from D-BUS type %s to glib C type"), - arg_info_get_type (arg)); + _("Unsupported conversion from D-BUS type signature \"%s\" to glib C type in method \"%s\" of interface \"%s\""), + arg_info_get_type (arg), + method_info_get_name (method), + interface_info_get_name (iface)); return FALSE; } @@ -707,6 +707,22 @@ write_args_for_direction (InterfaceInfo *iface, MethodInfo *method, GIOChannel * return FALSE; } +static gboolean +check_supported_parameters (MethodInfo *method) +{ + GSList *args; + + for (args = method_info_get_args (method); args; args = args->next) + { + ArgInfo *arg; + arg = args->data; + if (!dbus_gvalue_ctype_from_type (arg_info_get_type (arg), + arg_info_get_direction (arg))) + return FALSE; + } + return TRUE; +} + static gboolean generate_client_glue_list (GSList *list, DBusBindingToolCData *data, GError **error) { @@ -741,6 +757,7 @@ generate_client_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error GSList *methods; GSList *tmp; int count; + char *iface_prefix; channel = data->channel; @@ -749,6 +766,17 @@ generate_client_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error methods = interface_info_get_methods (interface); count = 0; + iface_prefix = iface_to_c_prefix (interface_info_get_name (interface)); + + if (!write_printf_to_iochannel ("#ifndef DBUS_GLIB_CLIENT_WRAPPERS_%s\n" + "#define DBUS_GLIB_CLIENT_WRAPPERS_%s\n\n", + channel, error, + iface_prefix, iface_prefix)) + { + g_free (iface_prefix); + goto io_lose; + } + for (tmp = methods; tmp != NULL; tmp = g_slist_next (tmp)) { MethodInfo *method; @@ -756,7 +784,15 @@ generate_client_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error method = (MethodInfo *) tmp->data; - method_name = compute_client_method_name (interface, method); + if (data->ignore_unsupported && !check_supported_parameters (method)) + { + g_warning ("Ignoring unsupported signature in method \"%s\" of interface \"%s\"\n", + method_info_get_name (method), + interface_info_get_name (interface)); + continue; + } + + method_name = compute_client_method_name (iface_prefix, method); WRITE_OR_LOSE ("static\n#ifdef G_HAVE_INLINE\ninline\n#endif\ngboolean\n"); if (!write_printf_to_iochannel ("%s (DBusGProxy *proxy", channel, error, @@ -791,6 +827,12 @@ generate_client_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error WRITE_OR_LOSE ("NULL);\n}\n\n"); } + + if (!write_printf_to_iochannel ("#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_%s */\n\n", channel, error, iface_prefix)) + { + g_free (iface_prefix); + goto io_lose; + } } return TRUE; io_lose: @@ -799,7 +841,7 @@ generate_client_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error gboolean -dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, GError **error) +dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, gboolean ignore_unsupported, GError **error) { DBusBindingToolCData data; gboolean ret; @@ -807,13 +849,19 @@ dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, GErro memset (&data, 0, sizeof (data)); data.channel = channel; + data.ignore_unsupported = ignore_unsupported; WRITE_OR_LOSE ("/* Generated by dbus-binding-tool; do not edit! */\n\n"); WRITE_OR_LOSE ("#include \n"); WRITE_OR_LOSE ("#include \n"); WRITE_OR_LOSE ("#include \n\n"); + WRITE_OR_LOSE ("G_BEGIN_DECLS\n\n"); ret = generate_client_glue (info, &data, error); + if (!ret) + goto io_lose; + + WRITE_OR_LOSE ("G_END_DECLS\n"); return ret; io_lose: diff --git a/glib/dbus-binding-tool-glib.h b/glib/dbus-binding-tool-glib.h index 6667438a..411c024e 100644 --- a/glib/dbus-binding-tool-glib.h +++ b/glib/dbus-binding-tool-glib.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS #define DBUS_GLIB_ANNOTATION_C_SYMBOL "org.freedesktop.DBus.GLib.CSymbol" -gboolean dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, GError **error); +gboolean dbus_binding_tool_output_glib_client (BaseInfo *info, GIOChannel *channel, gboolean ignore_unsupported, GError **error); gboolean dbus_binding_tool_output_glib_server (BaseInfo *info, GIOChannel *channel, GError **error); G_END_DECLS diff --git a/glib/dbus-glib-tool.c b/glib/dbus-glib-tool.c index 2fc564c4..85f78ed4 100644 --- a/glib/dbus-glib-tool.c +++ b/glib/dbus-glib-tool.c @@ -277,6 +277,7 @@ main (int argc, char **argv) struct stat srcbuf; struct stat targetbuf; gboolean force; + gboolean ignore_unsupported; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR); @@ -290,6 +291,7 @@ main (int argc, char **argv) files = NULL; prev_arg = NULL; output_file = NULL; + ignore_unsupported = FALSE; force = FALSE; i = 1; while (i < argc) @@ -322,6 +324,8 @@ main (int argc, char **argv) else usage (1); } + else if (strcmp (arg, "--ignore-unsupported") == 0) + ignore_unsupported = TRUE; else if (strncmp (arg, "--output=", 9) == 0) { output_file = arg + 9; @@ -413,7 +417,7 @@ main (int argc, char **argv) lose_gerror (_("Compilation failed"), error); break; case DBUS_BINDING_OUTPUT_GLIB_CLIENT: - if (!dbus_binding_tool_output_glib_client ((BaseInfo *) node, channel, &error)) + if (!dbus_binding_tool_output_glib_client ((BaseInfo *) node, channel, ignore_unsupported, &error)) lose_gerror (_("Compilation failed"), error); break; case DBUS_BINDING_OUTPUT_NONE: -- cgit