Main Page | Modules | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Namespace Members | Data Fields | Related Pages

UInt32.cs

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 UInt32 : IDBusType
00013   {
00014     public const char Code = 'u';
00015     private System.UInt32 val;
00016     
00017     private UInt32()
00018     {
00019     }
00020     
00021     public UInt32(System.UInt32 val, Service service) 
00022     {
00023       this.val = val;
00024     }
00025 
00026     public UInt32(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 UINT32 argument:" + val);
00035     }
00036 
00037     public static bool Suits(System.Type type) 
00038     {
00039       if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt32)) {
00040         return true;
00041       }
00042 
00043       switch (type.ToString()) {
00044       case "System.UInt32":
00045       case "System.UInt32&":
00046         return true;
00047       }
00048       
00049       return false;
00050     }
00051 
00052     public static void EmitMarshalIn(ILGenerator generator, Type type)
00053     {
00054       if (type.IsByRef) {
00055         generator.Emit(OpCodes.Ldind_U4);
00056       }
00057     }
00058 
00059     public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) 
00060     {
00061       generator.Emit(OpCodes.Unbox, type);
00062       generator.Emit(OpCodes.Ldind_U4);
00063       if (!isReturn) {
00064         generator.Emit(OpCodes.Stind_I4);
00065       }
00066     }
00067     
00068     public object Get() 
00069     {
00070       return this.val;
00071     }
00072 
00073     public object Get(System.Type type)
00074     {
00075       if (type.IsEnum) {
00076         return Enum.ToObject(type, this.val);
00077       }
00078 
00079       switch (type.ToString()) 
00080         {
00081         case "System.UInt32":
00082         case "System.UInt32&":
00083           return this.val;
00084         default:
00085           throw new ArgumentException("Cannot cast DBus.Type.UInt32 to type '" + type.ToString() + "'");
00086         }
00087     }    
00088 
00089     [DllImport("dbus-1")]
00090     private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt32 value);
00091  
00092     [DllImport("dbus-1")]
00093     private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt32 value);
00094   }
00095 }

Generated on Tue Sep 13 01:28:08 2005 for D-BUS by  doxygen 1.4.4