/* ========================================================================
* 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.Threading;
using System.Threading.Tasks;
namespace Opc.Ua.Server
{
///
/// An interface used by the monitored items to signal the subscription.
///
public interface ISubscription : IDisposable
{
///
/// The session that owns the monitored item.
///
ISession Session { get; }
///
/// The subscriptions owner identity.
///
IUserIdentity EffectiveIdentity { get; }
///
/// The identifier for the item that is unique within the server.
///
uint Id { get; }
///
/// The identifier for the session that owns the subscription.
///
NodeId SessionId { get; }
///
/// The number of monitored items.
///
int MonitoredItemCount { get; }
///
/// The priority assigned to the subscription.
///
byte Priority { get; }
///
/// The publishing rate for the subscription.
///
double PublishingInterval { get; }
///
/// True if the subscription is set to durable and supports long lifetime and queue size
///
bool IsDurable { get; }
///
/// Gets the lock that must be acquired before accessing the contents of the Diagnostics property.
///
object DiagnosticsLock { get; }
///
/// Gets the lock that must be acquired before updating the contents of the Diagnostics property.
///
object DiagnosticsWriteLock { get; }
///
/// Gets the current diagnostics for the subscription.
///
SubscriptionDiagnosticsDataType Diagnostics { get; }
///
/// Called when a monitored item is ready to publish.
///
void ItemReadyToPublish(IMonitoredItem monitoredItem);
///
/// Called when a monitored item is ready to publish.
///
void ItemNotificationsAvailable(IMonitoredItem monitoredItem);
///
/// Called when a value of monitored item is discarded in the monitoring queue.
///
void QueueOverflowHandler();
///
/// Checks if the subscription is ready to publish.
///
PublishingState PublishTimerExpired();
///
/// Returns the available sequence numbers for retransmission
/// For example used in Transfer Subscription
///
ArrayOf AvailableSequenceNumbersForRetransmission();
///
/// Refreshes the conditions.
///
ValueTask ConditionRefresh2Async(uint monitoredItemId, CancellationToken cancellationToken = default);
///
/// Refreshes the conditions.
///
ValueTask ConditionRefreshAsync(CancellationToken cancellationToken = default);
///
/// Updates the publishing parameters for the subscription.
///
void Modify(
OperationContext context,
double publishingInterval,
uint maxLifetimeCount,
uint maxKeepAliveCount,
uint maxNotificationsPerPublish,
byte priority);
///
/// Changes the monitoring mode for a set of items.
///
ValueTask<(ArrayOf results, ArrayOf diagnosticInfos)> SetMonitoringModeAsync(
OperationContext context,
MonitoringMode monitoringMode,
ArrayOf monitoredItemIds,
CancellationToken cancellationToken = default);
///
/// Enables/disables publishing for the subscription.
///
void SetPublishingMode(OperationContext context, bool publishingEnabled);
///
/// Deletes the monitored items in a subscription.
///
ValueTask DeleteMonitoredItemsAsync(
OperationContext context,
ArrayOf monitoredItemIds,
CancellationToken cancellationToken = default);
///
/// Modifies monitored items in a subscription.
///
ValueTask ModifyMonitoredItemsAsync(
OperationContext context,
TimestampsToReturn timestampsToReturn,
ArrayOf itemsToModify,
CancellationToken cancellationToken = default);
///
/// Adds monitored items to a subscription.
///
ValueTask CreateMonitoredItemsAsync(
OperationContext context,
TimestampsToReturn timestampsToReturn,
ArrayOf itemsToCreate,
CancellationToken cancellationToken = default);
///
/// Gets the monitored items for the subscription.
///
void GetMonitoredItems(
out ArrayOf serverHandles,
out ArrayOf clientHandles);
///
/// Sets the subscription to durable mode.
///
ServiceResult SetSubscriptionDurable(uint maxLifetimeCount);
///
/// Initiates resending of all data monitored items in a Subscription
///
void ResendData(OperationContext context);
///
/// Tells the subscription that the owning session is being closed.
///
void SessionClosed();
///
/// Removes a message from the message queue.
///
ServiceResult? Acknowledge(OperationContext context, uint sequenceNumber);
///
/// Deletes the subscription.
///
ValueTask DeleteAsync(OperationContext context, CancellationToken cancellationToken = default);
///
/// Verifies that a condition refresh operation is permitted.
///
void ValidateConditionRefresh(OperationContext context);
///
/// Verifies that a condition refresh operation is permitted.
///
void ValidateConditionRefresh2(OperationContext context, uint monitoredItemId);
///
/// Returns a cached notification message.
///
NotificationMessage Republish(OperationContext context, uint retransmitSequenceNumber);
///
/// Publishes a timeout status message.
///
NotificationMessage PublishTimeout();
///
/// Publishes a SubscriptionTransferred status message.
///
NotificationMessage SubscriptionTransferred();
///
/// Returns all available notifications.
///
NotificationMessage? Publish(
OperationContext context,
out ArrayOf availableSequenceNumbers,
out bool moreNotifications);
///
/// Transfers the subscription to a new session.
///
/// The session to which the subscription is transferred.
/// Whether the first Publish response shall contain current values.
/// The cancellation token.
ValueTask TransferSessionAsync(OperationContext context, bool sendInitialValues, CancellationToken cancellationToken = default);
///
/// Updates the triggers for the monitored item.
///
void SetTriggering(
OperationContext context,
uint triggeringItemId,
ArrayOf linksToAdd,
ArrayOf linksToRemove,
out ArrayOf addResults,
out ArrayOf addDiagnosticInfos,
out ArrayOf removeResults,
out ArrayOf removeDiagnosticInfos);
///
/// Return a StorableSubscription for restore after a server restart
///
IStoredSubscription ToStorableSubscription();
}
}