-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMumbleLinkFile.cs
70 lines (59 loc) · 1.84 KB
/
MumbleLinkFile.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
68
69
70
using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using static mumblelib.Text;
namespace mumblelib
{
public unsafe class MumbleLinkFile : IDisposable
{
/// <summary>Holds a reference to the shared memory block.</summary>
private readonly MemoryMappedFile memoryMappedFile;
private readonly Frame* ptr;
/// <summary>Indicates whether this object is disposed.</summary>
private bool disposed;
private static string LinkFileName()
{
return "MumbleLink";
}
public MumbleLinkFile(MemoryMappedFile memoryMappedFile)
{
this.memoryMappedFile = memoryMappedFile ?? throw new ArgumentNullException("memoryMappedFile");
byte* tmp = null;
memoryMappedFile.CreateViewAccessor().SafeMemoryMappedViewHandle.AcquirePointer(ref tmp);
ptr = (Frame*)tmp;
}
public Frame* FramePtr()
{
return ptr;
}
public static MumbleLinkFile CreateOrOpen()
{
return new MumbleLinkFile(MemoryMappedFile.CreateOrOpen(LinkFileName(), Marshal.SizeOf<Frame>()));
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void assertNotDisposed()
{
if (disposed)
{
throw new ObjectDisposedException(GetType().FullName);
}
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
{
return;
}
if (disposing)
{
memoryMappedFile.Dispose();
}
disposed = true;
}
}
}