summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Shaw <joeshaw@novell.com>2005-09-08 18:54:42 +0000
committerJoe Shaw <joeshaw@novell.com>2005-09-08 18:54:42 +0000
commit24c6ddc1a41e280c877233f98569d4e21d12f1ef (patch)
treea318f931347f3d43cd22f1b56461a4ecec67c4f8
parent76faf9aa9c05dac0d3397867d8f317c3eb9cc0bc (diff)
2005-09-08 Joe Shaw <joeshaw@novell.com>
Patches from James Willcox <snorp@snorp.net> * mono/Makefile.am: Add Int16.cs and UInt16.cs * mono/DBusType/Array.cs: Handle multidimensional arrays, and support array "out" parameters. * mono/DBusType/Int16.cs, mono/DBusType/UInt16.cs: New files, for 16-bit int support.
-rw-r--r--ChangeLog12
-rw-r--r--mono/DBusType/Array.cs25
-rw-r--r--mono/DBusType/Int16.cs93
-rw-r--r--mono/DBusType/UInt16.cs93
-rw-r--r--mono/Makefile.am2
5 files changed, 221 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e7ae006..56065355 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-09-08 Joe Shaw <joeshaw@novell.com>
+
+ Patches from James Willcox <snorp@snorp.net>
+
+ * mono/Makefile.am: Add Int16.cs and UInt16.cs
+
+ * mono/DBusType/Array.cs: Handle multidimensional arrays, and
+ support array "out" parameters.
+
+ * mono/DBusType/Int16.cs, mono/DBusType/UInt16.cs: New files,
+ for 16-bit int support.
+
2005-09-06 John (J5) Palmieri <johnp@redhat.com>
* Released 0.50
diff --git a/mono/DBusType/Array.cs b/mono/DBusType/Array.cs
index ef001b98..3279b5aa 100644
--- a/mono/DBusType/Array.cs
+++ b/mono/DBusType/Array.cs
@@ -17,7 +17,7 @@ namespace DBus.DBusType
private ArrayList elements;
private Type elementType;
private Service service = null;
-
+
private Array()
{
}
@@ -53,14 +53,30 @@ namespace DBus.DBusType
Marshal.FreeCoTaskMem(arrayIter);
}
+
+ public string GetElementCodeAsString ()
+ {
+ string ret = System.String.Empty;
+ Type t = val.GetType ().GetElementType ();
+
+ while (true) {
+ ret += Arguments.GetCodeAsString (Arguments.MatchType(t));
+
+ if (t.IsArray)
+ t = t.GetElementType ();
+ else
+ break;
+ }
+
+ return ret;
+ }
public void Append(IntPtr iter)
{
IntPtr arrayIter = Marshal.AllocCoTaskMem (Arguments.DBusMessageIterSize);
if (!dbus_message_iter_open_container (iter,
- (int) Code,
- Arguments.GetCodeAsString (elementType),
+ (int) Code, GetElementCodeAsString(),
arrayIter)) {
throw new ApplicationException("Failed to append array argument: " + val);
}
@@ -82,7 +98,8 @@ namespace DBus.DBusType
public static bool Suits(System.Type type)
{
- if (type.IsArray) {
+ Type type2 = type.GetElementType ();
+ if (type.IsArray || (type2 != null && type2.IsArray)) {
return true;
}
diff --git a/mono/DBusType/Int16.cs b/mono/DBusType/Int16.cs
new file mode 100644
index 00000000..cd99e19e
--- /dev/null
+++ b/mono/DBusType/Int16.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection.Emit;
+
+using DBus;
+
+namespace DBus.DBusType
+{
+ /// <summary>
+ /// 16-bit integer.
+ /// </summary>
+ public class Int16 : IDBusType
+ {
+ public const char Code = 'n';
+ private System.Int16 val;
+
+ private Int16()
+ {
+ }
+
+ public Int16(System.Int16 val, Service service)
+ {
+ this.val = val;
+ }
+
+ public Int16(IntPtr iter, Service service)
+ {
+ dbus_message_iter_get_basic (iter, out this.val);
+ }
+
+ public void Append(IntPtr iter)
+ {
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
+ throw new ApplicationException("Failed to append INT16 argument:" + val);
+ }
+
+ public static bool Suits(System.Type type)
+ {
+ if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Int16)) {
+ return true;
+ }
+
+ switch (type.ToString()) {
+ case "System.Int16":
+ case "System.Int16&":
+ return true; }
+
+ return false;
+ }
+
+ public static void EmitMarshalIn(ILGenerator generator, Type type)
+ {
+ if (type.IsByRef) {
+ generator.Emit(OpCodes.Ldind_I2);
+ }
+ }
+
+ public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
+ {
+ generator.Emit(OpCodes.Unbox, type);
+ generator.Emit(OpCodes.Ldind_I2);
+ if (!isReturn) {
+ generator.Emit(OpCodes.Stind_I2);
+ }
+ }
+
+ public object Get()
+ {
+ return this.val;
+ }
+
+ public object Get(System.Type type)
+ {
+ if (type.IsEnum) {
+ return Enum.ToObject(type, this.val);
+ }
+
+ switch (type.ToString()) {
+ case "System.Int16":
+ case "System.Int16&":
+ return this.val;
+ default:
+ throw new ArgumentException("Cannot cast DBus.Type.Int16 to type '" + type.ToString() + "'");
+ }
+ }
+
+ [DllImport("dbus-1")]
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int16 value);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int16 value);
+ }
+}
diff --git a/mono/DBusType/UInt16.cs b/mono/DBusType/UInt16.cs
new file mode 100644
index 00000000..73132875
--- /dev/null
+++ b/mono/DBusType/UInt16.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection.Emit;
+
+using DBus;
+
+namespace DBus.DBusType
+{
+ /// <summary>
+ /// 16-bit integer.
+ /// </summary>
+ public class UInt16 : IDBusType
+ {
+ public const char Code = 'q';
+ private System.UInt16 val;
+
+ private UInt16()
+ {
+ }
+
+ public UInt16(System.UInt16 val, Service service)
+ {
+ this.val = val;
+ }
+
+ public UInt16(IntPtr iter, Service service)
+ {
+ dbus_message_iter_get_basic (iter, out this.val);
+ }
+
+ public void Append(IntPtr iter)
+ {
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
+ throw new ApplicationException("Failed to append INT16 argument:" + val);
+ }
+
+ public static bool Suits(System.Type type)
+ {
+ if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt16)) {
+ return true;
+ }
+
+ switch (type.ToString()) {
+ case "System.UInt16":
+ case "System.UInt16&":
+ return true; }
+
+ return false;
+ }
+
+ public static void EmitMarshalIn(ILGenerator generator, Type type)
+ {
+ if (type.IsByRef) {
+ generator.Emit(OpCodes.Ldind_U2);
+ }
+ }
+
+ public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
+ {
+ generator.Emit(OpCodes.Unbox, type);
+ generator.Emit(OpCodes.Ldind_U2);
+ if (!isReturn) {
+ generator.Emit(OpCodes.Stind_I2);
+ }
+ }
+
+ public object Get()
+ {
+ return this.val;
+ }
+
+ public object Get(System.Type type)
+ {
+ if (type.IsEnum) {
+ return Enum.ToObject(type, this.val);
+ }
+
+ switch (type.ToString()) {
+ case "System.UInt16":
+ case "System.UInt16&":
+ return this.val;
+ default:
+ throw new ArgumentException("Cannot cast DBus.Type.UInt16 to type '" + type.ToString() + "'");
+ }
+ }
+
+ [DllImport("dbus-1")]
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt16 value);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt16 value);
+ }
+}
diff --git a/mono/Makefile.am b/mono/Makefile.am
index 02223f1a..239a3869 100644
--- a/mono/Makefile.am
+++ b/mono/Makefile.am
@@ -31,10 +31,12 @@ DBUS_SHARP_FILES= \
$(srcdir)/DBusType/Boolean.cs \
$(srcdir)/DBusType/Byte.cs \
$(srcdir)/DBusType/Double.cs \
+ $(srcdir)/DBusType/Int16.cs \
$(srcdir)/DBusType/Int32.cs \
$(srcdir)/DBusType/Int64.cs \
$(srcdir)/DBusType/ObjectPath.cs \
$(srcdir)/DBusType/String.cs \
+ $(srcdir)/DBusType/UInt16.cs \
$(srcdir)/DBusType/UInt32.cs \
$(srcdir)/DBusType/UInt64.cs