Made all DBusTypes take Service in the constructor because Array also needed it in...
[platform/upstream/dbus.git] / mono / DBusType / Int64.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Reflection.Emit;
4
5 using DBus;
6
7 namespace DBus.DBusType
8 {
9   /// <summary>
10   /// 64-bit integer.
11   /// </summary>
12   public class Int64 : IDBusType
13   {
14     public const char Code = 'x';
15     private System.Int64 val;
16     
17     private Int64()
18     {
19     }
20     
21     public Int64(System.Int64 val, Service service) 
22     {
23       this.val = val;
24     }
25
26     public Int64(IntPtr iter, Service service)
27     {
28       this.val = dbus_message_iter_get_int64(iter);
29     }
30     
31     public void Append(IntPtr iter)
32     {
33       if (!dbus_message_iter_append_int64(iter, val))
34         throw new ApplicationException("Failed to append INT64 argument:" + val);
35     }
36
37     public static bool Suits(System.Type type) 
38     {
39       switch (type.ToString()) {
40       case "System.Int64":
41       case "System.Int64&":
42         return true;
43       }
44       
45       return false;
46     }
47
48     public static void EmitMarshalIn(ILGenerator generator, Type type)
49     {
50       if (type.IsByRef) {
51         generator.Emit(OpCodes.Ldind_I8);
52       }
53     }
54
55     public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) 
56     {
57       generator.Emit(OpCodes.Unbox, type);
58       generator.Emit(OpCodes.Ldind_I8);
59       if (!isReturn) {
60         generator.Emit(OpCodes.Stind_I8);
61       }
62     }
63     
64     public object Get() 
65     {
66       return this.val;
67     }
68
69     public object Get(System.Type type)
70     {
71       switch (type.ToString()) {
72       case "System.Int64":
73       case "System.Int64&":
74         return this.val;
75       default:
76         throw new ArgumentException("Cannot cast DBus.Type.Int64 to type '" + type.ToString() + "'");
77       }
78     }    
79
80     [DllImport("dbus-1")]
81     private extern static System.Int64 dbus_message_iter_get_int64(IntPtr iter);
82  
83     [DllImport("dbus-1")]
84     private extern static bool dbus_message_iter_append_int64(IntPtr iter, System.Int64 value);
85   }
86 }