00001 using System;
00002 using System.Runtime.InteropServices;
00003 using System.Reflection.Emit;
00004
00005 using DBus;
00006
00007 namespace DBus.DBusType
00008 {
00012 public class Double : IDBusType
00013 {
00014 public const char Code = 'd';
00015 private System.Double val;
00016
00017 private Double()
00018 {
00019 }
00020
00021 public Double(System.Double val, Service service)
00022 {
00023 this.val = val;
00024 }
00025
00026 public Double(IntPtr iter, Service service)
00027 {
00028 dbus_message_iter_get_basic (iter, out this.val);
00029 }
00030
00031 public void Append(IntPtr iter)
00032 {
00033 if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
00034 throw new ApplicationException("Failed to append DOUBLE argument:" + val);
00035 }
00036
00037 public static bool Suits(System.Type type)
00038 {
00039 switch (type.ToString()) {
00040 case "System.Double":
00041 case "System.Double&":
00042 return true;
00043 }
00044
00045 return false;
00046 }
00047
00048 public static void EmitMarshalIn(ILGenerator generator, Type type)
00049 {
00050 if (type.IsByRef) {
00051 generator.Emit(OpCodes.Ldind_R8);
00052 }
00053 }
00054
00055 public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
00056 {
00057 generator.Emit(OpCodes.Unbox, type);
00058 generator.Emit(OpCodes.Ldind_R8);
00059 if (!isReturn) {
00060 generator.Emit(OpCodes.Stind_R8);
00061 }
00062 }
00063
00064 public object Get()
00065 {
00066 return this.val;
00067 }
00068
00069 public object Get(System.Type type)
00070 {
00071 switch (type.ToString()) {
00072 case "System.Double":
00073 case "System.Double&":
00074 return this.val;
00075 default:
00076 throw new ArgumentException("Cannot cast DBus.Type.Double to type '" + type.ToString() + "'");
00077 }
00078 }
00079
00080 [DllImport("dbus-1")]
00081 private extern static void dbus_message_iter_get_basic (IntPtr iter, out double value);
00082
00083 [DllImport("dbus-1")]
00084 private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref double value);
00085 }
00086 }