mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Compare commits
No commits in common. "5fc2e34f289edd18ea9d34cb7dd8865dea5e0644" and "e645e4dcf20d6b25180351aa237065c8678b4876" have entirely different histories.
5fc2e34f28
...
e645e4dcf2
@ -14,18 +14,13 @@ namespace RGB.NET.Core
|
||||
private readonly List<T> _decorators = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<T> Decorators { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractDecoratable{T}"/> class.
|
||||
/// </summary>
|
||||
protected AbstractDecoratable()
|
||||
public IReadOnlyCollection<T> Decorators
|
||||
{
|
||||
Decorators = new ReadOnlyCollection<T>(_decorators);
|
||||
get
|
||||
{
|
||||
lock (_decorators)
|
||||
return new ReadOnlyCollection<T>(_decorators);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -20,7 +20,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
|
||||
/// </summary>
|
||||
IReadOnlyList<T> Decorators { get; }
|
||||
IReadOnlyCollection<T> Decorators { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds an <see cref="IDecorator"/> to the <see cref="IDecoratable"/>.
|
||||
|
||||
@ -30,7 +30,7 @@ namespace RGB.NET.Core
|
||||
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
|
||||
public ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
@ -30,7 +31,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a collection <see cref="IDeviceUpdateTrigger"/> registered to this device provider.
|
||||
/// </summary>
|
||||
IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
|
||||
ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -26,15 +26,20 @@ namespace RGB.NET.Core
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>.
|
||||
/// This collection should be locked when enumerated in a multi-threaded application.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IRGBDevice> Devices { get; }
|
||||
public IEnumerable<IRGBDevice> Devices
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_devices)
|
||||
return new ReadOnlyCollection<IRGBDevice>(_devices);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly list containing all registered <see cref="IUpdateTrigger"/>.
|
||||
/// This collection should be locked when enumerated in a multi-threaded application.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IUpdateTrigger> UpdateTriggers { get; }
|
||||
public IEnumerable<IUpdateTrigger> UpdateTriggers => new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>.
|
||||
@ -48,7 +53,7 @@ namespace RGB.NET.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (Devices)
|
||||
lock (_devices)
|
||||
return _devices.SelectMany(x => x);
|
||||
}
|
||||
}
|
||||
@ -119,9 +124,6 @@ namespace RGB.NET.Core
|
||||
public RGBSurface()
|
||||
{
|
||||
_deltaTimeCounter = Stopwatch.StartNew();
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(_devices);
|
||||
UpdateTriggers = new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -144,8 +146,8 @@ namespace RGB.NET.Core
|
||||
bool render = customData["render"] as bool? ?? true;
|
||||
bool updateDevices = customData["updateDevices"] as bool? ?? true;
|
||||
|
||||
lock (UpdateTriggers)
|
||||
lock (Devices)
|
||||
lock (_updateTriggers)
|
||||
lock (_devices)
|
||||
{
|
||||
OnUpdating(updateTrigger, customData);
|
||||
|
||||
@ -176,7 +178,7 @@ namespace RGB.NET.Core
|
||||
public void Dispose()
|
||||
{
|
||||
List<IRGBDevice> devices;
|
||||
lock (Devices)
|
||||
lock (_devices)
|
||||
devices = new List<IRGBDevice>(_devices);
|
||||
|
||||
foreach (IRGBDevice device in devices)
|
||||
@ -265,7 +267,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="device">The <see cref="IRGBDevice"/> to attach.</param>
|
||||
public void Attach(IRGBDevice device)
|
||||
{
|
||||
lock (Devices)
|
||||
lock (_devices)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(device.DeviceInfo.DeviceName)) throw new RGBDeviceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' has no valid name.");
|
||||
if (device.Surface != null) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is already attached to a surface.");
|
||||
@ -285,7 +287,7 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if the <see cref="IRGBDevice"/> could be detached; <c>false</c> otherwise.</returns>
|
||||
public void Detach(IRGBDevice device)
|
||||
{
|
||||
lock (Devices)
|
||||
lock (_devices)
|
||||
{
|
||||
if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is not attached to this surface.");
|
||||
|
||||
@ -312,7 +314,7 @@ namespace RGB.NET.Core
|
||||
|
||||
private void UpdateSurfaceRectangle()
|
||||
{
|
||||
lock (Devices)
|
||||
lock (_devices)
|
||||
{
|
||||
Rectangle devicesRectangle = new(_devices.Select(d => d.Boundary));
|
||||
Boundary = Boundary.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));
|
||||
|
||||
@ -68,7 +68,7 @@ namespace RGB.NET.Devices.DMX.E131
|
||||
this.Hostname = deviceDefinition.Hostname;
|
||||
this.Port = deviceDefinition.Port;
|
||||
this.Universe = deviceDefinition.Universe;
|
||||
|
||||
|
||||
byte[]? cid = deviceDefinition.CID;
|
||||
if ((cid == null) || (cid.Length != CID_LENGTH))
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace RGB.NET.Devices.DMX.E131
|
||||
new Random().NextBytes(cid);
|
||||
}
|
||||
|
||||
CID = cid;
|
||||
CID = cid!;
|
||||
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user