1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2026-03-25 08:18:46 +00:00

Compare commits

..

No commits in common. "d070f0bbcb759843b4a0363700a166246500237a" and "7415c6b4efe0987d5628cb52909b960956e9a7e2" have entirely different histories.

16 changed files with 115 additions and 432 deletions

View File

@ -12,8 +12,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
private bool _isDisposed = false;
private readonly double _defaultUpdateRateHardLimit; private readonly double _defaultUpdateRateHardLimit;
/// <inheritdoc /> /// <inheritdoc />
@ -62,8 +60,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit; this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit;
} }
~AbstractRGBDeviceProvider() => Dispose(false);
#endregion #endregion
#region Methods #region Methods
@ -71,8 +67,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
ThrowsExceptions = throwExceptions; ThrowsExceptions = throwExceptions;
try try
@ -114,8 +108,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns>The filtered collection of loaded devices.</returns> /// <returns>The filtered collection of loaded devices.</returns>
protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter) protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
List<IRGBDevice> devices = new(); List<IRGBDevice> devices = new();
foreach (IRGBDevice device in LoadDevices()) foreach (IRGBDevice device in LoadDevices())
{ {
@ -160,8 +152,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns>The update trigger mapped to the specified id.</returns> /// <returns>The update trigger mapped to the specified id.</returns>
protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null) protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger)) if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger))
UpdateTriggerMapping[id] = (updaeTrigger = CreateUpdateTrigger(id, updateRateHardLimit ?? _defaultUpdateRateHardLimit)); UpdateTriggerMapping[id] = (updaeTrigger = CreateUpdateTrigger(id, updateRateHardLimit ?? _defaultUpdateRateHardLimit));
@ -181,8 +171,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// </summary> /// </summary>
protected virtual void Reset() protected virtual void Reset()
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values) foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values)
updateTrigger.Dispose(); updateTrigger.Dispose();
@ -204,8 +192,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns><c>true</c> if the device was added successfully; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the device was added successfully; otherwise <c>false</c>.</returns>
protected virtual bool AddDevice(IRGBDevice device) protected virtual bool AddDevice(IRGBDevice device)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (InternalDevices.Contains(device)) return false; if (InternalDevices.Contains(device)) return false;
InternalDevices.Add(device); InternalDevices.Add(device);
@ -221,8 +207,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns><c>true</c> if the device was removed successfully; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the device was removed successfully; otherwise <c>false</c>.</returns>
protected virtual bool RemoveDevice(IRGBDevice device) protected virtual bool RemoveDevice(IRGBDevice device)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (!InternalDevices.Remove(device)) return false; if (!InternalDevices.Remove(device)) return false;
try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ } try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ }
@ -257,26 +241,12 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args); protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args);
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public virtual void Dispose()
{ {
if (_isDisposed) return; Reset();
try
{
Dispose(true);
}
catch { /* don't throw in dispose! */ }
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
_isDisposed = true;
} }
/// <summary>
/// Disposes the object and frees all resources.
/// </summary>
/// <param name="disposing"><c>true</c> if explicitely called through the Dispose-Method, <c>false</c> if called by the destructor.</param>
protected virtual void Dispose(bool disposing) => Reset();
#endregion #endregion
} }

View File

@ -16,21 +16,11 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static AsusDeviceProvider? _instance; private static AsusDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="AsusDeviceProvider"/> instance. /// Gets the singleton <see cref="AsusDeviceProvider"/> instance.
/// </summary> /// </summary>
public static AsusDeviceProvider Instance public static AsusDeviceProvider Instance => _instance ?? new AsusDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new AsusDeviceProvider();
}
}
private IAuraSdk2? _sdk; private IAuraSdk2? _sdk;
private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk
@ -44,13 +34,10 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public AsusDeviceProvider() public AsusDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -93,19 +80,15 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _sdk?.ReleaseControl(0); } try { _sdk?.ReleaseControl(0); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_devices = null; _devices = null;
_sdk = null; _sdk = null;
_instance = null;
}
} }
#endregion #endregion

View File

