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

namespace GLib {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;
	using static GLib.AbiStructExtension;

#region Autogenerated code
	public partial class SocketAddressEnumerator : GLib.Object {

		public SocketAddressEnumerator (IntPtr raw) : base(raw) {}

		protected SocketAddressEnumerator() : base(IntPtr.Zero)
		{
			CreateNativeObject (Array.Empty<string> (), Array.Empty<GLib.Value> ());
		}

		static NextNativeDelegate Next_cb_delegate;
		static NextNativeDelegate NextVMCallback {
			get {
				if (Next_cb_delegate == null)
					Next_cb_delegate = new NextNativeDelegate (Next_cb);
				return Next_cb_delegate;
			}
		}

		static void OverrideNext (GLib.GType gtype)
		{
			OverrideNext (gtype, NextVMCallback);
		}

		static void OverrideNext (GLib.GType gtype, NextNativeDelegate callback)
		{
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset("next"));
				*raw_ptr = Marshal.GetFunctionPointerForDelegate(callback);
			}
		}

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

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

			try {
				SocketAddressEnumerator __obj = GLib.Object.GetObject (inst, false) as SocketAddressEnumerator;
				GLib.SocketAddress __result;
				__result = __obj.OnNext (GLib.Object.GetObject(cancellable) as GLib.Cancellable);
				return __result == null ? IntPtr.Zero : __result.Handle;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.SocketAddressEnumerator), ConnectionMethod="OverrideNext")]
		protected virtual GLib.SocketAddress OnNext (GLib.Cancellable cancellable)
		{
			return InternalNext (cancellable);
		}

		private GLib.SocketAddress InternalNext (GLib.Cancellable cancellable)
		{
			NextNativeDelegate unmanaged = class_abi.BaseOverride<NextNativeDelegate>(this.LookupGType(), "next");
			if (unmanaged == null) throw new InvalidOperationException ("No base method to invoke");

			IntPtr error = IntPtr.Zero;
			IntPtr __result = unmanaged (this.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);
			return GLib.Object.GetObject(__result) as GLib.SocketAddress;
		}

		static NextAsyncNativeDelegate NextAsync_cb_delegate;
		static NextAsyncNativeDelegate NextAsyncVMCallback {
			get {
				if (NextAsync_cb_delegate == null)
					NextAsync_cb_delegate = new NextAsyncNativeDelegate (NextAsync_cb);
				return NextAsync_cb_delegate;
			}
		}

		static void OverrideNextAsync (GLib.GType gtype)
		{
			OverrideNextAsync (gtype, NextAsyncVMCallback);
		}

		static void OverrideNextAsync (GLib.GType gtype, NextAsyncNativeDelegate callback)
		{
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset("next_async"));
				*raw_ptr = Marshal.GetFunctionPointerForDelegate(callback);
			}
		}

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

		static void NextAsync_cb (IntPtr inst, IntPtr cancellable, GLibSharp.AsyncReadyCallbackNative cb, IntPtr user_data)
		{
			try {
				SocketAddressEnumerator __obj = GLib.Object.GetObject (inst, false) as SocketAddressEnumerator;
				GLibSharp.AsyncReadyCallbackInvoker cb_invoker = new GLibSharp.AsyncReadyCallbackInvoker (cb, user_data);
				__obj.OnNextAsync (GLib.Object.GetObject(cancellable) as GLib.Cancellable, cb_invoker.Handler);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.SocketAddressEnumerator), ConnectionMethod="OverrideNextAsync")]
		protected virtual void OnNextAsync (GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb)
		{
			InternalNextAsync (cancellable, cb);
		}

		private void InternalNextAsync (GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb)
		{
			NextAsyncNativeDelegate unmanaged = class_abi.BaseOverride<NextAsyncNativeDelegate>(this.LookupGType(), "next_async");
			if (unmanaged == null) return;

			GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper (cb);
			cb_wrapper.PersistUntilCalled ();
			unmanaged (this.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
		}

		static NextFinishNativeDelegate NextFinish_cb_delegate;
		static NextFinishNativeDelegate NextFinishVMCallback {
			get {
				if (NextFinish_cb_delegate == null)
					NextFinish_cb_delegate = new NextFinishNativeDelegate (NextFinish_cb);
				return NextFinish_cb_delegate;
			}
		}

		static void OverrideNextFinish (GLib.GType gtype)
		{
			OverrideNextFinish (gtype, NextFinishVMCallback);
		}

		static void OverrideNextFinish (GLib.GType gtype, NextFinishNativeDelegate callback)
		{
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset("next_finish"));
				*raw_ptr = Marshal.GetFunctionPointerForDelegate(callback);
			}
		}

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

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

			try {
				SocketAddressEnumerator __obj = GLib.Object.GetObject (inst, false) as SocketAddressEnumerator;
				GLib.SocketAddress __result;
				__result = __obj.OnNextFinish (GLib.AsyncResultAdapter.GetObject (result, false));
				return __result == null ? IntPtr.Zero : __result.Handle;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.SocketAddressEnumerator), ConnectionMethod="OverrideNextFinish")]
		protected virtual GLib.SocketAddress OnNextFinish (GLib.IAsyncResult result)
		{
			return InternalNextFinish (result);
		}

		private GLib.SocketAddress InternalNextFinish (GLib.IAsyncResult result)
		{
			NextFinishNativeDelegate unmanaged = class_abi.BaseOverride<NextFinishNativeDelegate>(this.LookupGType(), "next_finish");
			if (unmanaged == null) throw new InvalidOperationException ("No base method to invoke");

			IntPtr error = IntPtr.Zero;
			IntPtr __result = unmanaged (this.Handle, result == null ? IntPtr.Zero : ((result is GLib.Object) ? (result as GLib.Object).Handle : (result as GLib.AsyncResultAdapter).Handle), out error);
			return GLib.Object.GetObject(__result) as GLib.SocketAddress;
		}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _class_abi = null;
		static public unsafe new GLib.AbiStruct class_abi {
			get {
				if (_class_abi == null)
					_class_abi = new GLib.AbiStruct (new List<GLib.AbiField>{ 
						new GLib.AbiField("next"
							, GLib.Object.class_abi.Fields
							, (uint) sizeof( IntPtr ) // next
							, null
							, "next_async"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("next_async"
							, -1
							, (uint) sizeof( IntPtr ) // next_async
							, "next"
							, "next_finish"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("next_finish"
							, -1
							, (uint) sizeof( IntPtr ) // next_finish
							, "next_async"
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

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

		public static new GLib.GType GType { 
			get {
				IntPtr raw_ret = g_socket_address_enumerator_get_type();
				GLib.GType ret = new GLib.GType(raw_ret);
				return ret;
			}
		}

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

		public unsafe GLib.SocketAddress Next(GLib.Cancellable cancellable) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_socket_address_enumerator_next(Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);
			GLib.SocketAddress ret = GLib.Object.GetObject(raw_ret) as GLib.SocketAddress;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

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

		public void NextAsync(GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb) {
			GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper (cb);
			cb_wrapper.PersistUntilCalled ();
			g_socket_address_enumerator_next_async(Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
		}

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

		public unsafe GLib.SocketAddress NextFinish(GLib.IAsyncResult result) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_socket_address_enumerator_next_finish(Handle, result == null ? IntPtr.Zero : ((result is GLib.Object) ? (result as GLib.Object).Handle : (result as GLib.AsyncResultAdapter).Handle), out error);
			GLib.SocketAddress ret = GLib.Object.GetObject(raw_ret) as GLib.SocketAddress;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public unsafe new GLib.AbiStruct abi_info {
			get {
				if (_abi_info == null)
					_abi_info = new GLib.AbiStruct (GLib.Object.abi_info.Fields);

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
