// 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 FormatterSaveToURIMethodNative(IntPtr formatter, IntPtr timeline, IntPtr uri, bool overwrite, out IntPtr error);

	internal class FormatterSaveToURIMethodInvoker {

		FormatterSaveToURIMethodNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal FormatterSaveToURIMethodInvoker (FormatterSaveToURIMethodNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal FormatterSaveToURIMethodInvoker (FormatterSaveToURIMethodNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		bool InvokeNative (GES.Formatter formatter, GES.Timeline timeline, string uri, bool overwrite)
		{
			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, overwrite, out error);
			GLib.Marshaller.Free (native_uri);
			return __result;
		}
	}

	internal class FormatterSaveToURIMethodWrapper {

		public bool NativeCallback (IntPtr formatter, IntPtr timeline, IntPtr uri, bool overwrite, 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), overwrite);
				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 FormatterSaveToURIMethodNative NativeDelegate;
		GES.FormatterSaveToURIMethod managed;

		public FormatterSaveToURIMethodWrapper (GES.FormatterSaveToURIMethod managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new FormatterSaveToURIMethodNative (NativeCallback);
		}

		public static GES.FormatterSaveToURIMethod GetManagedDelegate (FormatterSaveToURIMethodNative native)
		{
			if (native == null)
				return null;
			FormatterSaveToURIMethodWrapper wrapper = (FormatterSaveToURIMethodWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