@ -17,21 +17,11 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CoolerMasterDeviceProvider? _instance; private static CoolerMasterDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance. /// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CoolerMasterDeviceProvider Instance public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new CoolerMasterDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -54,13 +44,10 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CoolerMasterDeviceProvider() public CoolerMasterDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -107,17 +94,12 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _CoolerMasterSDK.Reload(); } try { _CoolerMasterSDK.Reload(); }
catch { /* Unlucky.. */ } catch { /* Unlucky.. */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -17,21 +17,11 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CorsairDeviceProvider? _instance; private static CorsairDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CorsairDeviceProvider"/> instance. /// Gets the singleton <see cref="CorsairDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CorsairDeviceProvider Instance public static CorsairDeviceProvider Instance => _instance ?? new CorsairDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new CorsairDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -89,13 +79,10 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CorsairDeviceProvider() public CorsairDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -313,20 +300,12 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _CUESDK.CorsairDisconnect(); } try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ }
catch { /* at least we tried */ } try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ }
try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -18,21 +18,11 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CorsairLegacyDeviceProvider? _instance; private static CorsairLegacyDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CorsairLegacyDeviceProvider"/> instance. /// Gets the singleton <see cref="CorsairLegacyDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CorsairLegacyDeviceProvider Instance public static CorsairLegacyDeviceProvider Instance => _instance ?? new CorsairLegacyDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new CorsairLegacyDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -65,13 +55,10 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CorsairLegacyDeviceProvider() public CorsairLegacyDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -214,17 +201,12 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _CUESDK.UnloadCUESDK(); } try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -16,21 +16,11 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DMXDeviceProvider? _instance; private static DMXDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DMXDeviceProvider"/> instance. /// Gets the singleton <see cref="DMXDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DMXDeviceProvider Instance public static DMXDeviceProvider Instance => _instance ?? new DMXDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new DMXDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -46,13 +36,10 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DMXDeviceProvider() public DMXDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -99,16 +86,5 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
return updateTrigger; return updateTrigger;
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -16,21 +16,11 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DebugDeviceProvider? _instance; private static DebugDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DebugDeviceProvider"/> instance. /// Gets the singleton <see cref="DebugDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DebugDeviceProvider Instance public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new DebugDeviceProvider();
}
}
private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new(); private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new();
@ -43,13 +33,10 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DebugDeviceProvider() public DebugDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -79,16 +66,11 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
_fakeDeviceDefinitions.Clear(); _fakeDeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -20,21 +20,11 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static LogitechDeviceProvider? _instance; private static LogitechDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance. /// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary> /// </summary>
public static LogitechDeviceProvider Instance public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new LogitechDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -174,13 +164,9 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public LogitechDeviceProvider() public LogitechDeviceProvider()
{ {
lock (_lock) if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
{
if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -268,11 +254,9 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _LogitechGSDK.LogiLedRestoreLighting(); } try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
@ -280,8 +264,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
try { _LogitechGSDK.UnloadLogitechGSDK(); } try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null; GC.SuppressFinalize(this);
}
} }
#endregion #endregion

View File

@ -17,21 +17,11 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static MsiDeviceProvider? _instance; private static MsiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="MsiDeviceProvider"/> instance. /// Gets the singleton <see cref="MsiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static MsiDeviceProvider Instance public static MsiDeviceProvider Instance => _instance ?? new MsiDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new MsiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -54,13 +44,10 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public MsiDeviceProvider() public MsiDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -111,17 +98,14 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
private void ThrowMsiError(int errorCode, bool isCritical = false) => Throw(new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)), isCritical); private void ThrowMsiError(int errorCode, bool isCritical = false) => Throw(new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)), isCritical);
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { _MsiSDK.UnloadMsiSDK(); } try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null; GC.SuppressFinalize(this);
}
} }
#endregion #endregion

View File

