// 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 SocketListener : GLib.Object {

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

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

		public SocketListener () : base (IntPtr.Zero)
		{
			if (GetType () != typeof (SocketListener)) {
				CreateNativeObject (Array.Empty<string> (), Array.Empty<GLib.Value> ());
				return;
			}
			Raw = g_socket_listener_new();
		}

		[GLib.Property ("listen-backlog")]
		public int ListenBacklog {
			get {
				GLib.Value val = GetProperty ("listen-backlog");
				int ret = (int) val;
				val.Dispose ();
				return ret;
			}
			set {
				GLib.Value val = new GLib.Value(value);
				SetProperty("listen-backlog", val);
				val.Dispose ();
			}
		}

		[GLib.Signal("event")]
		public event GLib.SocketEventHandler SocketEvent {
			add {
				this.AddSignalHandler ("event", value, typeof (GLib.SocketEventArgs));
			}
			remove {
				this.RemoveSignalHandler ("event", value);
			}
		}

		static ChangedNativeDelegate Changed_cb_delegate;
		static ChangedNativeDelegate ChangedVMCallback {
			get {
				if (Changed_cb_delegate == null)
					Changed_cb_delegate = new ChangedNativeDelegate (Changed_cb);
				return Changed_cb_delegate;
			}
		}

		static void OverrideChanged (GLib.GType gtype)
		{
			OverrideChanged (gtype, ChangedVMCallback);
		}

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void ChangedNativeDelegate (IntPtr inst);

		static void Changed_cb (IntPtr inst)
		{
			try {
				SocketListener __obj = GLib.Object.GetObject (inst, false) as SocketListener;
				__obj.OnChanged ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.SocketListener), ConnectionMethod="OverrideChanged")]
		protected virtual void OnChanged ()
		{
			InternalChanged ();
		}

		private void InternalChanged ()
		{
			ChangedNativeDelegate unmanaged = class_abi.BaseOverride<ChangedNativeDelegate>(this.LookupGType(), "changed");
			if (unmanaged == null) return;

			unmanaged (this.Handle);
		}

		static SocketEventNativeDelegate SocketEvent_cb_delegate;
		static SocketEventNativeDelegate SocketEventVMCallback {
			get {
				if (SocketEvent_cb_delegate == null)
					SocketEvent_cb_delegate = new SocketEventNativeDelegate (SocketEvent_cb);
				return SocketEvent_cb_delegate;
			}
		}

		static void OverrideSocketEvent (GLib.GType gtype)
		{
			OverrideSocketEvent (gtype, SocketEventVMCallback);
		}

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void SocketEventNativeDelegate (IntPtr inst, out int evnt, IntPtr socket);

		static void SocketEvent_cb (IntPtr inst, out int evnt, IntPtr socket)
		{
			try {
				SocketListener __obj = GLib.Object.GetObject (inst, false) as SocketListener;
				GLib.SocketListenerEvent myevnt;
				__obj.OnSocketEvent (out myevnt, socket == IntPtr.Zero ? null : (GLib.Socket) GLib.Opaque.GetOpaque (socket, typeof (GLib.Socket), false));
				evnt = (int) myevnt;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.SocketListener), ConnectionMethod="OverrideSocketEvent")]
		protected virtual void OnSocketEvent (out GLib.SocketListenerEvent evnt, GLib.Socket socket)
		{
			InternalSocketEvent (out evnt, socket);
		}

		private void InternalSocketEvent (out GLib.SocketListenerEvent evnt, GLib.Socket socket)
		{
			SocketEventNativeDelegate unmanaged = class_abi.BaseOverride<SocketEventNativeDelegate>(this.LookupGType(), "event");
			if (unmanaged == null) throw new InvalidOperationException ("No base method to invoke");

			int native_evnt;
			unmanaged (this.Handle, out native_evnt, socket == null ? IntPtr.Zero : socket.Handle);
			evnt = (GLib.SocketListenerEvent) native_evnt;
		}


		// 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("changed"
							, GLib.Object.class_abi.Fields
							, (uint) sizeof( IntPtr ) // changed
							, null
							, "event"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("event"
							, -1
							, (uint) sizeof( IntPtr ) // event
							, "changed"
							, "_g_reserved2"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved2"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved2
							, "event"
							, "_g_reserved3"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved3"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved3
							, "_g_reserved2"
							, "_g_reserved4"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved4"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved4
							, "_g_reserved3"
							, "_g_reserved5"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved5"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved5
							, "_g_reserved4"
							, "_g_reserved6"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved6"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved6
							, "_g_reserved5"
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

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

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

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

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

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

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

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

		public unsafe GLib.Socket AcceptSocket(GLib.Object source_object, GLib.Cancellable cancellable) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_socket_listener_accept_socket(Handle, source_object == null ? IntPtr.Zero : source_object.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error);
			GLib.Socket ret = raw_ret == IntPtr.Zero ? null : (GLib.Socket) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.Socket), false);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

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

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

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

		public unsafe GLib.Socket AcceptSocketFinish(GLib.IAsyncResult result, GLib.Object source_object) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = g_socket_listener_accept_socket_finish(Handle, result == null ? IntPtr.Zero : ((result is GLib.Object) ? (result as GLib.Object).Handle : (result as GLib.AsyncResultAdapter).Handle), source_object == null ? IntPtr.Zero : source_object.Handle, out error);
			GLib.Socket ret = raw_ret == IntPtr.Zero ? null : (GLib.Socket) GLib.Opaque.GetOpaque (raw_ret, typeof (GLib.Socket), false);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool d_g_socket_listener_add_address(IntPtr raw, IntPtr address, int type, int protocol, IntPtr source_object, IntPtr effective_address, out IntPtr error);
		static d_g_socket_listener_add_address g_socket_listener_add_address = FuncLoader.LoadFunction<d_g_socket_listener_add_address>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_socket_listener_add_address"));

		public unsafe bool AddAddress(GLib.SocketAddress address, GLib.SocketType type, GLib.SocketProtocol protocol, GLib.Object source_object, GLib.SocketAddress effective_address) {
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_socket_listener_add_address(Handle, address == null ? IntPtr.Zero : address.Handle, (int) type, (int) protocol, source_object == null ? IntPtr.Zero : source_object.Handle, effective_address == null ? IntPtr.Zero : effective_address.Handle, out error);
			bool ret = raw_ret;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate ushort d_g_socket_listener_add_any_inet_port(IntPtr raw, IntPtr source_object, out IntPtr error);
		static d_g_socket_listener_add_any_inet_port g_socket_listener_add_any_inet_port = FuncLoader.LoadFunction<d_g_socket_listener_add_any_inet_port>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_socket_listener_add_any_inet_port"));

		public unsafe ushort AddAnyInetPort(GLib.Object source_object) {
			IntPtr error = IntPtr.Zero;
			ushort raw_ret = g_socket_listener_add_any_inet_port(Handle, source_object == null ? IntPtr.Zero : source_object.Handle, out error);
			ushort ret = raw_ret;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool d_g_socket_listener_add_inet_port(IntPtr raw, ushort port, IntPtr source_object, out IntPtr error);
		static d_g_socket_listener_add_inet_port g_socket_listener_add_inet_port = FuncLoader.LoadFunction<d_g_socket_listener_add_inet_port>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_socket_listener_add_inet_port"));

		public unsafe bool AddInetPort(ushort port, GLib.Object source_object) {
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_socket_listener_add_inet_port(Handle, port, source_object == null ? IntPtr.Zero : source_object.Handle, out error);
			bool ret = raw_ret;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool d_g_socket_listener_add_socket(IntPtr raw, IntPtr socket, IntPtr source_object, out IntPtr error);
		static d_g_socket_listener_add_socket g_socket_listener_add_socket = FuncLoader.LoadFunction<d_g_socket_listener_add_socket>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_socket_listener_add_socket"));

		public unsafe bool AddSocket(GLib.Socket socket, GLib.Object source_object) {
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_socket_listener_add_socket(Handle, socket == null ? IntPtr.Zero : socket.Handle, source_object == null ? IntPtr.Zero : source_object.Handle, out error);
			bool ret = raw_ret;
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

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

		public void Close() {
			g_socket_listener_close(Handle);
		}

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

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_g_socket_listener_set_backlog(IntPtr raw, int listen_backlog);
		static d_g_socket_listener_set_backlog g_socket_listener_set_backlog = FuncLoader.LoadFunction<d_g_socket_listener_set_backlog>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gio), "g_socket_listener_set_backlog"));

		public int Backlog { 
			set {
				g_socket_listener_set_backlog(Handle, value);
			}
		}


		// 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 (new List<GLib.AbiField>{ 
						new GLib.AbiField("priv"
							, GLib.Object.abi_info.Fields
							, (uint) sizeof( IntPtr ) // priv
							, null
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
