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 Boolean : IDBusType 00013 { 00014 public const char Code = 'b'; 00015 private System.Boolean val; 00016 00017 private Boolean() 00018 { 00019 } 00020 00021 public Boolean(System.Boolean val, Service service) 00022 { 00023 this.val = val; 00024 } 00025 00026 public Boolean(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 BOOLEAN argument:" + val); 00035 } 00036 00037 public static bool Suits(System.Type type) 00038 { 00039 switch (type.ToString()) { 00040 case "System.Boolean": 00041 case "System.Boolean&": 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_I1); 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_I1); 00059 if (!isReturn) { 00060 generator.Emit(OpCodes.Stind_I1); 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.Boolean": 00073 case "System.Boolean&": 00074 return this.val; 00075 default: 00076 throw new ArgumentException("Cannot cast DBus.Type.Boolean to type '" + type.ToString() + "'"); 00077 } 00078 } 00079 00080 [DllImport("dbus-1")] 00081 private extern static void dbus_message_iter_get_basic (IntPtr iter, out bool value); 00082 00083 [DllImport("dbus-1")] 00084 private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref bool value); 00085 } 00086 }