@ -17,21 +17,11 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static NovationDeviceProvider? _instance; private static NovationDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="NovationDeviceProvider"/> instance. /// Gets the singleton <see cref="NovationDeviceProvider"/> instance.
/// </summary> /// </summary>
public static NovationDeviceProvider Instance public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new NovationDeviceProvider();
}
}
#endregion #endregion
@ -42,13 +32,10 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
private NovationDeviceProvider() private NovationDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -80,16 +67,5 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
} }
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -14,9 +14,6 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private readonly List<OpenRgbClient> _clients = new(); private readonly List<OpenRgbClient> _clients = new();
private static OpenRGBDeviceProvider? _instance; private static OpenRGBDeviceProvider? _instance;
@ -24,14 +21,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance. /// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance.
/// </summary> /// </summary>
public static OpenRGBDeviceProvider Instance public static OpenRGBDeviceProvider Instance => _instance ?? new OpenRGBDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new OpenRGBDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -57,13 +47,10 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public OpenRGBDeviceProvider() public OpenRGBDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -162,11 +149,9 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
foreach (OpenRgbClient client in _clients) foreach (OpenRgbClient client in _clients)
{ {
@ -176,9 +161,6 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
_clients.Clear(); _clients.Clear();
DeviceDefinitions.Clear(); DeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -25,21 +25,11 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static PicoPiDeviceProvider? _instance; private static PicoPiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance. /// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static PicoPiDeviceProvider Instance public static PicoPiDeviceProvider Instance => _instance ?? new PicoPiDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new PicoPiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets the HID-definitions for PicoPi-devices. /// Gets the HID-definitions for PicoPi-devices.
@ -66,13 +56,10 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public PicoPiDeviceProvider() public PicoPiDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -139,16 +126,5 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
_sdks.Clear(); _sdks.Clear();
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -19,21 +19,11 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static RazerDeviceProvider? _instance; private static RazerDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="RazerDeviceProvider"/> instance. /// Gets the singleton <see cref="RazerDeviceProvider"/> instance.
/// </summary> /// </summary>
public static RazerDeviceProvider Instance public static RazerDeviceProvider Instance => _instance ?? new RazerDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new RazerDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -277,13 +267,10 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public RazerDeviceProvider() public RazerDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -356,20 +343,15 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
TryUnInit(); TryUnInit();
// DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit
//try { _RazerSDK.UnloadRazerSDK(); } //try { _RazerSDK.UnloadRazerSDK(); }
//catch { /* at least we tried */ } //catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -20,21 +20,11 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static SteelSeriesDeviceProvider? _instance; private static SteelSeriesDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance. /// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance.
/// </summary> /// </summary>
public static SteelSeriesDeviceProvider Instance public static SteelSeriesDeviceProvider Instance => _instance ?? new SteelSeriesDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new SteelSeriesDeviceProvider();
}
}
private const int VENDOR_ID = 0x1038; private const int VENDOR_ID = 0x1038;
@ -102,13 +92,10 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public SteelSeriesDeviceProvider() public SteelSeriesDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -146,17 +133,12 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER }; protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER };
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
try { SteelSeriesSDK.Dispose(); } try { SteelSeriesSDK.Dispose(); }
catch { /* shit happens */ } catch { /* shit happens */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -16,21 +16,11 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WS281XDeviceProvider? _instance; private static WS281XDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WS281XDeviceProvider"/> instance. /// Gets the singleton <see cref="WS281XDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WS281XDeviceProvider Instance public static WS281XDeviceProvider Instance => _instance ?? new WS281XDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new WS281XDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -48,13 +38,10 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WS281XDeviceProvider() public WS281XDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -83,16 +70,11 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
DeviceDefinitions.Clear(); DeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -16,21 +16,11 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WootingDeviceProvider? _instance; private static WootingDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WootingDeviceProvider"/> instance. /// Gets the singleton <see cref="WootingDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WootingDeviceProvider Instance public static WootingDeviceProvider Instance => _instance ?? new WootingDeviceProvider();
{
get
{
lock (_lock)
return _instance ?? new WootingDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications.
@ -66,13 +56,10 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WootingDeviceProvider() public WootingDeviceProvider()
{
lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}");
_instance = this; _instance = this;
} }
}
#endregion #endregion
@ -107,20 +94,15 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Dispose(bool disposing) public override void Dispose()
{ {
lock (_lock) base.Dispose();
{
base.Dispose(disposing);
lock (_WootingSDK.SdkLock) lock (_WootingSDK.SdkLock)
{ {
try { _WootingSDK.UnloadWootingSDK(); } try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
} }
_instance = null;
}
} }
#endregion #endregion