/* ========================================================================
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System;
using System.Threading;
using System.Threading.Tasks;
using Opc.Ua.Di.Server.SoftwareUpdate;
namespace Opc.Ua.Di.Server.Builders
{
///
/// Loading variant for the OPC 10000-100 §10.3 software-update
/// facet. Picks the concrete SoftwareLoadingType subtype
/// that will be materialised under the device's
/// SoftwareUpdate.Loading slot.
///
public enum SoftwareLoadingMode
{
///
/// PackageLoadingType — file transfer via
/// FileTransfer.GenerateFileForWrite +
/// CloseAndCommit. Recommended default.
///
Package = 0,
///
/// DirectLoadingType — direct property write of the
/// new firmware. No file transfer.
///
Direct = 1,
///
/// CachedLoadingType — pending + fallback versions
/// archived for two-stage rollouts.
///
Cached = 2,
}
///
/// Phase reported by 's
/// state-changed hooks. Numeric-state-ID-free domain enum so
/// applications don't have to depend on Part-16 dispatcher
/// internals.
///
public enum SoftwareUpdatePhase
{
///
/// The state-machine method invocation was accepted.
///
Started = 0,
///
/// The work is in progress.
///
InProgress = 1,
///
/// The work completed successfully.
///
Completed = 2,
///
/// The work failed.
///
Failed = 3,
}
///
/// Snapshot passed to the SU state-changed hooks each time the
/// server-side state machine moves between phases.
///
/// The new phase.
///
/// Optional human-readable message (e.g. installation failure
/// reason). Empty when no message is supplied.
///
///
/// Optional 0..100 progress indicator for ;
/// when progress is not tracked.
///
public sealed record SoftwareUpdateStateChange(
SoftwareUpdatePhase Phase,
string Message,
byte? ProgressPercent);
///
/// Context object passed to
/// callbacks. Exposes the bits the application needs to react to
/// state-machine method invocations without dragging in the
/// full SoftwareUpdateState surface.
///
public interface ISoftwareUpdateContext
{
///
/// The NodeId of the device that owns the SU facet.
///
NodeId DeviceId { get; }
///
/// The server's system context.
///
ISystemContext SystemContext { get; }
///
/// The package store the SU facet is bound to.
///
ISoftwarePackageStore PackageStore { get; }
///
/// The per-device software folder.
///
ISoftwareFolder SoftwareFolder { get; }
}
///
/// Fluent configuration surface for a device's
/// SoftwareUpdateType facet.
///
///
///
/// Created via
/// .
///
///
/// Pick the Loading subtype with one of /
/// / ;
/// the default is .
///
///
/// Override the four state-machine method handlers
/// (Prepare / Install / Confirm / Uninstall) via the
/// On* methods. The library ships
/// "succeed-immediately" stubs so the facet is fully functional
/// out of the box — sample servers don't have to supply any of
/// the callbacks. Production servers override the relevant
/// hooks to drive the real firmware-flashing logic.
///
///
public interface ISoftwareUpdateBuilder
{
///
/// Selects — file
/// transfer + CloseAndCommit. Default behaviour when
///
/// is called with no configuration delegate.
///
ISoftwareUpdateBuilder UsePackageLoading();
///
/// Selects .
///
ISoftwareUpdateBuilder UseDirectLoading();
///
/// Selects .
///
ISoftwareUpdateBuilder UseCachedLoading();
///
/// Overrides the per-device .
/// Defaults to an in-memory MemorySoftwareFolder
/// keyed by the device's NodeId.
///
ISoftwareUpdateBuilder WithSoftwareFolder(ISoftwareFolder folder);
///
/// Sets the handler for PrepareForUpdate.Prepare.
/// The default stub marks the state machine as Prepared
/// immediately.
///
ISoftwareUpdateBuilder OnPrepare(
Func handler);
///
/// Sets the handler for
/// Installation.InstallSoftwarePackage. The default
/// stub records the supplied
/// as the device's current
/// version (via the folder) and transitions to Idle.
///
ISoftwareUpdateBuilder OnInstall(
Func handler);
///
/// Sets the handler for Confirmation.Confirm. The
/// default stub clears the Confirmation state machine.
///
ISoftwareUpdateBuilder OnConfirm(
Func handler);
///
/// Sets the handler for Installation.Uninstall. The
/// default stub clears the current version in the folder.
///
ISoftwareUpdateBuilder OnUninstall(
Func handler);
///
/// Subscribes a callback that fires whenever the server-side
/// PrepareForUpdate state machine moves between
/// phases (Started → InProgress → Completed | Failed). Useful
/// for surfacing progress in application telemetry.
///
ISoftwareUpdateBuilder OnPrepareStateChanged(
Func handler);
///
/// Subscribes a callback that fires whenever the server-side
/// Installation state machine moves between phases.
///
/// reflects the InstallationStateMachine's
/// PercentComplete child when the application updates it.
///
ISoftwareUpdateBuilder OnInstallationStateChanged(
Func handler);
///
/// Subscribes a callback that fires whenever the server-side
/// Confirmation state machine moves between phases.
///
ISoftwareUpdateBuilder OnConfirmStateChanged(
Func handler);
}
}