/* ========================================================================
* Copyright (c) 2005-2025 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.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
namespace Opc.Ua.Server
{
///
/// Provides access to the subscription manager within the server.
///
///
/// Sinks that receive these events must not block the thread.
///
public interface ISubscriptionManager : IDisposable
{
///
/// Raised after a new subscription is created.
///
event SubscriptionEventHandler SubscriptionCreated;
///
/// Raised before a subscription is deleted.
///
event SubscriptionEventHandler SubscriptionDeleted;
///
/// Returns all of the subscriptions known to the subscription manager.
///
/// A list of the subscriptions.
IList GetSubscriptions();
///
/// Get the subscription with the specified id
///
/// The id of the subscription
/// The subscription if found else null
/// True if found
bool TryGetSubscription(uint id, [NotNullWhen(true)] out ISubscription? subscription);
///
/// Set a subscription into durable mode
///
ServiceResult SetSubscriptionDurable(
ISystemContext context,
uint subscriptionId,
uint lifetimeInHours,
out uint revisedLifetimeInHours);
///
/// Creates a new subscription.
///
ValueTask CreateSubscriptionAsync(
OperationContext context,
double requestedPublishingInterval,
uint requestedLifetimeCount,
uint requestedMaxKeepAliveCount,
uint maxNotificationsPerPublish,
bool publishingEnabled,
byte priority,
CancellationToken cancellationToken = default);
///
/// Starts up the manager makes it ready to create subscriptions.
///
ValueTask StartupAsync(CancellationToken cancellationToken = default);
///
/// Closes all subscriptions and rejects any new requests.
///
ValueTask ShutdownAsync(CancellationToken cancellationToken = default);
///
/// Stores durable subscriptions to be able to restore them after a restart
///
ValueTask StoreSubscriptionsAsync(CancellationToken cancellationToken = default);
///
/// Restore durable subscriptions after a server restart
///
ValueTask RestoreSubscriptionsAsync(CancellationToken cancellationToken = default);
///
/// Deletes group of subscriptions.
///
ValueTask DeleteSubscriptionsAsync(
OperationContext context,
ArrayOf subscriptionIds,
CancellationToken cancellationToken = default);
///
/// Publishes a subscription.
///
Task PublishAsync(
OperationContext context,
ArrayOf subscriptionAcknowledgements,
CancellationToken cancellationToken = default);
///
/// Modifies an existing subscription.
///
void ModifySubscription(
OperationContext context,
uint subscriptionId,
double requestedPublishingInterval,
uint requestedLifetimeCount,
uint requestedMaxKeepAliveCount,
uint maxNotificationsPerPublish,
byte priority,
out double revisedPublishingInterval,
out uint revisedLifetimeCount,
out uint revisedMaxKeepAliveCount);
///
/// Sets the publishing mode for a set of subscriptions.
///
void SetPublishingMode(
OperationContext context,
bool publishingEnabled,
ArrayOf subscriptionIds,
out ArrayOf results,
out ArrayOf diagnosticInfos);
///
/// Attaches a groups of subscriptions to a different session.
///
ValueTask TransferSubscriptionsAsync(
OperationContext context,
ArrayOf subscriptionIds,
bool sendInitialValues,
CancellationToken cancellationToken = default);
///
/// Republishes a previously published notification message.
///
NotificationMessage Republish(
OperationContext context,
uint subscriptionId,
uint retransmitSequenceNumber);
///
/// Updates the triggers for the monitored item.
///
void SetTriggering(
OperationContext context,
uint subscriptionId,
uint triggeringItemId,
ArrayOf linksToAdd,
ArrayOf linksToRemove,
out ArrayOf addResults,
out ArrayOf addDiagnosticInfos,
out ArrayOf removeResults,
out ArrayOf removeDiagnosticInfos);
///
/// Adds monitored items to a subscription.
///
ValueTask CreateMonitoredItemsAsync(
OperationContext context,
uint subscriptionId,
TimestampsToReturn timestampsToReturn,
ArrayOf itemsToCreate,
CancellationToken cancellationToken = default);
///
/// Modifies monitored items in a subscription.
///
ValueTask ModifyMonitoredItemsAsync(
OperationContext context,
uint subscriptionId,
TimestampsToReturn timestampsToReturn,
ArrayOf itemsToModify,
CancellationToken cancellationToken = default);
///
/// Deletes the monitored items in a subscription.
///
ValueTask DeleteMonitoredItemsAsync(
OperationContext context,
uint subscriptionId,
ArrayOf monitoredItemIds,
CancellationToken cancellationToken = default);
///
/// Changes the monitoring mode for a set of items.
///
ValueTask<(ArrayOf results, ArrayOf diagnosticInfos)> SetMonitoringModeAsync(
OperationContext context,
uint subscriptionId,
MonitoringMode monitoringMode,
ArrayOf monitoredItemIds,
CancellationToken cancellationToken = default);
///
/// Signals that a session is closing.
///
ValueTask SessionClosingAsync(
OperationContext context,
NodeId sessionId,
bool deleteSubscriptions,
CancellationToken cancellationToken);
///
/// Deletes the specified subscription.
///
ValueTask DeleteSubscriptionAsync(OperationContext context, uint subscriptionId, CancellationToken cancellationToken = default);
///
/// Refreshes the conditions for the specified subscription.
///
void ConditionRefresh(OperationContext context, uint subscriptionId);
///
/// Refreshes the conditions for the specified subscription and monitored item.
///
void ConditionRefresh2(OperationContext context, uint subscriptionId, uint monitoredItemId);
}
///
/// The delegate for functions used to receive subscription related events.
///
/// The subscription that was affected.
/// True if the subscription was deleted.
public delegate void SubscriptionEventHandler(ISubscription subscription, bool deleted);
}