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

namespace GESSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
	internal delegate bool FormatterLoadFromURIMethodNative(IntPtr formatter, IntPtr timeline, IntPtr uri, out IntPtr error);

	internal class FormatterLoadFromURIMethodInvoker {

		FormatterLoadFromURIMethodNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal FormatterLoadFromURIMethodInvoker (FormatterLoadFromURIMethodNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal FormatterLoadFromURIMethodInvoker (FormatterLoadFromURIMethodNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

		internal GES.FormatterLoadFromURIMethod Handler {
			get {
				return new GES.FormatterLoadFromURIMethod(InvokeNative);
			}
		}

		bool InvokeNative (GES.Formatter formatter, GES.Timeline timeline, string uri)
		{
			IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup (uri);
			IntPtr error = IntPtr.Zero;
			bool __result = native_cb (formatter == null ? IntPtr.Zero : formatter.Handle, timeline == null ? IntPtr.Zero : timeline.Handle, native_uri, out error);
			GLib.Marshaller.Free (native_uri);
			return __result;
		}
	}

	internal class FormatterLoadFromURIMethodWrapper {

		public bool NativeCallback (IntPtr formatter, IntPtr timeline, IntPtr uri, out IntPtr error)
		{
			error = IntPtr.Zero;

			try {
				bool __ret = managed (GLib.Object.GetObject(formatter) as GES.Formatter, GLib.Object.GetObject(timeline) as GES.Timeline, GLib.Marshaller.Utf8PtrToString (uri));
				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 FormatterLoadFromURIMethodNative NativeDelegate;
		GES.FormatterLoadFromURIMethod managed;

		public FormatterLoadFromURIMethodWrapper (GES.FormatterLoadFromURIMethod managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new FormatterLoadFromURIMethodNative (NativeCallback);
		}

		public static GES.FormatterLoadFromURIMethod GetManagedDelegate (FormatterLoadFromURIMethodNative native)
		{
			if (native == null)
				return null;
			FormatterLoadFromURIMethodWrapper wrapper = (FormatterLoadFromURIMethodWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
