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

namespace GLibSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	internal delegate IntPtr DBusProxyTypeFuncNative(IntPtr manager, IntPtr object_path, IntPtr interface_name, IntPtr user_data);

	internal class DBusProxyTypeFuncInvoker {

		DBusProxyTypeFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal DBusProxyTypeFuncInvoker (DBusProxyTypeFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal DBusProxyTypeFuncInvoker (DBusProxyTypeFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

		internal GLib.DBusProxyTypeFunc Handler {
			get {
				return new GLib.DBusProxyTypeFunc(InvokeNative);
			}
		}

		GLib.GType InvokeNative (GLib.DBusObjectManagerClient manager, string object_path, string interface_name)
		{
			IntPtr native_object_path = GLib.Marshaller.StringToPtrGStrdup (object_path);
			IntPtr native_interface_name = GLib.Marshaller.StringToPtrGStrdup (interface_name);
			GLib.GType __result = new GLib.GType(native_cb (manager == null ? IntPtr.Zero : manager.Handle, native_object_path, native_interface_name, __data));
			GLib.Marshaller.Free (native_object_path);
			GLib.Marshaller.Free (native_interface_name);
			return __result;
		}
	}

	internal class DBusProxyTypeFuncWrapper {

		public IntPtr NativeCallback (IntPtr manager, IntPtr object_path, IntPtr interface_name, IntPtr user_data)
		{
			try {
				GLib.GType __ret = managed (manager == IntPtr.Zero ? null : (GLib.DBusObjectManagerClient) GLib.Opaque.GetOpaque (manager, typeof (GLib.DBusObjectManagerClient), false), GLib.Marshaller.Utf8PtrToString (object_path), GLib.Marshaller.Utf8PtrToString (interface_name));
				if (release_on_call)
					gch.Free ();
				return __ret.Val;
			} 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 DBusProxyTypeFuncNative NativeDelegate;
		GLib.DBusProxyTypeFunc managed;

		public DBusProxyTypeFuncWrapper (GLib.DBusProxyTypeFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new DBusProxyTypeFuncNative (NativeCallback);
		}

		public static GLib.DBusProxyTypeFunc GetManagedDelegate (DBusProxyTypeFuncNative native)
		{
			if (native == null)
				return null;
			DBusProxyTypeFuncWrapper wrapper = (DBusProxyTypeFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
