// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System; using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Layout; namespace RGB.NET.Devices.Debug { /// /// /// Represents a device provider responsible for debug devices. /// public class DebugDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields private static DebugDeviceProvider? _instance; /// /// Gets the singleton instance. /// public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider(); private List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = new(); #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// Thrown if this constructor is called even if there is already an instance of this class. public DebugDeviceProvider() { if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); _instance = this; } #endregion #region Methods /// /// Adds a new fake device definition. /// /// The path of the layout file to be used. /// A action emulating led-updates. public void AddFakeDeviceDefinition(IDeviceLayout layout, Action>? updateLedsAction = null) => _fakeDeviceDefinitions.Add((layout, updateLedsAction)); /// /// Removes all previously added fake device definitions. /// public void ClearFakeDeviceDefinitions() => _fakeDeviceDefinitions.Clear(); /// protected override void InitializeSDK() { } /// protected override IEnumerable LoadDevices() { foreach ((IDeviceLayout layout, Action>? updateLedsAction) in _fakeDeviceDefinitions) yield return new DebugRGBDevice(layout, updateLedsAction); } /// public override void Dispose() { base.Dispose(); _fakeDeviceDefinitions.Clear(); } #endregion } }