Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionPlacements.cs
T

64 lines
4.3 KiB
C#

using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
using ZB.MOM.WW.OtOpcUa.Core.Authorization;
namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
/// <summary>A1: where an origin condition comes from (wire <c>ConditionInfo.source_kind</c> NATIVE / SCRIPTED).</summary>
public enum ConditionSourceKind { Unspecified = 0, Native = 1, Scripted = 2 }
/// <summary>
/// A1: an origin condition's identity in the node manager — the realm key its condition is registered under
/// (<c>(Raw, RawPath)</c> for a native condition, <c>(Uns, ScriptedAlarmId)</c> for a scripted one).
/// ⚠️ ORIGIN-INTERNAL: a native <see cref="ConditionId"/> IS a RawPath; it never goes on the wire (the wire carries
/// the keyed <c>condition_key</c> instead, <see cref="ConditionKeys"/>).
/// </summary>
public readonly record struct OriginConditionRef(AddressSpaceRealm Realm, string ConditionId);
/// <summary>
/// A1 (§5.2 "Addressing within the listing export's realm"): one realm-local placement of an origin condition, as the
/// origin's catalog knows it.
/// <list type="bullet">
/// <item>Raw: <see cref="View"/> = the raw namespace at the RawPath; <see cref="Parent"/> = its device/group folder;
/// <see cref="Scope"/> = the raw tag's ACL subject.</item>
/// <item>UNS native: <see cref="View"/> = the uns namespace at the RESERVED reference id
/// <c>Area/Line/Equipment/EffectiveName</c> of each <c>UnsTagReference</c> to the alarm-bearing tag (no UNS node
/// exists there, #896; the effective-name guard reserves it); <see cref="Parent"/> = that equipment;
/// <see cref="Scope"/> = the equipment-owned subject.</item>
/// <item>UNS scripted: <see cref="View"/> = the uns namespace at the ScriptedAlarmId; <see cref="Parent"/> = its
/// equipment; <see cref="Scope"/> = the equipment-owned subject. Scripted conditions have no Raw placement.</item>
/// </list>
/// ⚠️ ORIGIN-INTERNAL (carries <see cref="Condition"/>). What may reach a peer is
/// <see cref="ConditionPlacementView"/>, via <see cref="LocalExportCatalog.ListConditions"/>.
/// </summary>
/// <param name="DriverType">A2b: the backing driver's type for a native condition (null for scripted); decides the Galaxy
/// service-ack opt-in (§6).</param>
public sealed record LocalConditionPlacement(DataView View, DataView Parent, NodeScope Scope, string BrowseName,
ConditionSourceKind SourceKind, OriginConditionRef Condition, string EntityKind, string EntityId, string? DriverType = null)
{
/// <summary>A2b: a Galaxy-sourced native condition (remote Acknowledge/AddComment need the export's opt-in).</summary>
public bool IsGalaxy => SourceKind == ConditionSourceKind.Native
&& string.Equals(DriverType, ZB.MOM.WW.OtOpcUa.Core.Abstractions.DriverTypeNames.Galaxy, StringComparison.OrdinalIgnoreCase);
/// <summary>The peer-safe projection: address, parent and name, in the placement's own realm.</summary>
public ConditionPlacementView ToView() => new(View, Parent, BrowseName);
}
/// <summary>A1: a placement as a listing may carry it (no origin condition id, no backing source).</summary>
public sealed record ConditionPlacementView(DataView View, DataView Parent, string BrowseName);
/// <summary>
/// A1: one condition as an export listing presents it — the opaque <see cref="ConditionKey"/> (equal across every
/// listing, principal, restart and pair member) and its placements INSIDE the listed export root, all in that root's
/// realm. Nothing here names a RawPath unless the listing is itself a Raw listing.
/// </summary>
public sealed record ExportedCondition(string ConditionKey, ConditionSourceKind SourceKind,
IReadOnlyList<ConditionPlacementView> Placements);
/// <summary>
/// A2: one condition of an export listing together with its origin-internal identity. ⚠️ ORIGIN-INTERNAL
/// (<see cref="Ref"/> names a RawPath for a native condition); only <see cref="Exported"/> may reach a peer.
/// </summary>
/// <param name="Methods">A2b: the methods the listing principal may call on it (0 when methods are not servable).</param>
internal sealed record ScopedCondition(OriginConditionRef Ref, ExportedCondition Exported, DataConditionMethods Methods = DataConditionMethods.None);