namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa; /// /// Abstraction over the OPC UA SDK's address space. OpcUaPublishActor consumes this /// so the Runtime project doesn't reference Opc.Ua.Server directly — production /// binds a real SDK-backed sink in the fused Host's wiring, dev/Mac binds the /// no-op. /// public interface IOpcUaAddressSpaceSink { /// Write a Variable node's current value + quality + source timestamp. /// The OPC UA node ID of the variable. /// The value to write. /// The quality status of the value. /// The source timestamp in UTC. /// Which of the two v3 namespaces ( device tree or /// equipment tree) the lives in — the sink /// resolves the namespace index from the realm rather than parsing it out of the id string. WP3's fan-out /// calls this once per NodeId (raw + every referencing UNS node) with the matching realm. void WriteValue(string nodeId, object? value, OpcUaQuality quality, DateTime sourceTimestampUtc, AddressSpaceRealm realm); /// Write an alarm-condition's full Part 9 state. When a real condition node has been /// materialised for via , /// this projects the whole /// (Enabled/Active/Acked/Confirmed/Shelving/Severity/Message) onto it and recomputes Retain; /// otherwise it falls back to the legacy two-element [Active, Acknowledged] placeholder /// variable. A materialised condition also fires a Part 9 condition event on each transition (T16) /// so subscribed clients receive the alarm event, not just the changed attributes. /// The OPC UA node ID of the alarm (== ScriptedAlarmId for materialised conditions). /// The full condition state to project onto the node. /// The source timestamp in UTC. /// The namespace realm lives in (must match the realm /// the condition was materialised under). void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm); /// #477 — annotate a materialised condition's source-data quality OUT OF BAND from any alarm /// transition (used by the driver-connectivity path: comms lost → , /// restored → ). Sets ONLY the condition's Quality — never /// Active/Acked/Severity/Retain (a comms-lost active alarm stays active) — and fires one Part 9 event /// only on a quality-bucket change. A no-op for an unmaterialised / non-condition node. /// The condition node id (RawPath for a native alarm). /// The source-data quality to annotate. /// The connectivity transition timestamp in UTC. /// The namespace realm the condition was materialised under. void WriteAlarmQuality(string alarmNodeId, OpcUaQuality quality, DateTime sourceTimestampUtc, AddressSpaceRealm realm); /// /// Materialise a real OPC UA Part 9 alarm-condition node under its equipment folder so clients /// can browse it as a proper condition (with basic Active/Ack state). The node id equals the /// alarm node id (the ScriptedAlarmId) so subsequent calls update /// it. Used by AddressSpaceApplier.MaterialiseScriptedAlarms. Idempotent. /// /// The alarm node ID (== ScriptedAlarmId); becomes the condition's NodeId. /// The equipment folder node ID the condition parents under. /// Human-readable condition name (BrowseName / DisplayName / Message). /// Domain alarm type — mapped to the SDK condition subtype by the sink. /// Domain severity (OPC UA 1..1000 scale); mapped to the SDK severity buckets. /// When true this is a driver-fed (native, e.g. Galaxy) equipment-tag alarm; when /// false (default) it is a scripted alarm. The node manager tracks native condition node ids so a later /// task can route a native condition's inbound Acknowledge to the driver instead of the scripted engine. /// The namespace realm the condition (and its parent folder ) /// live in. void MaterialiseAlarmCondition(string alarmNodeId, string equipmentNodeId, string displayName, string alarmType, int severity, AddressSpaceRealm realm, bool isNative = false); /// /// v3 Batch 4 (multi-notifier native alarms) — wire an already-materialised native alarm condition /// (, materialised at the raw tag via /// with ConditionId = the RawPath) as an event notifier of EACH referencing equipment's UNS folder, so /// the condition's single ReportEvent fans one event to every referencing equipment root /// WITHOUT re-reporting per root (distinct EventIds would break Server-object dedup + Part 9 ack /// correlation). Per folder the sink wires the SDK's bidirectional notifier pattern /// (alarm.AddNotifier(isInverse:true, folder) + folder.AddNotifier(isInverse:false, alarm)) /// and promotes the folder to an event notifier. Idempotent (a re-wire of the same pair updates, /// never duplicates); a missing endpoint is a no-op (logged, never thrown) so a mid-rebuild race /// can't fault a deploy. The sink tracks each wired pair so a later rebuild / condition-removal / /// equipment-subtree-removal tears the notifier down bidirectionally (no inverse-notifier entry leaks /// across redeploys). /// /// The native alarm condition's node id (== the backing tag's RawPath). /// The namespace realm the condition lives in (Raw for native alarms). /// The equipment folder node ids (their s= ids) to wire as /// extra event-notifier roots for this condition. An unknown / not-yet-materialised folder id is skipped. /// The namespace realm the notifier folders live in (Uns for equipment folders). void WireAlarmNotifiers(string alarmNodeId, AddressSpaceRealm alarmRealm, IReadOnlyList notifierFolderNodeIds, AddressSpaceRealm notifierFolderRealm); /// /// Ensure a folder node exists under the given parent. Used by AddressSpaceApplier to /// materialise the UNS Area/Line/Equipment hierarchy in the address space. When /// is null the folder is parented under the namespace /// root. Idempotent: calling twice with the same id is safe. /// /// The OPC UA node ID for the folder. /// The parent folder node ID, or null for namespace root. /// The display name for the folder. /// The namespace realm the folder (and its ) live in. void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName, AddressSpaceRealm realm); /// /// Ensure a Variable node exists at , parented under /// (or the namespace root when null). Created with /// Bad quality + null value; subsequent calls update both. /// Used by AddressSpaceApplier to materialise equipment-namespace tags ahead of any /// driver-side subscribe so OPC UA clients can browse them. Idempotent. /// /// The OPC UA node ID for the variable. /// The parent folder node ID, or null for namespace root. /// The display name for the variable. /// OPC UA built-in type name ("Boolean" / "Int32" / "Float" / etc.). /// When true the node is created CurrentReadWrite (an authored /// ReadWrite equipment tag); when false it stays CurrentRead (read-only). Non-equipment-tag /// variables (folders' children, alarm placeholders) always pass false. /// null ⇒ the variable is not historized; non-null ⇒ create it /// Historizing with the HistoryRead access bit and register the (already default-resolved) /// historian tagname. /// When true the node is created as a 1-D array (ValueRank=OneDimension /// with ArrayDimensions=[arrayLength]); when false (default) it stays scalar /// (ValueRank=Scalar). Array elements share the scalar's base — /// rank + dimensions carry the array-ness. /// The declared length of the 1-D array when is /// true; ignored for scalars. Null ⇒ length 0 (unbounded). /// The namespace realm the variable (and its ) live /// in. A historized UNS reference node registers the SAME as its backing /// raw node — both NodeIds map to one tagname — so this call carries the shared tagname per realm. void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, AddressSpaceRealm realm, string? historianTagname = null, bool isArray = false, uint? arrayLength = null); /// /// Tear down + repopulate the address space. Called by OpcUaPublishActor after a /// successful deployment apply so the node manager reflects the new config. Idempotent. /// void RebuildAddressSpace(); /// /// Announce that nodes were added at runtime (discovered-node injection) under /// so subscribed clients refresh their browse /// (Part 3 GeneralModelChangeEvent, verb NodeAdded). /// /// The node under which discovered nodes were added. /// The namespace realm lives in. void RaiseNodesAddedModelChange(string affectedNodeId, AddressSpaceRealm realm); /// /// Add an OPC UA reference from an already-materialised source node to an already-materialised /// target node, both realm-qualified. Used by AddressSpaceApplier to link each UNS reference /// Variable (source, ) to its backing Raw node (target, /// ) with an Organizes edge, so the UNS variable /// browse-resolves to its raw source (and the raw node back via the inverse). The edge is wired /// bidirectionally (forward on the source, inverse on the target) so browse resolves both ways. /// Idempotent (an existing edge is not duplicated); a missing endpoint is a no-op /// (logged, never thrown) so a mid-rebuild race can't fault a deploy. /// /// The source node's s= id (the referencing node — e.g. the UNS variable). /// The namespace realm lives in. /// The target node's s= id (the referenced node — e.g. the backing Raw node). /// The namespace realm lives in. /// The hierarchical reference type name — Organizes (default), /// HasComponent, or HasProperty; unknown names fall back to Organizes. void AddReference(string sourceNodeId, AddressSpaceRealm sourceRealm, string targetNodeId, AddressSpaceRealm targetRealm, string referenceType = "Organizes"); } /// OPC UA status code projection — Good / Uncertain / Bad. Real SDK has finer-grained /// codes; the engine actors only need this 3-state classification. public enum OpcUaQuality { Good, Uncertain, Bad } /// No-op sink. Bound by default so the actors are safe to run in dev / Mac / /// integration tests without a real SDK behind them. public sealed class NullOpcUaAddressSpaceSink : IOpcUaAddressSpaceSink { public static readonly NullOpcUaAddressSpaceSink Instance = new(); private NullOpcUaAddressSpaceSink() { } /// public void WriteValue(string nodeId, object? value, OpcUaQuality quality, DateTime sourceTimestampUtc, AddressSpaceRealm realm) { } /// public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime sourceTimestampUtc, AddressSpaceRealm realm) { } public void WriteAlarmQuality(string alarmNodeId, OpcUaQuality quality, DateTime sourceTimestampUtc, AddressSpaceRealm realm) { } /// public void MaterialiseAlarmCondition(string alarmNodeId, string equipmentNodeId, string displayName, string alarmType, int severity, AddressSpaceRealm realm, bool isNative = false) { } /// public void WireAlarmNotifiers(string alarmNodeId, AddressSpaceRealm alarmRealm, IReadOnlyList notifierFolderNodeIds, AddressSpaceRealm notifierFolderRealm) { } /// public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName, AddressSpaceRealm realm) { } /// public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, AddressSpaceRealm realm, string? historianTagname = null, bool isArray = false, uint? arrayLength = null) { } /// public void RebuildAddressSpace() { } /// public void RaiseNodesAddedModelChange(string affectedNodeId, AddressSpaceRealm realm) { } /// public void AddReference(string sourceNodeId, AddressSpaceRealm sourceRealm, string targetNodeId, AddressSpaceRealm targetRealm, string referenceType = "Organizes") { } }