]> git.sesse.net Git - vlc/blob - bindings/cil/src/marshal.cs
Prefer mono over trivial (in case trivial somehow wants to work).
[vlc] / bindings / cil / src / marshal.cs
1 /**
2  * @file marshal.cs
3  * @brief LibVLC marshalling utilities
4  *
5  * $Id$
6  */
7
8 /**********************************************************************
9  *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
10  *  This program is free software; you can redistribute and/or modify *
11  *  it under the terms of the GNU General Public License as published *
12  *  by the Free Software Foundation; version 2 of the license, or (at *
13  *  your option) any later version.                                   *
14  *                                                                    *
15  *  This program is distributed in the hope that it will be useful,   *
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
18  *  See the GNU General Public License for more details.              *
19  *                                                                    *
20  *  You should have received a copy of the GNU General Public License *
21  *  along with this program; if not, you can get it from:             *
22  *  http://www.gnu.org/copyleft/gpl.html                              *
23  **********************************************************************/
24
25 using System;
26 using System.Runtime.InteropServices;
27
28 namespace VideoLAN.LibVLC
29 {
30     /**
31      * Abstract safe handle class for non-NULL pointers
32      * (Microsoft.* namespace has a similar class,
33      *  but lets stick to System.*).
34      */
35     public abstract class NonNullHandle : SafeHandle
36     {
37         protected NonNullHandle ()
38             : base (IntPtr.Zero, true)
39         {
40         }
41
42         public override bool IsInvalid
43         {
44             get
45             {
46                 return handle == IntPtr.Zero;
47             }
48         }
49     };
50
51     /**
52      * Generic class for managed wrapper around a native safe handle.
53      */
54     public class BaseObject<HandleT> : IDisposable where HandleT : SafeHandle
55     {
56         protected NativeException ex;
57         protected HandleT self;
58
59         internal BaseObject (HandleT self)
60         {
61             this.self = self;
62             ex = new NativeException ();
63         }
64
65         public void Dispose ()
66         {
67             ex.Dispose ();
68             self.Close ();
69         }
70     };
71 };