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

namespace GstSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
	internal delegate bool PluginFeatureFilterNative(IntPtr feature, IntPtr user_data);

	internal class PluginFeatureFilterInvoker {

		PluginFeatureFilterNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal PluginFeatureFilterInvoker (PluginFeatureFilterNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal PluginFeatureFilterInvoker (PluginFeatureFilterNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		bool InvokeNative (Gst.PluginFeature feature)
		{
			bool __result = native_cb (feature == null ? IntPtr.Zero : feature.Handle, __data);
			return __result;
		}
	}

	internal class PluginFeatureFilterWrapper {

		public bool NativeCallback (IntPtr feature, IntPtr user_data)
		{
			try {
				bool __ret = managed (GLib.Object.GetObject(feature) as Gst.PluginFeature);
				if (release_on_call)
					gch.Free ();
				return __ret;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
				return false;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

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

		internal PluginFeatureFilterNative NativeDelegate;
		Gst.PluginFeatureFilter managed;

		public PluginFeatureFilterWrapper (Gst.PluginFeatureFilter managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new PluginFeatureFilterNative (NativeCallback);
		}

		public static Gst.PluginFeatureFilter GetManagedDelegate (PluginFeatureFilterNative native)
		{
			if (native == null)
				return null;
			PluginFeatureFilterWrapper wrapper = (PluginFeatureFilterWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
