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