diff options
author | Joe Shaw <joeshaw@novell.com> | 2005-01-25 19:47:13 +0000 |
---|---|---|
committer | Joe Shaw <joeshaw@novell.com> | 2005-01-25 19:47:13 +0000 |
commit | b0002eb697ec4b1e35846b51d9e6e1a7824e0b03 (patch) | |
tree | d14e5cdc6646cb3de31d6e9e9ded564ac7bff82a /mono/DBusType/Array.cs | |
parent | f4d4d5ace5804acc363fbcff51fbdc82c078702b (diff) |
2005-01-25 Joe Shaw <joeshaw@novell.com>
* Land the mono binding changes to conform to the new APIs.
* mono/Makefile.am: Remove Custom.cs, DBusType/Custom.cs,
DBusType/Dict.cs, and DBusType/Nil.cs from the build.
* mono/Arguments.cs (GetCodeAsString): Added. Returns the dbus
type code as a string.
(InitAppending): Rename dbus_message_append_iter_init() to
dbus_message_iter_init_append().
* mono/BusDriver.cs: Rename ServiceEventHandler to
NameOwnerChangedHandler. Rename GetServiceOwner to GetOwner.
Rename ServiceOwnerChanged to NameOwnerChanged.
* mono/Connection.cs: Rename BaseService to UniqueName, and the
underlying C call.
* mono/Custom.cs: Removed. The CUSTOM type has been removed.
* mono/Service.cs: Rename Exists to HasOwner, internally rename
dbus_bus_acquire_service() to dbus_bus_request_name().
* mono/DBusType/Array.cs (ctor): Use Type.GetElementType() instead
of Type.UnderlyingSystemType to get the correct element type for
the array.
(ctor): Update code for new APIs: use dbus_message_iter_recurse(),
dbus_message_get_{element|arg}_type() instead of
dbus_message_iter_init_array_iterator().
(Append): Replace dbus_message_iter_append_array() with
dbus_message_iter_open_container() and
dbus_message_iter_close_container().
* mono/DBusType/Custom.cs, mono/DBusType/Nil.cs: Removed. These
types have been removed.
* mono/DBusType/*.cs: Replace calls of
dbus_message_iter_get_[type]() to dbus_message_iter_get_basic(),
but specify the type in the DllImport extern declaration. Ditto
for dbus_message_iter_append_[type]() ->
dbus_message_iter_append_basic().
* mono/example/BusListener.cs: Update for ServiceEventHandler ->
NameOwnerChangedHandler.
Diffstat (limited to 'mono/DBusType/Array.cs')
-rw-r--r-- | mono/DBusType/Array.cs | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/mono/DBusType/Array.cs b/mono/DBusType/Array.cs index dd93a5cc..7e46f73d 100644 --- a/mono/DBusType/Array.cs +++ b/mono/DBusType/Array.cs @@ -25,7 +25,7 @@ namespace DBus.DBusType public Array(System.Array val, Service service) { this.val = val; - this.elementType = Arguments.MatchType(val.GetType().UnderlyingSystemType); + this.elementType = Arguments.MatchType(val.GetType().GetElementType()); this.service = service; } @@ -34,36 +34,37 @@ namespace DBus.DBusType this.service = service; IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize); - - int elementTypeCode; - bool notEmpty = dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode); - this.elementType = (Type) Arguments.DBusTypes[(char) elementTypeCode]; - elements = new ArrayList(); + int elementTypeCode = dbus_message_iter_get_element_type (iter); + dbus_message_iter_recurse (iter, arrayIter); + this.elementType = (Type) Arguments.DBusTypes [(char) elementTypeCode]; + + elements = new ArrayList (); - if (notEmpty) { - do { - object [] pars = new Object[2]; + if (dbus_message_iter_get_arg_type (arrayIter) != 0) { + do { + object [] pars = new Object[2]; pars[0] = arrayIter; - pars[1] = service; + pars[1] = service; DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars); elements.Add(dbusType); - } while (dbus_message_iter_next(arrayIter)); - } - + } while (dbus_message_iter_next(arrayIter)); + } + Marshal.FreeCoTaskMem(arrayIter); } public void Append(IntPtr iter) { - IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize); + IntPtr arrayIter = Marshal.AllocCoTaskMem (Arguments.DBusMessageIterSize); - if (!dbus_message_iter_append_array(iter, - arrayIter, - (int) Arguments.GetCode(this.elementType))) { - throw new ApplicationException("Failed to append INT32 argument:" + val); + if (!dbus_message_iter_open_container (iter, + (int) this.Code, + Arguments.GetCodeAsString (elementType), + arrayIter)) { + throw new ApplicationException("Failed to append array argument: " + val); } - + foreach (object element in this.val) { object [] pars = new Object[2]; pars[0] = element; @@ -72,7 +73,11 @@ namespace DBus.DBusType dbusType.Append(arrayIter); } - Marshal.FreeCoTaskMem(arrayIter); + if (!dbus_message_iter_close_container (iter, arrayIter)) { + throw new ApplicationException ("Failed to append array argument: " + val); + } + + Marshal.FreeCoTaskMem (arrayIter); } public static bool Suits(System.Type type) @@ -107,7 +112,7 @@ namespace DBus.DBusType public object Get(System.Type type) { if (type.IsArray) - type = type.GetElementType (); + type = type.GetElementType (); if (Arguments.Suits(elementType, type.UnderlyingSystemType)) { this.val = System.Array.CreateInstance(type.UnderlyingSystemType, elements.Count); @@ -123,19 +128,28 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static bool dbus_message_iter_init_array_iterator(IntPtr iter, - IntPtr arrayIter, - out int elementType); + private extern static bool dbus_message_iter_open_container (IntPtr iter, + int containerType, + string elementType, + IntPtr subIter); + + [DllImport("dbus-1")] + private extern static bool dbus_message_iter_close_container (IntPtr iter, + IntPtr subIter); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_array(IntPtr iter, - IntPtr arrayIter, - int elementType); + private extern static int dbus_message_iter_get_element_type(IntPtr iter); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_has_next(IntPtr iter); + private extern static int dbus_message_iter_get_arg_type(IntPtr iter); + + [DllImport("dbus-1")] + private extern static void dbus_message_iter_recurse(IntPtr iter, IntPtr subIter); [DllImport("dbus-1")] private extern static bool dbus_message_iter_next(IntPtr iter); + + [DllImport("dbus-1")] + private extern static bool dbus_message_iter_has_next (IntPtr iter); } } |