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

namespace Gst {

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

#region Autogenerated code
	public partial class Allocator : Gst.Object {

		protected Allocator (IntPtr raw) : base(raw) {}

		protected Allocator() : base(IntPtr.Zero)
		{
			CreateNativeObject (new string [0], new GLib.Value [0]);
		}

		public string MemType {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_type"));
					return GLib.Marshaller.Utf8PtrToString ((*raw_ptr));
				}
			}
		}

		public Gst.MemoryMapFunction MemMap {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_map"));
					 GstSharp.MemoryMapFunctionNative del = (GstSharp.MemoryMapFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryMapFunctionNative));
					return GstSharp.MemoryMapFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryUnmapFunction MemUnmap {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_unmap"));
					 GstSharp.MemoryUnmapFunctionNative del = (GstSharp.MemoryUnmapFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryUnmapFunctionNative));
					return GstSharp.MemoryUnmapFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryCopyFunction MemCopy {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_copy"));
					 GstSharp.MemoryCopyFunctionNative del = (GstSharp.MemoryCopyFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryCopyFunctionNative));
					return GstSharp.MemoryCopyFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryShareFunction MemShare {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_share"));
					 GstSharp.MemoryShareFunctionNative del = (GstSharp.MemoryShareFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryShareFunctionNative));
					return GstSharp.MemoryShareFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryIsSpanFunction MemIsSpan {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_is_span"));
					 GstSharp.MemoryIsSpanFunctionNative del = (GstSharp.MemoryIsSpanFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryIsSpanFunctionNative));
					return GstSharp.MemoryIsSpanFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryMapFullFunction MemMapFull {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_map_full"));
					 GstSharp.MemoryMapFullFunctionNative del = (GstSharp.MemoryMapFullFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryMapFullFunctionNative));
					return GstSharp.MemoryMapFullFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		public Gst.MemoryUnmapFullFunction MemUnmapFull {
			get {
				unsafe {
					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + abi_info.GetFieldOffset("mem_unmap_full"));
					 GstSharp.MemoryUnmapFullFunctionNative del = (GstSharp.MemoryUnmapFullFunctionNative)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(GstSharp.MemoryUnmapFullFunctionNative));
					return GstSharp.MemoryUnmapFullFunctionWrapper.GetManagedDelegate ((del));
				}
			}
		}

		static AllocNativeDelegate Alloc_cb_delegate;
		static AllocNativeDelegate AllocVMCallback {
			get {
				if (Alloc_cb_delegate == null)
					Alloc_cb_delegate = new AllocNativeDelegate (Alloc_cb);
				return Alloc_cb_delegate;
			}
		}

		static void OverrideAlloc (GLib.GType gtype)
		{
			OverrideAlloc (gtype, AllocVMCallback);
		}

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr AllocNativeDelegate (IntPtr inst, UIntPtr size, IntPtr parms);

		static IntPtr Alloc_cb (IntPtr inst, UIntPtr size, IntPtr parms)
		{
			try {
				Allocator __obj = GLib.Object.GetObject (inst, false) as Allocator;
				Gst.Memory __result;
				__result = __obj.OnAlloc ((ulong) size, Gst.AllocationParams.New (parms));
				return __result == null ? IntPtr.Zero : __result.OwnedCopy;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw e;
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(Gst.Allocator), ConnectionMethod="OverrideAlloc")]
		protected virtual Gst.Memory OnAlloc (ulong size, Gst.AllocationParams parms)
		{
			return InternalAlloc (size, parms);
		}

		private Gst.Memory InternalAlloc (ulong size, Gst.AllocationParams parms)
		{
			AllocNativeDelegate unmanaged = null;
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) this.LookupGType().GetThresholdType().GetClassPtr()) + (long) class_abi.GetFieldOffset("alloc"));
				unmanaged = (AllocNativeDelegate) Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(AllocNativeDelegate));
			}
			if (unmanaged == null) return null;

			IntPtr native_parms = GLib.Marshaller.StructureToPtrAlloc (parms);
			IntPtr __result = unmanaged (this.Handle, new UIntPtr (size), native_parms);
			Marshal.FreeHGlobal (native_parms);
			return __result == IntPtr.Zero ? null : (Gst.Memory) GLib.Opaque.GetOpaque (__result, typeof (Gst.Memory), true);
		}

		static FreeNativeDelegate Free_cb_delegate;
		static FreeNativeDelegate FreeVMCallback {
			get {
				if (Free_cb_delegate == null)
					Free_cb_delegate = new FreeNativeDelegate (Free_cb);
				return Free_cb_delegate;
			}
		}

		static void OverrideFree (GLib.GType gtype)
		{
			OverrideFree (gtype, FreeVMCallback);
		}

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void FreeNativeDelegate (IntPtr inst, IntPtr memory);

		static void Free_cb (IntPtr inst, IntPtr memory)
		{
			try {
				Allocator __obj = GLib.Object.GetObject (inst, false) as Allocator;
				__obj.OnFree (memory == IntPtr.Zero ? null : (Gst.Memory) GLib.Opaque.GetOpaque (memory, typeof (Gst.Memory), true));
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(Gst.Allocator), ConnectionMethod="OverrideFree")]
		protected virtual void OnFree (Gst.Memory memory)
		{
			InternalFree (memory);
		}

		private void InternalFree (Gst.Memory memory)
		{
			FreeNativeDelegate unmanaged = null;
			unsafe {
				IntPtr* raw_ptr = (IntPtr*)(((long) this.LookupGType().GetThresholdType().GetClassPtr()) + (long) class_abi.GetFieldOffset("free"));
				unmanaged = (FreeNativeDelegate) Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(FreeNativeDelegate));
			}
			if (unmanaged == null) return;

			memory.Owned = false;
			unmanaged (this.Handle, memory == null ? IntPtr.Zero : memory.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("alloc"
							, Gst.Object.class_abi.Fields
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // alloc
							, null
							, "free"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("free"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // free
							, "alloc"
							, "_gst_reserved"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("_gst_reserved"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) * 4 // _gst_reserved
							, "free"
							, null
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

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

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

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_allocator_find(IntPtr name);

		public static Gst.Allocator Find(string name) {
			IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
			IntPtr raw_ret = gst_allocator_find(native_name);
			Gst.Allocator ret = GLib.Object.GetObject(raw_ret, true) as Gst.Allocator;
			GLib.Marshaller.Free (native_name);
			return ret;
		}

		public static Gst.Allocator Find() {
			return Find (null);
		}

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern void gst_allocator_register(IntPtr name, IntPtr allocator);

		public static void Register(string name, Gst.Allocator allocator) {
			IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
			gst_allocator_register(native_name, allocator == null ? IntPtr.Zero : allocator.OwnedHandle);
			GLib.Marshaller.Free (native_name);
		}

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern IntPtr gst_allocator_alloc(IntPtr raw, UIntPtr size, IntPtr parms);

		public Gst.Memory Alloc(ulong size, Gst.AllocationParams parms) {
			IntPtr native_parms = GLib.Marshaller.StructureToPtrAlloc (parms);
			IntPtr raw_ret = gst_allocator_alloc(Handle, new UIntPtr (size), native_parms);
			Gst.Memory ret = raw_ret == IntPtr.Zero ? null : (Gst.Memory) GLib.Opaque.GetOpaque (raw_ret, typeof (Gst.Memory), true);
			Marshal.FreeHGlobal (native_parms);
			return ret;
		}

		public Gst.Memory Alloc(ulong size) {
			return Alloc (size, Gst.AllocationParams.Zero);
		}

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern void gst_allocator_free(IntPtr raw, IntPtr memory);

		public void Free(Gst.Memory memory) {
			memory.Owned = false;
			gst_allocator_free(Handle, memory == null ? IntPtr.Zero : memory.Handle);
		}

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

		public void SetDefault() {
			gst_allocator_set_default(Handle);
		}


		// 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("mem_type"
							, Gst.Object.abi_info.Fields
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_type
							, null
							, "mem_map"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_map"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_map
							, "mem_type"
							, "mem_unmap"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_unmap"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_unmap
							, "mem_map"
							, "mem_copy"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_copy"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_copy
							, "mem_unmap"
							, "mem_share"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_share"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_share
							, "mem_copy"
							, "mem_is_span"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_is_span"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_is_span
							, "mem_share"
							, "mem_map_full"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_map_full"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_map_full
							, "mem_is_span"
							, "mem_unmap_full"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("mem_unmap_full"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // mem_unmap_full
							, "mem_map_full"
							, "_gst_reserved"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("_gst_reserved"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) * 2 // _gst_reserved
							, "mem_unmap_full"
							, "priv"
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
						new GLib.AbiField("priv"
							, -1
							, (uint) Marshal.SizeOf(typeof(IntPtr)) // priv
							, "_gst_reserved"
							, null
							, (uint) Marshal.SizeOf(typeof(IntPtr))
							, 0
							),
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
