Files
lmxopcua/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/IAlarmInitialStateSignal.cs
T

69 lines
3.9 KiB
C#

namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions;
/// <summary>
/// Optional companion to <see cref="IAlarmSource"/>: the driver says when the standing state of a set of its
/// conditions has been <b>established</b> — the initial replay, refresh, poll or walk that covers them has
/// completed and every alarm event it produced has already been raised (plan
/// <c>2026-11-23-grpc-data-connections-history-alarms</c> §5.1, F1/F2/G1/G5).
/// </summary>
/// <remarks>
/// <para>
/// <b>An ordered callback, never a <see cref="System.Threading.Tasks.Task"/> (F2).</b> Raise
/// <see cref="InitialAlarmStateDelivered"/> synchronously, on the same thread and callback path as
/// <see cref="IAlarmSource.OnAlarmEvent"/>, <b>after</b> the last alarm event the completed read covers. The
/// host marshals both onto the same actor mailbox, so the "known" mark it derives is applied after every
/// projection the driver emitted before raising it. A task continuation could overtake queued transitions.
/// </para>
/// <para>
/// <b>Carry what it covers (G1).</b> <see cref="AlarmInitialStateEventArgs.ConditionIds"/> lists the driver
/// <c>ConditionId</c>s (= the condition's RawPath, the routing key of the alarm event) whose state the
/// completed read established — never "the whole driver". An unreachable device's conditions are simply
/// left out and stay unknown.
/// </para>
/// <para>
/// <b>Raise on every completed read or cycle</b>, not only the first. Repeats are no-ops downstream; they are
/// what makes conditions known again after a reconnect or a deploy that adds conditions.
/// </para>
/// <para>
/// <b>Suppression gate (G5).</b> Obey exactly the gate <see cref="IAlarmSource.OnAlarmEvent"/> obeys: raise
/// only while an alarm subscription is live. A refresh / poll / sentinel that completes while events are
/// suppressed raises nothing; the first signal after (re)subscribe follows the post-subscribe replay.
/// </para>
/// <para>
/// <b>A source that cannot signal at all</b> (an OPC UA upstream without ConditionRefresh) raises the event
/// once with <see cref="AlarmInitialStateEventArgs.Unsignalable"/> set: the host then applies its
/// per-driver-type backstop timer to those conditions instead. No other shipped source should use it.
/// </para>
/// </remarks>
public interface IAlarmInitialStateSignal
{
/// <summary>The standing state of <see cref="AlarmInitialStateEventArgs.ConditionIds"/> has been delivered.</summary>
event EventHandler<AlarmInitialStateEventArgs>? InitialAlarmStateDelivered;
}
/// <summary>Payload of <see cref="IAlarmInitialStateSignal.InitialAlarmStateDelivered"/>.</summary>
public sealed class AlarmInitialStateEventArgs : EventArgs
{
/// <summary>Creates the payload.</summary>
/// <param name="conditionIds">The driver condition ids (RawPaths) whose state the completed read established.</param>
/// <param name="unsignalable">
/// <see langword="true"/> when the source can never signal for these conditions (no refresh upstream);
/// the host's backstop timer applies instead of an immediate mark.
/// </param>
public AlarmInitialStateEventArgs(IReadOnlyList<string> conditionIds, bool unsignalable = false)
{
ArgumentNullException.ThrowIfNull(conditionIds);
ConditionIds = conditionIds;
Unsignalable = unsignalable;
}
/// <summary>The driver condition ids (= RawPaths) the completed read covers. Never "everything".</summary>
public IReadOnlyList<string> ConditionIds { get; }
/// <summary>
/// The source reports <c>InitialStateUnsignalable</c> for these conditions: no real signal will ever come,
/// so the per-driver-type backstop timer (OpcUaClient only) decides when they become known.
/// </summary>
public bool Unsignalable { get; }
}