// 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 bool RTSPSendListFuncNative(IntPtr buffer_list, byte channel, IntPtr user_data);

	internal class RTSPSendListFuncInvoker {

		RTSPSendListFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal RTSPSendListFuncInvoker (RTSPSendListFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal RTSPSendListFuncInvoker (RTSPSendListFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		bool InvokeNative (Gst.BufferList buffer_list, byte channel)
		{
			bool __result = native_cb (buffer_list == null ? IntPtr.Zero : buffer_list.Handle, channel, __data);
			return __result;
		}
	}

	internal class RTSPSendListFuncWrapper {

		public bool NativeCallback (IntPtr buffer_list, byte channel, IntPtr user_data)
		{
			try {
				bool __ret = managed (buffer_list == IntPtr.Zero ? null : (Gst.BufferList) GLib.Opaque.GetOpaque (buffer_list, typeof (Gst.BufferList), false), channel);
				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 RTSPSendListFuncNative NativeDelegate;
		Gst.RtspServer.RTSPSendListFunc managed;

		public RTSPSendListFuncWrapper (Gst.RtspServer.RTSPSendListFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new RTSPSendListFuncNative (NativeCallback);
		}

		public static Gst.RtspServer.RTSPSendListFunc GetManagedDelegate (RTSPSendListFuncNative native)
		{
			if (native == null)
				return null;
			RTSPSendListFuncWrapper wrapper = (RTSPSendListFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}