-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDevice.cs
More file actions
72 lines (60 loc) · 2.4 KB
/
Device.cs
File metadata and controls
72 lines (60 loc) · 2.4 KB
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
71
72
using CtlLibraryBindings;
using CtlLibraryWrapper;
using System;
using System.Linq;
namespace FanControl.IntelCtlLibraryPlugin
{
public class Device : IDisposable
{
private readonly DeviceFan[] _fans;
private readonly DeviceTemp[] _temps;
private readonly CompositeDisposable _disposable;
public static Device[] GetDevices(SWIGTYPE_p__ctl_api_handle_t apiHandle, CompositeDisposable disposable)
{
return CtlLibraryHelpers.GetDevices(apiHandle)
.DisposeWith(disposable)
.GetItems((x, i) => new Device(x.getitem(i), i))
.ToArray();
}
private static SWIGTYPE_p__ctl_fan_handle_t[] GetFanHandles(SWIGTYPE_p__ctl_device_adapter_handle_t handle, CompositeDisposable disposable)
{
return CtlLibraryHelpers.GetFanHandles(handle)
.DisposeWith(disposable)
.GetItems((x, i) => x.getitem(i))
.ToArray();
}
private static SWIGTYPE_p__ctl_temp_handle_t[] GetTempHandles(SWIGTYPE_p__ctl_device_adapter_handle_t handle, CompositeDisposable disposable)
{
return CtlLibraryHelpers.GetTempHandles(handle)
.DisposeWith(disposable)
.GetItems((x, i) => x.getitem(i))
.ToArray();
}
private Device(SWIGTYPE_p__ctl_device_adapter_handle_t handle, int index)
{
_disposable = new CompositeDisposable();
_fans = GetFanHandles(handle, _disposable).Select((x, i) => new DeviceFan(x, i)).ToArray();
_temps = GetTempHandles(handle, _disposable).Select((x) => new DeviceTemp(x)).ToArray();
ctl_device_adapter_properties_t properties = new ctl_device_adapter_properties_t().DisposeWith(_disposable);
CtlLibrary.ctlGetDeviceProperties(handle, properties).ThrowIfError("Get device properties");
Name = properties.name;
Index = index;
}
public string Name { get; }
public DeviceFan[] Fans => _fans;
public DeviceTemp[] Temps => _temps;
public int Index { get; }
public void Dispose()
{
foreach (var fan in _fans)
{
fan.Dispose();
}
foreach (var temp in _temps)
{
temp.Dispose();
}
_disposable.Dispose();
}
}
}