// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace Gst.BaseSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
	internal delegate void CollectPadsFlushFunctionNative(IntPtr pads, IntPtr user_data);

	internal class CollectPadsFlushFunctionInvoker {

		CollectPadsFlushFunctionNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

		~CollectPadsFlushFunctionInvoker ()
		{
			if (__notify == null)
				return;
			__notify (__data);
		}

		internal CollectPadsFlushFunctionInvoker (CollectPadsFlushFunctionNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal CollectPadsFlushFunctionInvoker (CollectPadsFlushFunctionNative native_cb, IntPtr data) : this (native_cb, data, null) {}

		internal CollectPadsFlushFunctionInvoker (CollectPadsFlushFunctionNative native_cb, IntPtr data, GLib.DestroyNotify notify)
		{
			this.native_cb = native_cb;
			__data = data;
			__notify = notify;
		}

		internal Gst.Base.CollectPadsFlushFunction Handler {
			get {
				return new Gst.Base.CollectPadsFlushFunction(InvokeNative);
			}
		}

		void InvokeNative (Gst.Base.CollectPads pads)
		{
			native_cb (pads == null ? IntPtr.Zero : pads.Handle, __data);
		}
	}

	internal class CollectPadsFlushFunctionWrapper {

		public void NativeCallback (IntPtr pads, IntPtr user_data)
		{
			try {
				managed (GLib.Object.GetObject(pads) as Gst.Base.CollectPads);
				if (release_on_call)
					gch.Free ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		bool release_on_call = false;
		GCHandle gch;

		public void PersistUntilCalled ()
		{
			release_on_call = true;
			gch = GCHandle.Alloc (this);
		}

		internal CollectPadsFlushFunctionNative NativeDelegate;
		Gst.Base.CollectPadsFlushFunction managed;

		public CollectPadsFlushFunctionWrapper (Gst.Base.CollectPadsFlushFunction managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new CollectPadsFlushFunctionNative (NativeCallback);
		}

		public static Gst.Base.CollectPadsFlushFunction GetManagedDelegate (CollectPadsFlushFunctionNative native)
		{
			if (native == null)
				return null;
			CollectPadsFlushFunctionWrapper wrapper = (CollectPadsFlushFunctionWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
