// 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 ThreadedSocketService : GLib.SocketService {

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

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

		public ThreadedSocketService (int max_threads) : base (IntPtr.Zero)
		{
			if (GetType () != typeof (ThreadedSocketService)) {
				var vals = new List<GLib.Value> ();
				var names = new List<string> ();
				names.Add ("max_threads");
				vals.Add (new GLib.Value (max_threads));
				CreateNativeObject (names.ToArray (), vals.ToArray ());
				return;
			}
			Raw = g_threaded_socket_service_new(max_threads);
		}

		[GLib.Property ("max-threads")]
		public int MaxThreads {
			get {
				GLib.Value val = GetProperty ("max-threads");
				int ret = (int) val;
				val.Dispose ();
				return ret;
			}
		}

		[GLib.Signal("run")]
		public event GLib.RunHandler Run {
			add {
				this.AddSignalHandler ("run", value, typeof (GLib.RunArgs));
			}
			remove {
				this.RemoveSignalHandler ("run", value);
			}
		}

		static RunNativeDelegate Run_cb_delegate;
		static RunNativeDelegate RunVMCallback {
			get {
				if (Run_cb_delegate == null)
					Run_cb_delegate = new RunNativeDelegate (Run_cb);
				return Run_cb_delegate;
			}
		}

		static void OverrideRun (GLib.GType gtype)
		{
			OverrideRun (gtype, RunVMCallback);
		}

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool RunNativeDelegate (IntPtr inst, IntPtr connection, IntPtr source_object);

		static bool Run_cb (IntPtr inst, IntPtr connection, IntPtr source_object)
		{
			try {
				ThreadedSocketService __obj = GLib.Object.GetObject (inst, false) as ThreadedSocketService;
				bool __result;
				__result = __obj.OnRun (GLib.Object.GetObject(connection) as GLib.SocketConnection, GLib.Object.GetObject (source_object));
				return __result;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(GLib.ThreadedSocketService), ConnectionMethod="OverrideRun")]
		protected virtual bool OnRun (GLib.SocketConnection connection, GLib.Object source_object)
		{
			return InternalRun (connection, source_object);
		}

		private bool InternalRun (GLib.SocketConnection connection, GLib.Object source_object)
		{
			RunNativeDelegate unmanaged = class_abi.BaseOverride<RunNativeDelegate>(this.LookupGType(), "run");
			if (unmanaged == null) return false;

			bool __result = unmanaged (this.Handle, connection == null ? IntPtr.Zero : connection.Handle, source_object == null ? IntPtr.Zero : source_object.Handle);
			return __result;
		}


		// 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("run"
							, GLib.SocketService.class_abi.Fields
							, (uint) sizeof( IntPtr ) // run
							, null
							, "_g_reserved1"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved1"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved1
							, "run"
							, "_g_reserved2"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_g_reserved2"
							, -1
							, (uint) sizeof( IntPtr ) // _g_reserved2
							, "_g_reserved1"
							, "_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"
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

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

		public static new GLib.GType GType { 
			get {
				IntPtr raw_ret = g_threaded_socket_service_get_type();
				GLib.GType ret = new GLib.GType(raw_ret);
				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 (new List<GLib.AbiField>{ 
						new GLib.AbiField("priv"
							, GLib.SocketService.abi_info.Fields
							, (uint) sizeof( IntPtr ) // priv
							, null
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
