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

namespace GLib {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class ProxyResolverAdapter : GLib.GInterfaceAdapter, GLib.IProxyResolver {

		[StructLayout (LayoutKind.Sequential)]
		struct GProxyResolverInterface {
			public IsSupportedNativeDelegate IsSupported;
			public LookupNativeDelegate Lookup;
			public LookupAsyncNativeDelegate LookupAsync;
			public LookupFinishNativeDelegate LookupFinish;
		}

		static GProxyResolverInterface iface;

		static ProxyResolverAdapter ()
		{
			GLib.GType.Register (_gtype, typeof (ProxyResolverAdapter));
			iface.IsSupported = new IsSupportedNativeDelegate (IsSupported_cb);
			iface.Lookup = new LookupNativeDelegate (Lookup_cb);
			iface.LookupAsync = new LookupAsyncNativeDelegate (LookupAsync_cb);
			iface.LookupFinish = new LookupFinishNativeDelegate (LookupFinish_cb);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool IsSupportedNativeDelegate (IntPtr inst);

		static bool IsSupported_cb (IntPtr inst)
		{
			try {
				IProxyResolverImplementor __obj = GLib.Object.GetObject (inst, false) as IProxyResolverImplementor;
				bool __result;
				__result = __obj.IsSupported;
				return __result;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr LookupNativeDelegate (IntPtr inst, IntPtr uri, IntPtr cancellable, out IntPtr error);

		static IntPtr Lookup_cb (IntPtr inst, IntPtr uri, IntPtr cancellable, out IntPtr error)
		{
			error = IntPtr.Zero;

			try {
				IProxyResolverImplementor __obj = GLib.Object.GetObject (inst, false) as IProxyResolverImplementor;
				string __result;
				__result = __obj.Lookup (GLib.Marshaller.Utf8PtrToString (uri), GLib.Object.GetObject(cancellable) as GLib.Cancellable);
				return GLib.Marshaller.StringToPtrGStrdup(__result);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void LookupAsyncNativeDelegate (IntPtr inst, IntPtr uri, IntPtr cancellable, GLibSharp.AsyncReadyCallbackNative cb, IntPtr user_data);

		static void LookupAsync_cb (IntPtr inst, IntPtr uri, IntPtr cancellable, GLibSharp.AsyncReadyCallbackNative cb, IntPtr user_data)
		{
			try {
				IProxyResolverImplementor __obj = GLib.Object.GetObject (inst, false) as IProxyResolverImplementor;
				GLibSharp.AsyncReadyCallbackInvoker cb_invoker = new GLibSharp.AsyncReadyCallbackInvoker (cb, user_data);
				__obj.LookupAsync (GLib.Marshaller.Utf8PtrToString (uri), GLib.Object.GetObject(cancellable) as GLib.Cancellable, cb_invoker.Handler);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr LookupFinishNativeDelegate (IntPtr inst, IntPtr result, out IntPtr error);

		static IntPtr LookupFinish_cb (IntPtr inst, IntPtr result, out IntPtr error)
		{
			error = IntPtr.Zero;

			try {
				IProxyResolverImplementor __obj = GLib.Object.GetObject (inst, false) as IProxyResolverImplementor;
				string __result;
				__result = __obj.LookupFinish (GLib.AsyncResultAdapter.GetObject (result, false));
				return GLib.Marshaller.StringToPtrGStrdup(__result);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		static int class_offset = 2 * IntPtr.Size;

		static void Initialize (IntPtr ptr, IntPtr data)
		{
			IntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);
			GProxyResolverInterface native_iface = (GProxyResolverInterface) Marshal.PtrToStructure (ifaceptr, typeof (GProxyResolverInterface));
			native_iface.IsSupported = iface.IsSupported;
			native_iface.Lookup = iface.Lookup;
			native_iface.LookupAsync = iface.LookupAsync;
			native_iface.LookupFinish = iface.LookupFinish;
			Marshal.StructureToPtr (native_iface, ifaceptr, false);
		}

		GLib.Object implementor;

		public ProxyResolverAdapter ()
		{
			InitHandler = new GLib.GInterfaceInitHandler (Initialize);
		}

		public ProxyResolverAdapter (IProxyResolverImplementor implementor)
		{
			if (implementor == null)
				throw new ArgumentNullException ("implementor");
			else if (!(implementor is GLib.Object))
				throw new ArgumentException ("implementor must be a subclass of GLib.Object");
			this.implementor = implementor as GLib.Object;
		}

		public ProxyResolverAdapter (IntPtr handle)
		{
			if (!_gtype.IsInstance (handle))
				throw new ArgumentException ("The gobject doesn't implement the GInterface of this adapter", "handle");
			implementor = GLib.Object.GetObject (handle);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_g_proxy_resolver_get_type();
		static d_g_proxy_resolver_get_type g_proxy_resolver_get_type = FuncLoader.LoadFunction<d_g_proxy_resolver_get_type>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_get_type"));

		private static GLib.GType _gtype = new GLib.GType (g_proxy_resolver_get_type ());

		public static GLib.GType GType {
			get {
				return _gtype;
			}
		}

		public override GLib.GType GInterfaceGType {
			get {
				return _gtype;
			}
		}

		public override IntPtr Handle {
			get {
				return implementor.Handle;
			}
		}

		public IntPtr OwnedHandle {
			get {
				return implementor.OwnedHandle;
			}
		}

		public static IProxyResolver GetObject (IntPtr handle, bool owned)
		{
			GLib.Object obj = GLib.Object.GetObject (handle, owned);
			return GetObject (obj);
		}

		public static IProxyResolver GetObject (GLib.Object obj)
		{
			if (obj == null)
				return null;
			else if (obj is IProxyResolverImplementor)
				return new ProxyResolverAdapter (obj as IProxyResolverImplementor);
			else if (obj as IProxyResolver == null)
				return new ProxyResolverAdapter (obj.Handle);
			else
				return obj as IProxyResolver;
		}

		public IProxyResolverImplementor Implementor {
			get {
				return implementor as IProxyResolverImplementor;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_g_proxy_resolver_get_default();
		static d_g_proxy_resolver_get_default g_proxy_resolver_get_default = FuncLoader.LoadFunction<d_g_proxy_resolver_get_default>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_get_default"));

		public static GLib.IProxyResolver Default { 
			get {
				IntPtr raw_ret = g_proxy_resolver_get_default();
				GLib.IProxyResolver ret = GLib.ProxyResolverAdapter.GetObject (raw_ret, false);
				return ret;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool d_g_proxy_resolver_is_supported(IntPtr raw);
		static d_g_proxy_resolver_is_supported g_proxy_resolver_is_supported = FuncLoader.LoadFunction<d_g_proxy_resolver_is_supported>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_is_supported"));

		public bool IsSupported { 
			get {
				bool raw_ret = g_proxy_resolver_is_supported(Handle);
				bool ret = raw_ret;
				return ret;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_g_proxy_resolver_lookup(IntPtr raw, IntPtr uri, IntPtr cancellable, out IntPtr error);
		static d_g_proxy_resolver_lookup g_proxy_resolver_lookup = FuncLoader.LoadFunction<d_g_proxy_resolver_lookup>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_lookup"));

		public string Lookup(string uri, GLib.Cancellable cancellable) {
			IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup (uri);
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_proxy_resolver_lookup(Handle, native_uri, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);
			string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
			GLib.Marshaller.Free (native_uri);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_g_proxy_resolver_lookup_async(IntPtr raw, IntPtr uri, IntPtr cancellable, GLibSharp.AsyncReadyCallbackNative cb, IntPtr user_data);
		static d_g_proxy_resolver_lookup_async g_proxy_resolver_lookup_async = FuncLoader.LoadFunction<d_g_proxy_resolver_lookup_async>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_lookup_async"));

		public void LookupAsync(string uri, GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb) {
			IntPtr native_uri = GLib.Marshaller.StringToPtrGStrdup (uri);
			GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper (cb);
			cb_wrapper.PersistUntilCalled ();
			g_proxy_resolver_lookup_async(Handle, native_uri, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
			GLib.Marshaller.Free (native_uri);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_g_proxy_resolver_lookup_finish(IntPtr raw, IntPtr result, out IntPtr error);
		static d_g_proxy_resolver_lookup_finish g_proxy_resolver_lookup_finish = FuncLoader.LoadFunction<d_g_proxy_resolver_lookup_finish>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_proxy_resolver_lookup_finish"));

		public string LookupFinish(GLib.IAsyncResult result) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_proxy_resolver_lookup_finish(Handle, result == null ? IntPtr.Zero : ((result is GLib.Object) ? (result as GLib.Object).Handle : (result as GLib.AsyncResultAdapter).Handle), out error);
			string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

#endregion
	}
}
