// 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 void TagMergeFuncNative(IntPtr dest, IntPtr src);

	internal class TagMergeFuncInvoker {

		TagMergeFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal TagMergeFuncInvoker (TagMergeFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal TagMergeFuncInvoker (TagMergeFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (GLib.Value dest, GLib.Value src)
		{
			IntPtr native_dest = GLib.Marshaller.StructureToPtrAlloc (dest);
			IntPtr native_src = GLib.Marshaller.StructureToPtrAlloc (src);
			native_cb (native_dest, native_src);
			Marshal.FreeHGlobal (native_dest);
			Marshal.FreeHGlobal (native_src);
		}
	}

	internal class TagMergeFuncWrapper {

		public void NativeCallback (IntPtr dest, IntPtr src)
		{
			try {
				managed ((GLib.Value) Marshal.PtrToStructure (dest, typeof (GLib.Value)), (GLib.Value) Marshal.PtrToStructure (src, typeof (GLib.Value)));
				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 TagMergeFuncNative NativeDelegate;
		Gst.TagMergeFunc managed;

		public TagMergeFuncWrapper (Gst.TagMergeFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new TagMergeFuncNative (NativeCallback);
		}

		public static Gst.TagMergeFunc GetManagedDelegate (TagMergeFuncNative native)
		{
			if (native == null)
				return null;
			TagMergeFuncWrapper wrapper = (TagMergeFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
