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

namespace GtkSourceSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	internal delegate IntPtr MountOperationFactoryNative(IntPtr file, IntPtr userdata);

	internal class MountOperationFactoryInvoker {

		MountOperationFactoryNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal MountOperationFactoryInvoker (MountOperationFactoryNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal MountOperationFactoryInvoker (MountOperationFactoryNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

		internal GtkSource.MountOperationFactory Handler {
			get {
				return new GtkSource.MountOperationFactory(InvokeNative);
			}
		}

		GLib.MountOperation InvokeNative (GtkSource.File file)
		{
			GLib.MountOperation __result = GLib.Object.GetObject(native_cb (file == null ? IntPtr.Zero : file.Handle, __data)) as GLib.MountOperation;
			return __result;
		}
	}

	internal class MountOperationFactoryWrapper {

		public IntPtr NativeCallback (IntPtr file, IntPtr userdata)
		{
			try {
				GLib.MountOperation __ret = managed (GLib.Object.GetObject(file) as GtkSource.File);
				if (release_on_call)
					gch.Free ();
				return __ret == null ? IntPtr.Zero : __ret.Handle;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: Above call does not return.
				throw;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

		public void PersistUntilCalled ()
		{
			release_on_call = true;
			gch = GCHandle.Alloc (this);
		}

		internal MountOperationFactoryNative NativeDelegate;
		GtkSource.MountOperationFactory managed;

		public MountOperationFactoryWrapper (GtkSource.MountOperationFactory managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new MountOperationFactoryNative (NativeCallback);
		}

		public static GtkSource.MountOperationFactory GetManagedDelegate (MountOperationFactoryNative native)
		{
			if (native == null)
				return null;
			MountOperationFactoryWrapper wrapper = (MountOperationFactoryWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
