using System; using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.SteelSeries.API; using RGB.NET.Devices.SteelSeries.HID; namespace RGB.NET.Devices.SteelSeries { /// /// /// Represents a device provider responsible for SteelSeries- devices. /// public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields private static SteelSeriesDeviceProvider? _instance; /// /// Gets the singleton instance. /// public static SteelSeriesDeviceProvider Instance => _instance ?? new SteelSeriesDeviceProvider(); #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 SteelSeriesDeviceProvider() { if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); _instance = this; } #endregion #region Methods protected override void InitializeSDK() { if (!SteelSeriesSDK.IsInitialized) SteelSeriesSDK.Initialize(); } protected override IEnumerable GetLoadedDevices(RGBDeviceType loadFilter) { DeviceChecker.LoadDeviceList(loadFilter); return base.GetLoadedDevices(loadFilter); } protected override IEnumerable LoadDevices() { foreach ((string model, RGBDeviceType deviceType, int _, SteelSeriesDeviceType steelSeriesDeviceType, Dictionary ledMapping) in DeviceChecker.ConnectedDevices) { string? apiName = steelSeriesDeviceType.GetAPIName(); if (apiName == null) Throw(new RGBDeviceException($"Missing API-name for device {model}")); else yield return new SteelSeriesRGBDevice(new SteelSeriesRGBDeviceInfo(deviceType, model, steelSeriesDeviceType), apiName, ledMapping, GetUpdateTrigger()); } } /// public override void Dispose() { base.Dispose(); try { SteelSeriesSDK.Dispose(); } catch { /* shit happens */ } } #endregion } }