X-Git-Url: https://git.videolan.org/gitweb.cgi/vlc.git/?p=vlc.git;p=vlc.git;a=blobdiff_plain;f=bindings%2Fcil%2Fsrc%2Fmarshal.cs;h=b68059bfb4b9966f758edf2dfef1058522b16004;hp=c210283d04e34b0678db206a9d0d104afcb98429;hb=d1324549f23cf84d500188275032cf2a0640f65e;hpb=a2aa6ae3482a8efaf21bcc169a2e20b988dff34b diff --git a/bindings/cil/src/marshal.cs b/bindings/cil/src/marshal.cs index c210283d04..b68059bfb4 100644 --- a/bindings/cil/src/marshal.cs +++ b/bindings/cil/src/marshal.cs @@ -1,11 +1,11 @@ -/* - * libvlc.cs - libvlc-control CIL bindings - * - * $Id$ +/** + * @file marshal.cs + * @brief Common LibVLC objects marshalling utilities + * @ingroup Internals */ /********************************************************************** - * Copyright (C) 2007 Rémi Denis-Courmont. * + * Copyright (C) 2007-2009 Rémi Denis-Courmont. * * This program is free software; you can redistribute and/or modify * * it under the terms of the GNU General Public License as published * * by the Free Software Foundation; version 2 of the license, or (at * @@ -27,16 +27,21 @@ using System.Runtime.InteropServices; namespace VideoLAN.LibVLC { /** - * Abstract safe handle class for non-NULL pointers - * (Microsoft.* namespace has a similar class, but lets stick to System.*) + * @brief NonNullHandle: abstract safe handle class for non-NULL pointers + * @ingroup Internals + * Microsoft.* namespace has a similar class. However we want to use the + * System.* namespace only. */ - public abstract class NonNullHandle : SafeHandle + internal abstract class NonNullHandle : SafeHandle { protected NonNullHandle () : base (IntPtr.Zero, true) { } + /** + * System.Runtime.InteropServices.SafeHandle::IsInvalid. + */ public override bool IsInvalid { get @@ -44,23 +49,49 @@ namespace VideoLAN.LibVLC return handle == IntPtr.Zero; } } + + protected abstract void Destroy (); + + /** + * System.Runtime.InteropServices.SafeHandle::ReleaseHandle. + */ + protected override bool ReleaseHandle () + { + Destroy (); + return true; + } + }; - public class BaseObject : IDisposable where HandleT : SafeHandle + /** + * @brief BaseObject: generic wrapper around a safe handle. + * @ingroup Internals + * This is the baseline for all managed LibVLC objects which wrap + * an unmanaged LibVLC pointer. + */ + public class BaseObject : IDisposable { - protected NativeException ex; - protected HandleT self; + protected NativeException ex; /**< buffer for LibVLC exceptions */ + protected SafeHandle handle; /**< wrapped safe handle */ - internal BaseObject (HandleT self) + internal BaseObject () { - this.self = self; ex = new NativeException (); + this.handle = null; + } + + protected void Raise () + { + ex.Raise (); } + /** + * IDisposable::Dispose. + */ public void Dispose () { ex.Dispose (); - self.Close (); + handle.Close (); } }; };