mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added heartbeat functionality to device update trigger
This commit is contained in:
parent
a9adf9763c
commit
c6cfe35124
@ -42,7 +42,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractRGBDeviceProvider" /> class.
|
||||
/// </summary>
|
||||
@ -157,7 +157,6 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
|
||||
/// <returns>The newly created update trigger.</returns>
|
||||
protected virtual IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resets the device provider and disposes all devices and update triggers.
|
||||
/// </summary>
|
||||
|
||||
@ -40,4 +40,16 @@ public static class CustomUpdateDataExtension
|
||||
customUpdateData[CustomUpdateDataIndex.UPDATE_DEVICES] = value;
|
||||
return customUpdateData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="CustomUpdateDataIndex.HEARTBEAT"/>-Parameter to the given value.
|
||||
/// </summary>
|
||||
/// <param name="customUpdateData">The update-data to modify.</param>
|
||||
/// <param name="value">The value to set.</param>
|
||||
/// <returns>The modified update-data.</returns>
|
||||
public static CustomUpdateData Heartbeat(this CustomUpdateData customUpdateData, bool value = true)
|
||||
{
|
||||
customUpdateData[CustomUpdateDataIndex.HEARTBEAT] = value;
|
||||
return customUpdateData;
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,11 @@ public static class CustomUpdateDataIndex
|
||||
/// default: true
|
||||
/// </summary>
|
||||
public const string UPDATE_DEVICES = "updateDevices";
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="DeviceUpdateTrigger"/> to indicate heatbeat updates.
|
||||
/// </summary>
|
||||
public const string HEARTBEAT = "heartbeat";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -52,9 +53,20 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time in ms after which a refresh-request is sent even if no changes are made in the meantime to prevent the target from timing out or similar problems.
|
||||
/// To disable heartbeats leave it at 0.
|
||||
/// </summary>
|
||||
public int HeartbeatTimer { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double LastUpdateTime { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timestamp of the last update.
|
||||
/// </summary>
|
||||
protected long LastUpdateTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the event to trigger when new data is available (<see cref="TriggerHasData"/>).
|
||||
/// </summary>
|
||||
@ -145,6 +157,14 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
||||
while (!UpdateToken.IsCancellationRequested)
|
||||
if (HasDataEvent.WaitOne(Timeout))
|
||||
LastUpdateTime = TimerHelper.Execute(() => OnUpdate(), UpdateFrequency * 1000);
|
||||
else if ((HeartbeatTimer > 0) && (LastUpdateTimestamp > 0) && ((Stopwatch.GetTimestamp() - LastUpdateTimestamp) > HeartbeatTimer))
|
||||
OnUpdate(new CustomUpdateData().Heartbeat());
|
||||
}
|
||||
|
||||
protected override void OnUpdate(CustomUpdateData? updateData = null)
|
||||
{
|
||||
base.OnUpdate(updateData);
|
||||
LastUpdateTimestamp = Stopwatch.GetTimestamp();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user