dbus/mono/DBusType Array.cs, 1.8, 1.9 Int16.cs, NONE, 1.1 UInt16.cs, NONE, 1.1

Joe Shaw joe at freedesktop.org
Thu Sep 8 11:54:45 PDT 2005


Update of /cvs/dbus/dbus/mono/DBusType
In directory gabe:/tmp/cvs-serv17360/mono/DBusType

Modified Files:
	Array.cs 
Added Files:
	Int16.cs UInt16.cs 
Log Message:
2005-09-08  Joe Shaw  <joeshaw at novell.com>

	Patches from James Willcox <snorp at 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.

Index: Array.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/DBusType/Array.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Array.cs	8 Mar 2005 20:45:03 -0000	1.8
+++ Array.cs	8 Sep 2005 18:54:42 -0000	1.9
@@ -17,7 +17,7 @@
     private ArrayList elements;
     private Type elementType;
     private Service service = null;
-    
+
     private Array()
     {
     }
@@ -53,14 +53,30 @@
 
       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 @@
 
     public static bool Suits(System.Type type) 
     {
-      if (type.IsArray) {
+      Type type2 = type.GetElementType ();
+      if (type.IsArray || (type2 != null && type2.IsArray)) {
 	return true;
       }
       

--- NEW FILE: Int16.cs ---
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);
  }
}

--- NEW FILE: UInt16.cs ---
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);
  }
}



More information about the dbus-commit mailing list