summaryrefslogtreecommitdiffstats
path: root/mono/DBusType/Int32.cs
diff options
context:
space:
mode:
Diffstat (limited to 'mono/DBusType/Int32.cs')
-rw-r--r--mono/DBusType/Int32.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/mono/DBusType/Int32.cs b/mono/DBusType/Int32.cs
new file mode 100644
index 00000000..b617a9a0
--- /dev/null
+++ b/mono/DBusType/Int32.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection.Emit;
+
+using DBus;
+
+namespace DBus.DBusType
+{
+ /// <summary>
+ /// 32-bit integer.
+ /// </summary>
+ public class Int32 : IDBusType
+ {
+ public const char Code = 'i';
+ private System.Int32 val;
+
+ private Int32()
+ {
+ }
+
+ public Int32(System.Int32 val)
+ {
+ this.val = val;
+ }
+
+ public Int32(IntPtr iter)
+ {
+ this.val = dbus_message_iter_get_int32(iter);
+ }
+
+ public void Append(IntPtr iter)
+ {
+ if (!dbus_message_iter_append_int32(iter, val))
+ throw new ApplicationException("Failed to append INT32 argument:" + val);
+ }
+
+ public static bool Suits(System.Type type)
+ {
+ switch (type.ToString()) {
+ case "System.Int32":
+ case "System.Int32&":
+ return true;
+ }
+
+ return false;
+ }
+
+ public static void EmitMarshalIn(ILGenerator generator, Type type)
+ {
+ if (type.IsByRef) {
+ generator.Emit(OpCodes.Ldind_I4);
+ }
+ }
+
+ public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
+ {
+ generator.Emit(OpCodes.Unbox, type);
+ generator.Emit(OpCodes.Ldind_I4);
+ if (!isReturn) {
+ generator.Emit(OpCodes.Stind_I4);
+ }
+ }
+
+ public object Get()
+ {
+ return this.val;
+ }
+
+ public object Get(System.Type type)
+ {
+ switch (type.ToString()) {
+ case "System.Int32":
+ case "System.Int32&":
+ return this.val;
+ default:
+ throw new ArgumentException("Cannot cast DBus.Type.Int32 to type '" + type.ToString() + "'");
+ }
+ }
+
+ [DllImport("dbus-1")]
+ private extern static System.Int32 dbus_message_iter_get_int32(IntPtr iter);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_append_int32(IntPtr iter, System.Int32 value);
+ }
+}