namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa; /// /// Late-binding adapter that accepts and retains the latest requested ServiceLevel until /// the SDK publisher is available. Binding synchronously replays that request, including zero. /// /// /// Publishing and binding are serialized through the synchronous inner call. Inner publishers /// must not call back into this adapter. Acceptance while unbound is not an SDK write confirmation. /// A failed call retains both the requested level and the installed publisher for later recovery. /// public sealed class DeferredServiceLevelPublisher : IServiceLevelPublisher { private readonly object _gate = new(); private IServiceLevelPublisher? _inner; private byte? _latest; /// Bind and replay the latest request, or unbind while retaining that request. /// The publisher implementation to use, or null to unbind. public void SetInner(IServiceLevelPublisher? inner) { lock (_gate) { _inner = inner; if (_latest is { } latest) _inner?.Publish(latest); } } /// public void Publish(byte serviceLevel) { lock (_gate) { _latest = serviceLevel; _inner?.Publish(serviceLevel); } } }