// 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 RTSPClientSessionFilterFuncNative(IntPtr client, IntPtr sess, IntPtr user_data);

	internal class RTSPClientSessionFilterFuncInvoker {

		RTSPClientSessionFilterFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal RTSPClientSessionFilterFuncInvoker (RTSPClientSessionFilterFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal RTSPClientSessionFilterFuncInvoker (RTSPClientSessionFilterFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		Gst.RtspServer.RTSPFilterResult InvokeNative (Gst.RtspServer.RTSPClient client, Gst.RtspServer.RTSPSession sess)
		{
			Gst.RtspServer.RTSPFilterResult __result = (Gst.RtspServer.RTSPFilterResult) native_cb (client == null ? IntPtr.Zero : client.Handle, sess == null ? IntPtr.Zero : sess.Handle, __data);
			return __result;
		}
	}

	internal class RTSPClientSessionFilterFuncWrapper {

		public int NativeCallback (IntPtr client, IntPtr sess, IntPtr user_data)
		{
			try {
				Gst.RtspServer.RTSPFilterResult __ret = managed (GLib.Object.GetObject(client) as Gst.RtspServer.RTSPClient, GLib.Object.GetObject(sess) as Gst.RtspServer.RTSPSession);
				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 RTSPClientSessionFilterFuncNative NativeDelegate;
		Gst.RtspServer.RTSPClientSessionFilterFunc managed;

		public RTSPClientSessionFilterFuncWrapper (Gst.RtspServer.RTSPClientSessionFilterFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new RTSPClientSessionFilterFuncNative (NativeCallback);
		}

		public static Gst.RtspServer.RTSPClientSessionFilterFunc GetManagedDelegate (RTSPClientSessionFilterFuncNative native)
		{
			if (native == null)
				return null;
			RTSPClientSessionFilterFuncWrapper wrapper = (RTSPClientSessionFilterFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
