From 2b97fb81a508a047b14f4c4426c28abfd18bb2e0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 27 Feb 2005 17:38:12 +0000 Subject: 2005-02-27 Colin Walters * glib/dbus-gidl.c (property_info_get_type, arg_info_get_type): Change return value to const char * instead of int so we can do full signatures. (struct PropertyInfo, struct ArgInfo): Store char *. (property_info_new, arg_info_new): Update parameters, strdup. (property_info_unref, arg_info_unref): Free. * glib/dbus-gidl.h: Update prototypes. * glib/dbus-gparser.c (basic_type_from_string): Delete. (validate_signature): New function, just validates signature and sets GError. (parse_property, parse_arg): Invoke validate_signature. Store signature instead of just type code. * glib/dbus-gvalue.c (base_type_from_signature): New utility function to return a primary type for a signature, dropping information about types in container types. (dbus_gvalue_genmarshal_name_from_type) (dbus_gvalue_binding_type_from_type) (dbus_gvalue_ctype_from_type): Update to take full signature instead of type code. (dbus_gtype_to_dbus_type): Moved here from glib/dbus-gobject.c. * glib/dbus-gvalue.h: Update prototypes for above. * glib/dbus-gobject.c (gtype_to_dbus_type): Moved to glib/dbus-gvalue.c as dbus_gtype_to_dbus_type. (introspect_properties, introspect_signals, write_interface): Update to handle signatures, and remove usage of _dbus_gutils_type_to_string. (handle_introspect): Print out type codes instead of e.g. "string" in hardcoded introspection XML; also use x_AS_STRING constants instead of hardcoding in string. * glib/dbus-glib-tool.c (pretty_print): Handle signature change to string. Remove usage of _dbus_gutils_type_to_string. * glib/dbus-gutils.c (_dbus_gutils_type_to_string): Delete. * glib/dbus-gutils.h (_dbus_gutils_type_to_string): Update for deletion. * glib/dbus-binding-tool-glib.c (compute_marshaller) (compute_marshaller_name, generate_glue): Handle signature change to string. (write_formal_parameters, write_args_for_direction): Ditto, and remove FIXME. * tools/dbus-tree-view.c (type_to_string): Delete. (info_set_func_text): Update to print full signatures. * test/glib/test-service-glib.xml: Change types to new introspection format. --- glib/dbus-gparser.c | 72 ++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 56 deletions(-) (limited to 'glib/dbus-gparser.c') diff --git a/glib/dbus-gparser.c b/glib/dbus-gparser.c index 5d6d664a..745e0dde 100644 --- a/glib/dbus-gparser.c +++ b/glib/dbus-gparser.c @@ -21,7 +21,9 @@ * */ #include "dbus-gparser.h" +#include "dbus/dbus-glib-lowlevel.h" #include "dbus-gidl.h" +#include "dbus/dbus-signature.h" #include #include @@ -461,59 +463,21 @@ parse_signal (Parser *parser, return TRUE; } -static int -basic_type_from_string (const char *str) +static gboolean +validate_signature (const char *str, + const char *element_name, + GError **error) { - if (strcmp (str, "string") == 0) - return DBUS_TYPE_STRING; - else if (strcmp (str, "int16") == 0) - return DBUS_TYPE_INT16; - else if (strcmp (str, "uint16") == 0) - return DBUS_TYPE_UINT16; - else if (strcmp (str, "int32") == 0) - return DBUS_TYPE_INT32; - else if (strcmp (str, "uint32") == 0) - return DBUS_TYPE_UINT32; - else if (strcmp (str, "int64") == 0) - return DBUS_TYPE_INT64; - else if (strcmp (str, "uint64") == 0) - return DBUS_TYPE_UINT64; - else if (strcmp (str, "double") == 0) - return DBUS_TYPE_DOUBLE; - else if (strcmp (str, "byte") == 0) - return DBUS_TYPE_BYTE; - else if (strcmp (str, "boolean") == 0) - return DBUS_TYPE_BOOLEAN; - else if (strcmp (str, "byte") == 0) - return DBUS_TYPE_BYTE; - else if (strcmp (str, "object") == 0) - return DBUS_TYPE_OBJECT_PATH; - else if (strcmp (str, "variant") == 0) - return DBUS_TYPE_VARIANT; - else - return DBUS_TYPE_INVALID; -} + DBusError derror; -/* FIXME we have to allow type signatures, not just basic types - */ -static int -type_from_string (const char *str, - const char *element_name, - GError **error) -{ - int t; + dbus_error_init (&derror); - t = basic_type_from_string (str); - - if (t == DBUS_TYPE_INVALID) + if (!dbus_signature_validate (str, &derror)) { - g_set_error (error, G_MARKUP_ERROR, - G_MARKUP_ERROR_PARSE, - _("Type \"%s\" not understood on <%s> element "), - str, element_name); + dbus_set_g_error (error, &derror); + return FALSE; } - - return t; + return TRUE; } static gboolean @@ -529,7 +493,6 @@ parse_property (Parser *parser, PropertyInfo *property; NodeInfo *top; PropertyAccessFlags access_flags; - int t; if (parser->interface == NULL || parser->node_stack == NULL || @@ -582,8 +545,7 @@ parse_property (Parser *parser, return FALSE; } - t = type_from_string (type, element_name, error); - if (t == DBUS_TYPE_INVALID) + if (!validate_signature (type, element_name, error)) return FALSE; access_flags = 0; @@ -604,7 +566,7 @@ parse_property (Parser *parser, top = parser->node_stack->data; - property = property_info_new (name, t, access_flags); + property = property_info_new (name, type, access_flags); interface_info_add_property (parser->interface, property); property_info_unref (property); @@ -624,7 +586,6 @@ parse_arg (Parser *parser, const char *type; const char *direction; ArgDirection dir; - int t; ArgInfo *arg; char *generated_name; @@ -694,8 +655,7 @@ parse_arg (Parser *parser, return FALSE; } - t = type_from_string (type, element_name, error); - if (t == DBUS_TYPE_INVALID) + if (!validate_signature (type, element_name, error)) return FALSE; generated_name = NULL; @@ -706,7 +666,7 @@ parse_arg (Parser *parser, signal_info_get_n_args (parser->signal)); - arg = arg_info_new (name ? name : generated_name, dir, t); + arg = arg_info_new (name ? name : generated_name, dir, type); if (parser->method) method_info_add_arg (parser->method, arg); else if (parser->signal) -- cgit