From 11920f2addbe8c6cad5b78bfd4afe84a5f858031 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 5 Jul 2014 13:00:50 +0200 Subject: [PATCH] glib: Re-organize code in Source for better readability Move stuff around to have them in a reasonable order: fields, then constructors, then destructor, then static methods, then instance stuff. Also remove a commented out method, which would not be correct anyway. No real code change here, just cosmetic changes. --- glib/Source.cs | 114 ++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 64 deletions(-) diff --git a/glib/Source.cs b/glib/Source.cs index b39755c5e..c28e54c5f 100644 --- a/glib/Source.cs +++ b/glib/Source.cs @@ -46,10 +46,46 @@ namespace GLib { public partial class Source : GLib.Opaque { + internal static Hashtable source_handlers = new Hashtable (); + private Source () {} - internal static Hashtable source_handlers = new Hashtable (); - + public Source(IntPtr raw) : base(raw) {} + + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr g_source_new(IntPtr source_funcs, uint struct_size); + + public Source (GLib.SourceFuncs source_funcs, uint struct_size) + { + IntPtr native_source_funcs = GLib.Marshaller.StructureToPtrAlloc (source_funcs); + Raw = g_source_new(native_source_funcs, struct_size); + source_funcs = GLib.SourceFuncs.New (native_source_funcs); + Marshal.FreeHGlobal (native_source_funcs); + } + + class FinalizerInfo { + IntPtr handle; + + public FinalizerInfo (IntPtr handle) + { + this.handle = handle; + } + + public bool Handler () + { + g_source_destroy (handle); + return false; + } + } + + ~Source () + { + if (!Owned) + return; + FinalizerInfo info = new FinalizerInfo (Handle); + GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler)); + } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern bool g_source_remove (uint tag); @@ -60,6 +96,17 @@ namespace GLib { return g_source_remove (tag); } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr g_source_get_type(); + + public static GLib.GType GType { + get { + IntPtr raw_ret = g_source_get_type(); + GLib.GType ret = new GLib.GType(raw_ret); + return ret; + } + } + [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern IntPtr g_source_get_context(IntPtr raw); @@ -107,17 +154,6 @@ namespace GLib { } } - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr g_source_get_type(); - - public static GLib.GType GType { - get { - IntPtr raw_ret = g_source_get_type(); - GLib.GType ret = new GLib.GType(raw_ret); - return ret; - } - } - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern void g_source_add_child_source(IntPtr raw, IntPtr child_source); @@ -288,19 +324,6 @@ namespace GLib { } } - /* - * commented out because there is already a custom implementation for Remove - * - [DllImport (Global.GLibNativeLib, CallingConvention = CallingConvention.Cdecl)] - static extern bool g_source_remove(uint tag); - - public static bool Remove(uint tag) { - bool raw_ret = g_source_remove(tag); - bool ret = raw_ret; - return ret; - } - */ - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern bool g_source_remove_by_funcs_user_data(IntPtr funcs, IntPtr user_data); @@ -331,19 +354,6 @@ namespace GLib { GLib.Marshaller.Free (native_name); } - public Source(IntPtr raw) : base(raw) {} - - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr g_source_new(IntPtr source_funcs, uint struct_size); - - public Source (GLib.SourceFuncs source_funcs, uint struct_size) - { - IntPtr native_source_funcs = GLib.Marshaller.StructureToPtrAlloc (source_funcs); - Raw = g_source_new(native_source_funcs, struct_size); - source_funcs = GLib.SourceFuncs.New (native_source_funcs); - Marshal.FreeHGlobal (native_source_funcs); - } - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern IntPtr g_source_ref(IntPtr raw); @@ -373,29 +383,5 @@ namespace GLib { { g_source_destroy (raw); } - - class FinalizerInfo { - IntPtr handle; - - public FinalizerInfo (IntPtr handle) - { - this.handle = handle; - } - - public bool Handler () - { - g_source_destroy (handle); - return false; - } - } - - ~Source () - { - if (!Owned) - return; - FinalizerInfo info = new FinalizerInfo (Handle); - GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler)); - } } - -} \ No newline at end of file +}