1 // GLib.DestroyNotify.cs - internal DestroyNotify helper
2 //
3 // Author: Mike Kestner <mkestner@novell.com>
4 //
5 // Copyright (c) 2005 Novell, Inc.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of version 2 of the Lesser GNU General
9 // Public License as published by the Free Software Foundation.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this program; if not, write to the
18 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
20 
21 namespace GLib {
22 
23 	using System;
24 	using System.Runtime.InteropServices;
25 
26 	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
DestroyNotify(IntPtr data)27 	public delegate void DestroyNotify (IntPtr data);
28 
29 	public class DestroyHelper {
30 
DestroyHelper()31 		private DestroyHelper () {}
32 
ReleaseGCHandle(IntPtr data)33 		static void ReleaseGCHandle (IntPtr data)
34 		{
35 			if (data == IntPtr.Zero)
36 				return;
37 			GCHandle gch = (GCHandle) data;
38 			gch.Free ();
39 		}
40 
41 		static DestroyNotify release_gchandle;
42 
43 		public static DestroyNotify NotifyHandler {
44 			get {
45 				if (release_gchandle == null)
46 					release_gchandle = new DestroyNotify (ReleaseGCHandle);
47 				return release_gchandle;
48 			}
49 		}
50 	}
51 }
52