]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2005-03-12 Colin Walters <walters@verbum.org>
authorColin Walters <walters@verbum.org>
Sat, 12 Mar 2005 20:07:21 +0000 (20:07 +0000)
committerColin Walters <walters@verbum.org>
Sat, 12 Mar 2005 20:07:21 +0000 (20:07 +0000)
* 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
bus/Makefile.am
bus/driver.c
glib/Makefile.am
glib/dbus-binding-tool-glib.c
glib/dbus-binding-tool-glib.h
glib/dbus-glib-tool.c

index f35d45ab8ab73fa2de865941aa20afbbdc5b20d3..e53c2b175b01cb189e29f77f598791c9978b3cfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2005-03-12  Colin Walters  <walters@verbum.org>
+
+       * 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  <walters@verbum.org>
 
        * glib/Makefile.am: Generate dbus-glib-bindings.h and
index f6e04ee7e2862a51c89712a4b3417345c9b9104c..a1fb76a0feae5ba100d3afa77b810eb36c33ea05 100644 (file)
@@ -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
index e647fbf3a72f94080b1e01b2de0b44a9fd44b8fa..8f627787debc47a8e66423093432509cddfa41bc 100644 (file)
@@ -31,6 +31,7 @@
 #include "utils.h"
 #include <dbus/dbus-string.h>
 #include <dbus/dbus-internals.h>
+#include <dbus/dbus-marshal-recursive.h>
 #include <string.h>
 
 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, "      <arg direction=\"%s\" type=\"%s\"/>\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, "    <method name=\"%s\">\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, "      <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
-            goto oom;
-          if (!_dbus_string_append_printf (&xml, "      <arg direction=\"in\" type=\"%s\"/>\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, "      <arg direction=\"in\" type=\"%s\"/>\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, "      <arg direction=\"out\" type=\"%s\"/>\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, "      <arg direction=\"out\" type=\"%s\"/>\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, "      <arg direction=\"out\" type=\"%s\"/>\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, "      <arg direction=\"out\" type=\"%s\"/>\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, "    </method>\n"))
-        goto oom;
+       goto oom;
       
       ++i;
     }
index 4cfea7f016f5dec194e5111868c7380d54718a75..b4256fac329948eb4e46f2a8ac542c72ec8c9006 100644 (file)
@@ -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
 
index 5bd413e115ed4e78ab73fbddbae4b28a4a83d088..c78b9d53250e314c2a00188cab20ccf0b3616959 100644 (file)
@@ -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 <glib/gtypes.h>\n");
   WRITE_OR_LOSE ("#include <glib/gerror.h>\n");
   WRITE_OR_LOSE ("#include <dbus/dbus-glib.h>\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:
index 6667438adb5a13934b716f16af5f027c2c560b5e..411c024e28a48e490e4a9b43787186789aa37f96 100644 (file)
@@ -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
index 2fc564c44357fccfcac63d9348e63718137fa23a..85f78ed4116bd81bcda5460e248552d0804d3418 100644 (file)
@@ -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: