// 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 FormatterCanLoadURIMethodNative(IntPtr dummy_instance, IntPtr uri, out IntPtr error);

	internal class FormatterCanLoadURIMethodInvoker {

		FormatterCanLoadURIMethodNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal FormatterCanLoadURIMethodInvoker (FormatterCanLoadURIMethodNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal FormatterCanLoadURIMethodInvoker (FormatterCanLoadURIMethodNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

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

	internal class FormatterCanLoadURIMethodWrapper {

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

			try {
				bool __ret = managed (GLib.Object.GetObject(dummy_instance) as GES.Formatter, 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 FormatterCanLoadURIMethodNative NativeDelegate;
		GES.FormatterCanLoadURIMethod managed;

		public FormatterCanLoadURIMethodWrapper (GES.FormatterCanLoadURIMethod managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new FormatterCanLoadURIMethodNative (NativeCallback);
		}

		public static GES.FormatterCanLoadURIMethod GetManagedDelegate (FormatterCanLoadURIMethodNative native)
		{
			if (native == null)
				return null;
			FormatterCanLoadURIMethodWrapper wrapper = (FormatterCanLoadURIMethodWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
