39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
|
|
|
/// <summary>
|
|
/// Late-binding adapter that accepts and retains the latest requested ServiceLevel until
|
|
/// the SDK publisher is available. Binding synchronously replays that request, including zero.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// 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.
|
|
/// </remarks>
|
|
public sealed class DeferredServiceLevelPublisher : IServiceLevelPublisher
|
|
{
|
|
private readonly object _gate = new();
|
|
private IServiceLevelPublisher? _inner;
|
|
private byte? _latest;
|
|
|
|
/// <summary>Bind and replay the latest request, or unbind while retaining that request.</summary>
|
|
/// <param name="inner">The publisher implementation to use, or null to unbind.</param>
|
|
public void SetInner(IServiceLevelPublisher? inner)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
_inner = inner;
|
|
if (_latest is { } latest) _inner?.Publish(latest);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Publish(byte serviceLevel)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
_latest = serviceLevel;
|
|
_inner?.Publish(serviceLevel);
|
|
}
|
|
}
|
|
}
|