mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-04-20 04:50:48 +02:00
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.
This commit is contained in:
parent
76faf9aa9c
commit
24c6ddc1a4
5 changed files with 221 additions and 4 deletions
12
ChangeLog
12
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
93
mono/DBusType/Int16.cs
Normal file
93
mono/DBusType/Int16.cs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
93
mono/DBusType/UInt16.cs
Normal file
93
mono/DBusType/UInt16.cs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue