/* ========================================================================
* 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 Microsoft.Extensions.Logging;
using Opc.Ua.PubSub.PublishedData;
namespace Opc.Ua.PubSub
{
///
/// Base class for a DataSet message implementation
///
public abstract class UaDataSetMessage
{
// Configuration Major and Major current version (VersionTime)
///
/// Default value for Configured MetaDataVersion.MajorVersion
///
protected const uint kDefaultConfigMajorVersion = 0;
///
/// Default value for Configured MetaDataVersion.MinorVersion
///
protected const uint kDefaultConfigMinorVersion = 0;
///
/// Create new instance of
///
protected UaDataSetMessage(ILogger logger)
{
m_logger = logger ?? Utils.Fallback.Logger;
DecodeErrorReason = DataSetDecodeErrorReason.NoError;
Timestamp = DateTime.UtcNow;
MetaDataVersion = new ConfigurationVersionDataType
{
MajorVersion = kDefaultConfigMajorVersion,
MinorVersion = kDefaultConfigMinorVersion
};
}
///
/// Get DataSet
///
public DataSet DataSet { get; internal set; } = null!;
///
/// Get and Set corresponding DataSetWriterId
///
public ushort DataSetWriterId { get; set; }
///
/// Get DataSetFieldContentMask
/// This DataType defines flags to include DataSet field related information like status and
/// timestamp in addition to the value in the DataSetMessage.
///
public DataSetFieldContentMask FieldContentMask { get; protected set; }
///
/// The version of the DataSetMetaData which describes the contents of the Payload.
///
public ConfigurationVersionDataType MetaDataVersion { get; set; }
///
/// Get and Set SequenceNumber
/// A strictly monotonically increasing sequence number assigned by the publisher to each DataSetMessage sent.
///
public uint SequenceNumber { get; set; }
///
/// Get and Set Timestamp
///
public DateTimeUtc Timestamp { get; set; }
///
/// Get and Set Status
///
public StatusCode Status { get; set; }
///
/// Get and Set the reason that an error encountered while decoding occurred
///
public DataSetDecodeErrorReason DecodeErrorReason { get; set; }
///
/// Checks if the MetadataMajorVersion has changed depending on the value of DataSetDecodeErrorReason
///
public bool IsMetadataMajorVersionChange
=> DecodeErrorReason == DataSetDecodeErrorReason.MetadataMajorVersion;
///
/// Set DataSetFieldContentMask
///
/// The new for this dataset
public abstract void SetFieldContentMask(DataSetFieldContentMask fieldContentMask);
///
/// Validates the MetadataVersion against a given ConfigurationVersionDataType
///
/// The value to validate MetadataVersion against
/// NoError if validation passes or the cause of the failure
protected DataSetDecodeErrorReason ValidateMetadataVersion(
ConfigurationVersionDataType configurationVersionDataType)
{
if (MetaDataVersion.MajorVersion != kDefaultConfigMajorVersion &&
MetaDataVersion.MajorVersion != configurationVersionDataType.MajorVersion)
{
return DataSetDecodeErrorReason.MetadataMajorVersion;
}
return DataSetDecodeErrorReason.NoError;
}
///
/// A Logger to be used by this and derived classes
///
#pragma warning disable IDE1006 // Naming Styles
protected ILogger m_logger { get; }
#pragma warning restore IDE1006 // Naming Styles
}
}