diff options
author | Havoc Pennington <hp@redhat.com> | 2005-01-15 07:15:38 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2005-01-15 07:15:38 +0000 |
commit | 9c3d566e95c9080f6040c64531b0ccae22bd5d74 (patch) | |
tree | d21a18baa5a5ee9855c8a00eb2c1985bc23ca65f /glib | |
parent | 6ec04e917c8b4d477e818aa65ebb5e1fd50e4395 (diff) |
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
Diffstat (limited to 'glib')
-rw-r--r-- | glib/dbus-gobject.c | 2 | ||||
-rw-r--r-- | glib/dbus-gproxy.c | 7 | ||||
-rw-r--r-- | glib/dbus-gutils.c | 24 | ||||
-rw-r--r-- | glib/dbus-gvalue.c | 186 |
4 files changed, 156 insertions, 63 deletions
diff --git a/glib/dbus-gobject.c b/glib/dbus-gobject.c index df9ff9d6..e1e387e5 100644 --- a/glib/dbus-gobject.c +++ b/glib/dbus-gobject.c @@ -308,7 +308,7 @@ handle_introspect (DBusConnection *connection, g_error ("Out of memory"); dbus_message_append_args (message, - DBUS_TYPE_STRING, xml->str, + DBUS_TYPE_STRING, &xml->str, DBUS_TYPE_INVALID); dbus_connection_send (connection, message, NULL); diff --git a/glib/dbus-gproxy.c b/glib/dbus-gproxy.c index fe285ab3..24ce6bf3 100644 --- a/glib/dbus-gproxy.c +++ b/glib/dbus-gproxy.c @@ -941,8 +941,8 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection, DBusGProxy *proxy; DBusMessage *request, *reply; DBusError derror; - char *base_service_name; - + const char *base_service_name; + g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (service_name != NULL, NULL); g_return_val_if_fail (path_name != NULL, NULL); @@ -962,7 +962,7 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection, g_error ("Out of memory"); if (! dbus_message_append_args (request, - DBUS_TYPE_STRING, service_name, + DBUS_TYPE_STRING, &service_name, DBUS_TYPE_INVALID)) g_error ("Out of memory"); @@ -997,7 +997,6 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection, dbus_message_unref (request); if (reply) dbus_message_unref (reply); - dbus_free (base_service_name); return proxy; } diff --git a/glib/dbus-gutils.c b/glib/dbus-gutils.c index a40e3603..9e4a5cd2 100644 --- a/glib/dbus-gutils.c +++ b/glib/dbus-gutils.c @@ -84,10 +84,10 @@ _dbus_gutils_type_to_string (int type) { case DBUS_TYPE_INVALID: return "invalid"; - case DBUS_TYPE_NIL: - return "nil"; case DBUS_TYPE_BOOLEAN: return "boolean"; + case DBUS_TYPE_BYTE: + return "byte"; case DBUS_TYPE_INT32: return "int32"; case DBUS_TYPE_UINT32: @@ -96,16 +96,20 @@ _dbus_gutils_type_to_string (int type) return "double"; case DBUS_TYPE_STRING: return "string"; - case DBUS_TYPE_CUSTOM: - return "custom"; + case DBUS_TYPE_OBJECT_PATH: + return "object_path"; + case DBUS_TYPE_SIGNATURE: + return "signature"; + case DBUS_TYPE_STRUCT: + return "struct"; case DBUS_TYPE_ARRAY: return "array"; - case DBUS_TYPE_DICT: - return "dict"; - case DBUS_TYPE_INT64: - return "int64"; - case DBUS_TYPE_UINT64: - return "uint64"; + case DBUS_TYPE_VARIANT: + return "variant"; + case DBUS_STRUCT_BEGIN_CHAR: + return "begin_struct"; + case DBUS_STRUCT_END_CHAR: + return "end_struct"; default: return "unknown"; } diff --git a/glib/dbus-gvalue.c b/glib/dbus-gvalue.c index 04e962fe..b44640ce 100644 --- a/glib/dbus-gvalue.c +++ b/glib/dbus-gvalue.c @@ -1,3 +1,26 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-gvalue.c GValue to-from DBusMessageIter + * + * Copyright (C) 2004 Ximian, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + #include <dbus-gvalue.h> gboolean @@ -5,41 +28,43 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value) { gboolean can_convert = TRUE; + /* This is slightly evil, we don't use g_value_set_foo() functions */ +#define MAP_BASIC(d_t, g_t) \ + case DBUS_TYPE_##d_t: \ + g_value_init (value, G_TYPE_##g_t); \ + dbus_message_iter_get_basic (iter, &value->data[0]); \ + break + switch (dbus_message_iter_get_arg_type (iter)) { -#define MAP(d_t, d_get, g_t, g_set) \ - case DBUS_##d_t: \ - g_value_init (value, G_##g_t); \ - g_value_##g_set (value, dbus_message_iter_##d_get (iter)); \ - break - - MAP(TYPE_BYTE, get_byte, TYPE_UCHAR, set_uchar); - MAP(TYPE_BOOLEAN, get_boolean, TYPE_BOOLEAN , set_boolean); - MAP(TYPE_INT32, get_int32, TYPE_INT , set_int); - MAP(TYPE_UINT32, get_uint32, TYPE_UINT , set_uint); -#ifdef DBUS_HAVE_INT64 - MAP(TYPE_INT64, get_int64, TYPE_INT64 , set_int64); - MAP(TYPE_UINT64, get_uint64, TYPE_UINT64 , set_uint64); -#endif - MAP(TYPE_DOUBLE, get_double, TYPE_DOUBLE , set_double); + MAP_BASIC (BOOLEAN, BOOLEAN); + MAP_BASIC (BYTE, UCHAR); + MAP_BASIC (INT32, INT); + MAP_BASIC (UINT32, UINT); + MAP_BASIC (INT64, INT64); + MAP_BASIC (UINT64, UINT64); + MAP_BASIC (DOUBLE, DOUBLE); + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + case DBUS_TYPE_SIGNATURE: { - char *s; /* FIXME use a const string accessor */ + const char *s; g_value_init (value, G_TYPE_STRING); - s = dbus_message_iter_get_string (iter); + dbus_message_iter_get_basic (iter, &s); g_value_set_string (value, s); - g_free (s); } break; + + case DBUS_TYPE_STRUCT: + case DBUS_TYPE_ARRAY: + case DBUS_TYPE_VARIANT: default: - /* FIXME: we need to define custom boxed types for arrays - etc. so we can map them transparently / pleasantly */ can_convert = FALSE; - break; } -#undef MAP +#undef MAP_BASIC return can_convert; } @@ -54,59 +79,120 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value) switch (value_type) { case G_TYPE_CHAR: - dbus_message_iter_append_byte (iter, - g_value_get_char (value)); + { + char b = g_value_get_char (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_BYTE, + &b)) + goto nomem; + } break; case G_TYPE_UCHAR: - dbus_message_iter_append_byte (iter, - g_value_get_uchar (value)); + { + unsigned char b = g_value_get_uchar (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_BYTE, + &b)) + goto nomem; + } break; case G_TYPE_BOOLEAN: - dbus_message_iter_append_boolean (iter, - g_value_get_boolean (value)); + { + unsigned char b = g_value_get_boolean (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_BOOLEAN, + &b)) + goto nomem; + } break; case G_TYPE_INT: - dbus_message_iter_append_int32 (iter, - g_value_get_int (value)); + { + dbus_int32_t v = g_value_get_int (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_INT32, + &v)) + goto nomem; + } break; case G_TYPE_UINT: - dbus_message_iter_append_uint32 (iter, - g_value_get_uint (value)); + { + dbus_uint32_t v = g_value_get_uint (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_UINT32, + &v)) + goto nomem; + } break; /* long gets cut to 32 bits so the remote API is consistent * on all architectures */ case G_TYPE_LONG: - dbus_message_iter_append_int32 (iter, - g_value_get_long (value)); + { + dbus_int32_t v = g_value_get_long (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_INT32, + &v)) + goto nomem; + } break; case G_TYPE_ULONG: - dbus_message_iter_append_uint32 (iter, - g_value_get_ulong (value)); + { + dbus_uint32_t v = g_value_get_ulong (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_UINT32, + &v)) + goto nomem; + } break; -#ifdef DBUS_HAVE_INT64 case G_TYPE_INT64: - dbus_message_iter_append_int64 (iter, - g_value_get_int64 (value)); + { + gint64 v = g_value_get_int64 (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_INT64, + &v)) + goto nomem; + } break; case G_TYPE_UINT64: - dbus_message_iter_append_uint64 (iter, - g_value_get_uint64 (value)); + { + guint64 v = g_value_get_uint64 (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_UINT64, + &v)) + goto nomem; + } break; -#endif case G_TYPE_FLOAT: - dbus_message_iter_append_double (iter, - g_value_get_float (value)); + { + double v = g_value_get_float (value); + + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_DOUBLE, + &v)) + goto nomem; + } break; case G_TYPE_DOUBLE: - dbus_message_iter_append_double (iter, - g_value_get_double (value)); + { + double v = g_value_get_double (value); + + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_DOUBLE, + &v)) + goto nomem; + } break; case G_TYPE_STRING: /* FIXME, the GValue string may not be valid UTF-8 */ - dbus_message_iter_append_string (iter, - g_value_get_string (value)); + { + const char *v = g_value_get_string (value); + if (!dbus_message_iter_append_basic (iter, + DBUS_TYPE_STRING, + &v)) + goto nomem; + } break; + default: /* FIXME: we need to define custom boxed types for arrays etc. so we can map them transparently / pleasantly */ @@ -115,5 +201,9 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value) } return can_convert; + + nomem: + g_error ("no memory"); + return FALSE; } |