From b0002eb697ec4b1e35846b51d9e6e1a7824e0b03 Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Tue, 25 Jan 2005 19:47:13 +0000 Subject: 2005-01-25 Joe Shaw * 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. --- mono/DBusType/Array.cs | 70 ++++++++++++++++------------ mono/DBusType/Boolean.cs | 8 ++-- mono/DBusType/Byte.cs | 10 ++-- mono/DBusType/Custom.cs | 109 -------------------------------------------- mono/DBusType/Double.cs | 8 ++-- mono/DBusType/Int32.cs | 8 ++-- mono/DBusType/Int64.cs | 8 ++-- mono/DBusType/Nil.cs | 68 --------------------------- mono/DBusType/ObjectPath.cs | 15 ++++-- mono/DBusType/String.cs | 14 ++++-- mono/DBusType/UInt32.cs | 8 ++-- mono/DBusType/UInt64.cs | 8 ++-- 12 files changed, 91 insertions(+), 243 deletions(-) delete mode 100644 mono/DBusType/Custom.cs delete mode 100644 mono/DBusType/Nil.cs (limited to 'mono/DBusType') 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); } } diff --git a/mono/DBusType/Boolean.cs b/mono/DBusType/Boolean.cs index fa5e1bcf..c561f0c5 100644 --- a/mono/DBusType/Boolean.cs +++ b/mono/DBusType/Boolean.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public Boolean(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_boolean(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_boolean(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append BOOLEAN argument:" + val); } @@ -78,9 +78,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.Boolean dbus_message_iter_get_boolean(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out bool value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_boolean(IntPtr iter, System.Boolean value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref bool value); } } diff --git a/mono/DBusType/Byte.cs b/mono/DBusType/Byte.cs index 2fb19aeb..958f6832 100644 --- a/mono/DBusType/Byte.cs +++ b/mono/DBusType/Byte.cs @@ -30,12 +30,12 @@ namespace DBus.DBusType public Byte(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_byte(iter); - } + dbus_message_iter_get_basic (iter, out this.val); + } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_byte(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append BYTE argument:" + val); } @@ -97,9 +97,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.Byte dbus_message_iter_get_byte(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out byte value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_byte(IntPtr iter, System.Byte value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref byte value); } } diff --git a/mono/DBusType/Custom.cs b/mono/DBusType/Custom.cs deleted file mode 100644 index 92560649..00000000 --- a/mono/DBusType/Custom.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Reflection.Emit; - -using DBus; - -namespace DBus.DBusType -{ - /// - /// A named byte array, used for custom types. - /// - public class Custom : IDBusType - { - public const char Code = 'c'; - private DBus.Custom val; - - private Custom() - { - } - - public Custom(DBus.Custom val, Service service) - { - this.val = val; - } - - public Custom(IntPtr iter, Service service) - { - string name; - IntPtr value; - int len; - - if (!dbus_message_iter_get_custom(iter, out name, out value, out len)) { - throw new ApplicationException("Failed to get CUSTOM argument."); - } - - this.val.Name = name; - this.val.Data = new byte[len]; - Marshal.Copy(value, this.val.Data, 0, len); - } - - public void Append(IntPtr iter) - { - IntPtr data = Marshal.AllocCoTaskMem(this.val.Data.Length); - try { - Marshal.Copy(this.val.Data, 0, data, this.val.Data.Length); - if (!dbus_message_iter_append_custom(iter, this.val.Name, data, this.val.Data.Length)) { - throw new ApplicationException("Failed to append CUSTOM argument:" + val); - } - } finally { - Marshal.FreeCoTaskMem(data); - } - } - - public static bool Suits(System.Type type) - { - switch (type.ToString()) { - case "DBus.Custom": - case "DBus.Custom&": - return true; - } - - return false; - } - - public static void EmitMarshalIn(ILGenerator generator, Type type) - { - if (type.IsByRef) { - generator.Emit(OpCodes.Ldobj, type); - } - } - - public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) - { - generator.Emit(OpCodes.Unbox, type); - generator.Emit(OpCodes.Ldobj, type); - if (!isReturn) { - generator.Emit(OpCodes.Stobj, type); - } - } - - public object Get() - { - return this.val; - } - - public object Get(System.Type type) - { - switch (type.ToString()) { - case "DBus.Custom": - case "DBus.Custom&": - return this.val; - default: - throw new ArgumentException("Cannot cast DBus.Type.Custom to type '" + type.ToString() + "'"); - } - } - - [DllImport("dbus-1")] - private extern static bool dbus_message_iter_get_custom(IntPtr iter, - out string name, - out IntPtr value, - out int len); - - [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_custom(IntPtr iter, - string name, - IntPtr data, - int len); - } -} diff --git a/mono/DBusType/Double.cs b/mono/DBusType/Double.cs index 008f6824..c8975cdc 100644 --- a/mono/DBusType/Double.cs +++ b/mono/DBusType/Double.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public Double(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_double(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_double(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append DOUBLE argument:" + val); } @@ -78,9 +78,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.Double dbus_message_iter_get_double(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out double value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_double(IntPtr iter, System.Double value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref double value); } } diff --git a/mono/DBusType/Int32.cs b/mono/DBusType/Int32.cs index a759b794..868d4335 100644 --- a/mono/DBusType/Int32.cs +++ b/mono/DBusType/Int32.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public Int32(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_int32(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_int32(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append INT32 argument:" + val); } @@ -85,9 +85,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.Int32 dbus_message_iter_get_int32(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int32 value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_int32(IntPtr iter, System.Int32 value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int32 value); } } diff --git a/mono/DBusType/Int64.cs b/mono/DBusType/Int64.cs index 6aea7ee8..47c066bc 100644 --- a/mono/DBusType/Int64.cs +++ b/mono/DBusType/Int64.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public Int64(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_int64(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_int64(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append INT64 argument:" + val); } @@ -86,9 +86,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.Int64 dbus_message_iter_get_int64(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int64 value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_int64(IntPtr iter, System.Int64 value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int64 value); } } diff --git a/mono/DBusType/Nil.cs b/mono/DBusType/Nil.cs deleted file mode 100644 index a271db3d..00000000 --- a/mono/DBusType/Nil.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Reflection.Emit; - -using DBus; - -namespace DBus.DBusType -{ - /// - /// Marks a "void"/"unset"/"nonexistent"/"null" argument. - /// - public class Nil : IDBusType - { - public const char Code = 'v'; - - private Nil() - { - } - - public Nil(object nil, Service service) - { - } - - public Nil(IntPtr iter, Service service) - { - } - - public void Append(IntPtr iter) - { - if (!dbus_message_iter_append_nil(iter)) - throw new ApplicationException("Failed to append NIL argument"); - } - - public static bool Suits(System.Type type) - { - return false; - } - - public static void EmitMarshalIn(ILGenerator generator, Type type) - { - if (type.IsByRef) { - generator.Emit(OpCodes.Ldind_I1); - } - } - - public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) - { - generator.Emit(OpCodes.Unbox, type); - generator.Emit(OpCodes.Ldind_I1); - if (!isReturn) { - generator.Emit(OpCodes.Stind_I1); - } - } - - public object Get() - { - return null; - } - - public object Get(System.Type type) - { - throw new ArgumentException("Cannot cast DBus.Type.Nil to type '" + type.ToString() + "'"); - } - - [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_nil(IntPtr iter); - } -} diff --git a/mono/DBusType/ObjectPath.cs b/mono/DBusType/ObjectPath.cs index f82c6804..01a21ca9 100644 --- a/mono/DBusType/ObjectPath.cs +++ b/mono/DBusType/ObjectPath.cs @@ -28,8 +28,11 @@ namespace DBus.DBusType public ObjectPath(IntPtr iter, Service service) { - - this.path = Marshal.PtrToStringAnsi(dbus_message_iter_get_object_path(iter)); + IntPtr raw; + + dbus_message_iter_get_basic (iter, out raw); + + this.path = Marshal.PtrToStringAnsi (raw); this.service = service; } @@ -47,7 +50,9 @@ namespace DBus.DBusType public void Append(IntPtr iter) { - if (!dbus_message_iter_append_object_path(iter, Marshal.StringToHGlobalAnsi(Path))) + IntPtr marshalVal = Marshal.StringToHGlobalAnsi (Path); + + if (!dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal)) throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val); } @@ -91,9 +96,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static IntPtr dbus_message_iter_get_object_path(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr path); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_object_path(IntPtr iter, IntPtr path); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr path); } } diff --git a/mono/DBusType/String.cs b/mono/DBusType/String.cs index bced310a..bf354ea0 100644 --- a/mono/DBusType/String.cs +++ b/mono/DBusType/String.cs @@ -25,12 +25,18 @@ namespace DBus.DBusType public String(IntPtr iter, Service service) { - this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter)); + IntPtr raw; + + dbus_message_iter_get_basic (iter, out raw); + + this.val = Marshal.PtrToStringAnsi (raw); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val))) + IntPtr marshalVal = Marshal.StringToHGlobalAnsi (val); + + if (!dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal)) throw new ApplicationException("Failed to append STRING argument:" + val); } @@ -78,9 +84,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static IntPtr dbus_message_iter_get_string(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr value); } } diff --git a/mono/DBusType/UInt32.cs b/mono/DBusType/UInt32.cs index b55893d3..5bb31217 100644 --- a/mono/DBusType/UInt32.cs +++ b/mono/DBusType/UInt32.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public UInt32(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_uint32(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_uint32(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append UINT32 argument:" + val); } @@ -87,9 +87,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.UInt32 dbus_message_iter_get_uint32(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt32 value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_uint32(IntPtr iter, System.UInt32 value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt32 value); } } diff --git a/mono/DBusType/UInt64.cs b/mono/DBusType/UInt64.cs index c987a918..ef689f2a 100644 --- a/mono/DBusType/UInt64.cs +++ b/mono/DBusType/UInt64.cs @@ -25,12 +25,12 @@ namespace DBus.DBusType public UInt64(IntPtr iter, Service service) { - this.val = dbus_message_iter_get_uint64(iter); + dbus_message_iter_get_basic (iter, out this.val); } public void Append(IntPtr iter) { - if (!dbus_message_iter_append_uint64(iter, val)) + if (!dbus_message_iter_append_basic (iter, (int) Code, ref val)) throw new ApplicationException("Failed to append UINT64 argument:" + val); } @@ -87,9 +87,9 @@ namespace DBus.DBusType } [DllImport("dbus-1")] - private extern static System.UInt64 dbus_message_iter_get_uint64(IntPtr iter); + private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt64 value); [DllImport("dbus-1")] - private extern static bool dbus_message_iter_append_uint64(IntPtr iter, System.UInt64 value); + private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt64 value); } } -- cgit