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

namespace Gst.RtspServer {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;

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

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

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_new();

		public RTSPSessionPool () : base (IntPtr.Zero)
		{
			if (GetType () != typeof (RTSPSessionPool)) {
				CreateNativeObject (new string [0], new GLib.Value[0]);
				return;
			}
			Raw = gst_rtsp_session_pool_new();
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern uint gst_rtsp_session_pool_get_max_sessions(IntPtr raw);

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern void gst_rtsp_session_pool_set_max_sessions(IntPtr raw, uint max);

		[GLib.Property ("max-sessions")]
		public uint MaxSessions {
			get  {
				uint raw_ret = gst_rtsp_session_pool_get_max_sessions(Handle);
				uint ret = raw_ret;
				return ret;
			}
			set  {
				gst_rtsp_session_pool_set_max_sessions(Handle, value);
			}
		}

		[GLib.Signal("session-removed")]
		public event Gst.RtspServer.SessionRemovedHandler SessionRemoved {
			add {
				this.AddSignalHandler ("session-removed", value, typeof (Gst.RtspServer.SessionRemovedArgs));
			}
			remove {
				this.RemoveSignalHandler ("session-removed", value);
			}
		}

		static CreateSessionIdNativeDelegate CreateSessionId_cb_delegate;
		static CreateSessionIdNativeDelegate CreateSessionIdVMCallback {
			get {
				if (CreateSessionId_cb_delegate == null)
					CreateSessionId_cb_delegate = new CreateSessionIdNativeDelegate (CreateSessionId_cb);
				return CreateSessionId_cb_delegate;
			}
		}

		static void OverrideCreateSessionId (GLib.GType gtype)
		{
			OverrideCreateSessionId (gtype, CreateSessionIdVMCallback);
		}

		static void OverrideCreateSessionId (GLib.GType gtype, CreateSessionIdNativeDelegate callback)
		{
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset("create_session_id"));
				*raw_ptr = Marshal.GetFunctionPointerForDelegate((Delegate) callback);
			}
		}

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

		static IntPtr CreateSessionId_cb (IntPtr inst)
		{
			try {
				RTSPSessionPool __obj = GLib.Object.GetObject (inst, false) as RTSPSessionPool;
				string __result;
				__result = __obj.OnCreateSessionId ();
				return GLib.Marshaller.StringToPtrGStrdup(__result);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw e;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(Gst.RtspServer.RTSPSessionPool), ConnectionMethod="OverrideCreateSessionId")]
		protected virtual string OnCreateSessionId ()
		{
			return InternalCreateSessionId ();
		}

		private string InternalCreateSessionId ()
		{
			CreateSessionIdNativeDelegate unmanaged = null;
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) this.LookupGType().GetThresholdType().GetClassPtr()) + (long) class_abi.GetFieldOffset("create_session_id"));
				unmanaged = (CreateSessionIdNativeDelegate) Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(CreateSessionIdNativeDelegate));
			}
			if (unmanaged == null) return null;

			IntPtr __result = unmanaged (this.Handle);
			return GLib.Marshaller.PtrToStringGFree(__result);
		}

		static SessionRemovedNativeDelegate SessionRemoved_cb_delegate;
		static SessionRemovedNativeDelegate SessionRemovedVMCallback {
			get {
				if (SessionRemoved_cb_delegate == null)
					SessionRemoved_cb_delegate = new SessionRemovedNativeDelegate (SessionRemoved_cb);
				return SessionRemoved_cb_delegate;
			}
		}

		static void OverrideSessionRemoved (GLib.GType gtype)
		{
			OverrideSessionRemoved (gtype, SessionRemovedVMCallback);
		}

		static void OverrideSessionRemoved (GLib.GType gtype, SessionRemovedNativeDelegate callback)
		{
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) gtype.GetClassPtr()) + (long) class_abi.GetFieldOffset("session_removed"));
				*raw_ptr = Marshal.GetFunctionPointerForDelegate((Delegate) callback);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void SessionRemovedNativeDelegate (IntPtr inst, IntPtr _object);

		static void SessionRemoved_cb (IntPtr inst, IntPtr _object)
		{
			try {
				RTSPSessionPool __obj = GLib.Object.GetObject (inst, false) as RTSPSessionPool;
				__obj.OnSessionRemoved (GLib.Object.GetObject(_object) as Gst.RtspServer.RTSPSession);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(Gst.RtspServer.RTSPSessionPool), ConnectionMethod="OverrideSessionRemoved")]
		protected virtual void OnSessionRemoved (Gst.RtspServer.RTSPSession _object)
		{
			InternalSessionRemoved (_object);
		}

		private void InternalSessionRemoved (Gst.RtspServer.RTSPSession _object)
		{
			SessionRemovedNativeDelegate unmanaged = null;
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) this.LookupGType().GetThresholdType().GetClassPtr()) + (long) class_abi.GetFieldOffset("session_removed"));
				unmanaged = (SessionRemovedNativeDelegate) Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(SessionRemovedNativeDelegate));
			}
			if (unmanaged == null) return;

			unmanaged (this.Handle, _object == null ? IntPtr.Zero : _object.Handle);
		}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _class_abi = null;
		static public new GLib.AbiStruct class_abi {
			get {
				if (_class_abi == null)
					_class_abi = new GLib.AbiStruct (new List<GLib.AbiField>{ 
						new GLib.AbiField("create_session_id"
							, GLib.Object.class_abi.Fields
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // create_session_id
							, null
							, "create_session"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("create_session"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // create_session
							, "create_session_id"
							, "session_removed"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("session_removed"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // session_removed
							, "create_session"
							, "_gst_reserved"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("_gst_reserved"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) * 19 // _gst_reserved
							, "session_removed"
							, null
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_get_type();

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

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern uint gst_rtsp_session_pool_cleanup(IntPtr raw);

		public uint Cleanup() {
			uint raw_ret = gst_rtsp_session_pool_cleanup(Handle);
			uint ret = raw_ret;
			return ret;
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_create(IntPtr raw);

		public Gst.RtspServer.RTSPSession Create() {
			IntPtr raw_ret = gst_rtsp_session_pool_create(Handle);
			Gst.RtspServer.RTSPSession ret = GLib.Object.GetObject(raw_ret, true) as Gst.RtspServer.RTSPSession;
			return ret;
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_create_watch(IntPtr raw);

		public GLib.Source CreateWatch() {
			IntPtr raw_ret = gst_rtsp_session_pool_create_watch(Handle);
			GLib.Source ret = new GLib.Source(raw_ret);
			return ret;
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_filter(IntPtr raw, Gst.RtspServerSharp.RTSPSessionPoolFilterFuncNative func, IntPtr user_data);

		public Gst.RtspServer.RTSPSession[] Filter(Gst.RtspServer.RTSPSessionPoolFilterFunc func) {
			Gst.RtspServerSharp.RTSPSessionPoolFilterFuncWrapper func_wrapper = new Gst.RtspServerSharp.RTSPSessionPoolFilterFuncWrapper (func);
			IntPtr raw_ret = gst_rtsp_session_pool_filter(Handle, func_wrapper.NativeDelegate, IntPtr.Zero);
			Gst.RtspServer.RTSPSession[] ret = (Gst.RtspServer.RTSPSession[]) GLib.Marshaller.ListPtrToArray (raw_ret, typeof(GLib.List), true, true, typeof(Gst.RtspServer.RTSPSession));
			return ret;
		}

		public Gst.RtspServer.RTSPSession[] Filter() {
			return Filter (null);
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_rtsp_session_pool_find(IntPtr raw, IntPtr sessionid);

		public Gst.RtspServer.RTSPSession Find(string sessionid) {
			IntPtr native_sessionid = GLib.Marshaller.StringToPtrGStrdup (sessionid);
			IntPtr raw_ret = gst_rtsp_session_pool_find(Handle, native_sessionid);
			Gst.RtspServer.RTSPSession ret = GLib.Object.GetObject(raw_ret, true) as Gst.RtspServer.RTSPSession;
			GLib.Marshaller.Free (native_sessionid);
			return ret;
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern uint gst_rtsp_session_pool_get_n_sessions(IntPtr raw);

		public uint NSessions { 
			get {
				uint raw_ret = gst_rtsp_session_pool_get_n_sessions(Handle);
				uint ret = raw_ret;
				return ret;
			}
		}

		[DllImport("gstrtspserver-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern bool gst_rtsp_session_pool_remove(IntPtr raw, IntPtr sess);

		public bool Remove(Gst.RtspServer.RTSPSession sess) {
			bool raw_ret = gst_rtsp_session_pool_remove(Handle, sess == null ? IntPtr.Zero : sess.Handle);
			bool ret = raw_ret;
			return ret;
		}


		static RTSPSessionPool ()
		{
			GtkSharp.GstreamerSharp.ObjectManager.Initialize ();
		}

		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public 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) Marshal.SizeOf(typeof(IntPtr)) // priv
							, null
							, "_gst_reserved"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("_gst_reserved"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) * 4 // _gst_reserved
							, "priv"
							, null
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
