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

namespace Gst.RtspServerSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
	internal delegate int RTSPStreamTransportFilterFuncNative(IntPtr stream, IntPtr trans, IntPtr user_data);

	internal class RTSPStreamTransportFilterFuncInvoker {

		RTSPStreamTransportFilterFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal RTSPStreamTransportFilterFuncInvoker (RTSPStreamTransportFilterFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal RTSPStreamTransportFilterFuncInvoker (RTSPStreamTransportFilterFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		Gst.RtspServer.RTSPFilterResult InvokeNative (Gst.RtspServer.RTSPStream stream, Gst.RtspServer.RTSPStreamTransport trans)
		{
			Gst.RtspServer.RTSPFilterResult __result = (Gst.RtspServer.RTSPFilterResult) native_cb (stream == null ? IntPtr.Zero : stream.Handle, trans == null ? IntPtr.Zero : trans.Handle, __data);
			return __result;
		}
	}

	internal class RTSPStreamTransportFilterFuncWrapper {

		public int NativeCallback (IntPtr stream, IntPtr trans, IntPtr user_data)
		{
			try {
				Gst.RtspServer.RTSPFilterResult __ret = managed (GLib.Object.GetObject(stream) as Gst.RtspServer.RTSPStream, GLib.Object.GetObject(trans) as Gst.RtspServer.RTSPStreamTransport);
				if (release_on_call)
					gch.Free ();
				return (int) __ret;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: Above call does not return.
				throw e;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

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

		internal RTSPStreamTransportFilterFuncNative NativeDelegate;
		Gst.RtspServer.RTSPStreamTransportFilterFunc managed;

		public RTSPStreamTransportFilterFuncWrapper (Gst.RtspServer.RTSPStreamTransportFilterFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new RTSPStreamTransportFilterFuncNative (NativeCallback);
		}

		public static Gst.RtspServer.RTSPStreamTransportFilterFunc GetManagedDelegate (RTSPStreamTransportFilterFuncNative native)
		{
			if (native == null)
				return null;
			RTSPStreamTransportFilterFuncWrapper wrapper = (RTSPStreamTransportFilterFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
