Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/ConditionStateRecords.cs
T

99 lines
5.2 KiB
C#

using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
/// <summary>
/// The origin-owned activation marker of one condition (plan §5.6 step 3, T3): <c>(serving incarnation,
/// per-condition sequence)</c>. The sequence moves only on a NEW occurrence — an Active false→true edge or any
/// Acked true→false edge — never on a re-projection that leaves Active/Acked unchanged.
/// </summary>
/// <param name="Incarnation">The node manager's serving incarnation (one per process lifetime).</param>
/// <param name="Sequence">The per-condition occurrence sequence.</param>
public readonly record struct ConditionActivationMarker(string Incarnation, ulong Sequence);
/// <summary>
/// One immutable, SDK-free copy of a live condition's state (plan §5.1), produced by the node manager under its
/// <c>Lock</c> — either as a delta (raised for every condition state change) or inside a
/// <see cref="ConditionSnapshotSlice"/>. Invisible until A2 puts it on the wire.
/// </summary>
/// <param name="Realm">The condition's realm (Raw = native RawPath, Uns = ScriptedAlarmId).</param>
/// <param name="ConditionId">The condition node id within <paramref name="Realm"/>.</param>
/// <param name="IsNative">Driver-fed (native) rather than scripted.</param>
/// <param name="Version">The hub version: the delta's own version, or the slice watermark for a snapshot copy.</param>
/// <param name="Removed">A removal record: the condition left the address space.</param>
/// <param name="StateKnown">
/// The condition's state has actually been established (§5.1 T2). A record with <c>false</c> never changes a
/// consumer's last state; it only marks the condition Uncertain.
/// </param>
/// <param name="Active">Part 9 ActiveState.</param>
/// <param name="Acknowledged">Part 9 AckedState.</param>
/// <param name="Confirmed">Part 9 ConfirmedState.</param>
/// <param name="Enabled">Part 9 EnabledState.</param>
/// <param name="Shelving">The shelving kind.</param>
/// <param name="Severity">The node's Part 9 severity (1..1000).</param>
/// <param name="Message">The node's message text.</param>
/// <param name="Quality">The condition's source-data Quality status code.</param>
/// <param name="ConditionClassName">The Part 9 ConditionClassName text, if set.</param>
/// <param name="TimeUtc">The condition's <c>Time</c>.</param>
/// <param name="Retain">Part 9 Retain.</param>
/// <param name="Activation">The origin-owned activation marker (T3).</param>
/// <param name="Comment">The condition's Comment text, if any.</param>
/// <param name="ClientUserId">Who left that comment, if recorded.</param>
public sealed record ConditionStateRecord(
AddressSpaceRealm Realm,
string ConditionId,
bool IsNative,
long Version,
bool Removed,
bool StateKnown,
bool Active,
bool Acknowledged,
bool Confirmed,
bool Enabled,
AlarmShelvingKind Shelving,
ushort Severity,
string Message,
uint Quality,
string? ConditionClassName,
DateTime TimeUtc,
bool Retain,
ConditionActivationMarker Activation,
string? Comment = null,
string? ClientUserId = null);
/// <summary>
/// The node manager's SDK-free delta callback (plan §5.1). Implemented by the Runtime's <c>ConditionStateHub</c>.
/// </summary>
/// <remarks>
/// Both members are called <b>under the node manager's <c>Lock</c></b>, which is what makes a snapshot cut atomic:
/// every delta is either inside a slice or after its watermark. Implementations must therefore only enqueue —
/// no I/O, never block, never call back into the node manager.
/// </remarks>
public interface IConditionStateSink
{
/// <summary>The version of the last appended record (the snapshot watermark). Read under the node manager's Lock.</summary>
long Watermark { get; }
/// <summary>Append one delta record. The sink assigns its version; the record's own <c>Version</c> is ignored.</summary>
/// <param name="record">The record.</param>
/// <returns>The version assigned.</returns>
long Append(ConditionStateRecord record);
/// <summary>
/// The node manager's address-space apply state changed: <see langword="false"/> when a rebuild began (the
/// condition set is being re-created), <see langword="true"/> when <c>CompleteAddressSpaceApply</c> ran. Part of
/// the <c>snapshot_complete</c> readiness (§5.1: apply complete + Primary verdict).
/// </summary>
/// <param name="complete">Whether the current apply has completed.</param>
void OnApplyStateChanged(bool complete);
}
/// <summary>
/// One <c>Lock</c> hold of <see cref="OtOpcUaNodeManager.SnapshotConditions"/>: at most <c>MaxConditions</c>
/// records plus the watermark at that instant. A delta for one of these conditions with a version above
/// <see cref="Watermark"/> applies after the slice; one at or below it is already inside.
/// </summary>
/// <param name="Watermark">The sink's watermark taken under the same hold.</param>
/// <param name="Records">The copied records (each carries <see cref="Watermark"/> as its version).</param>
public sealed record ConditionSnapshotSlice(long Watermark, IReadOnlyList<ConditionStateRecord> Records);