-
Notifications
You must be signed in to change notification settings - Fork 1
/
TorrentHandle.cs
67 lines (54 loc) · 1.73 KB
/
TorrentHandle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Runtime.InteropServices;
namespace Tsunami.Core
{
using TorrentHandleHandle = HandleRef;
public class TorrentHandle : IDisposable
{
#region PInvoke
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr TorrentHandle_Create();
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void TorrentHandle_Destroy(TorrentHandleHandle h);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern bool TorrentHandle_IsValid(TorrentHandleHandle h);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr TorrentHandle_Status(TorrentHandleHandle h);
#endregion PInvoke
TorrentHandleHandle handle;
public TorrentHandle()
{
IntPtr h = TorrentHandle_Create();
handle = new HandleRef(this, h);
}
public TorrentHandle(IntPtr h)
{
handle = new HandleRef(this, h);
}
public TorrentStatus Status
{
get
{
return new TorrentStatus(TorrentHandle_Status(handle));
}
}
public void Dispose()
{
CleanUp();
GC.SuppressFinalize(this);
}
private void CleanUp()
{
TorrentHandle_Destroy(handle);
handle = new HandleRef(this, IntPtr.Zero);
}
public bool IsValid()
{
return TorrentHandle_IsValid(handle);
}
~TorrentHandle()
{
CleanUp();
}
}
}