Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Libraries/Opc.Ua.Server/Diagnostics/DiagnosticsNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,61 @@ var historyServerCapabilitiesNode
}
}

/// <summary>
/// Updates the Server object EventNotifier based on history capabilities.
/// </summary>
/// <remarks>
/// This method can be overridden to customize the Server EventNotifier based on
/// history capabilities settings.
/// </remarks>
public virtual void UpdateServerEventNotifier()
{
lock (Lock)
{
// Get or create the history capabilities
HistoryServerCapabilitiesState historyCapabilities = GetDefaultHistoryCapabilities();

// Find the Server object
ServerObjectState serverObject = (ServerObjectState)FindPredefinedNode(
ObjectIds.Server,
typeof(ServerObjectState));

if (serverObject != null && historyCapabilities != null)
{
// Update EventNotifier based on history capabilities
byte eventNotifier = serverObject.EventNotifier;

// Set HistoryRead bit if history events or data capabilities are enabled
if (historyCapabilities.AccessHistoryEventsCapability?.Value == true ||
historyCapabilities.AccessHistoryDataCapability?.Value == true)
{
eventNotifier |= EventNotifiers.HistoryRead;
}
else
{
eventNotifier = (byte)(eventNotifier & ~EventNotifiers.HistoryRead);
}

// Set HistoryWrite bit if history update capabilities are enabled
if (historyCapabilities.InsertEventCapability?.Value == true ||
historyCapabilities.ReplaceEventCapability?.Value == true ||
historyCapabilities.UpdateEventCapability?.Value == true ||
historyCapabilities.InsertDataCapability?.Value == true ||
historyCapabilities.UpdateDataCapability?.Value == true ||
historyCapabilities.ReplaceDataCapability?.Value == true)
{
eventNotifier |= EventNotifiers.HistoryWrite;
}
else
{
eventNotifier = (byte)(eventNotifier & ~EventNotifiers.HistoryWrite);
}

serverObject.EventNotifier = eventNotifier;
}
}
}

/// <summary>
/// Adds an aggregate function to the server capabilities object.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Opc.Ua.Server/Server/ServerInternalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ .. m_configuration.ServerConfiguration.ServerProfileArray
DefaultSystemContext,
m_configuration);

// Initialize history capabilities and update Server EventNotifier accordingly
DiagnosticsNodeManager.GetDefaultHistoryCapabilities();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is already called in the next method

DiagnosticsNodeManager.UpdateServerEventNotifier();

Auditing = m_configuration.ServerConfiguration.AuditingEnabled;
PropertyState<bool> auditing = serverObject.Auditing;
auditing.OnSimpleWriteValue += OnWriteAuditing;
Expand Down
82 changes: 82 additions & 0 deletions Tests/Opc.Ua.Server.Tests/ReferenceServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,5 +992,87 @@ private void UpdateValues(NodeId[] testSet)
response.StringTable,
logger);
}

/// <summary>
/// Test that Server object EventNotifier has HistoryRead bit set when history capabilities are enabled.
/// </summary>
[Test]
public void ServerEventNotifierHistoryReadBit()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
ILogger logger = telemetry.CreateLogger<ReferenceServerTests>();

// Read Server object EventNotifier attribute
var readIdCollection = new ReadValueIdCollection
{
new ReadValueId
{
AttributeId = Attributes.EventNotifier,
NodeId = ObjectIds.Server
}
};

m_requestHeader.Timestamp = DateTime.UtcNow;
ResponseHeader response = m_server.Read(
m_requestHeader,
0,
TimestampsToReturn.Both,
readIdCollection,
out DataValueCollection serverEventNotifierValues,
out DiagnosticInfoCollection diagnosticInfos);

ServerFixtureUtils.ValidateResponse(response, serverEventNotifierValues, readIdCollection);
Assert.AreEqual(1, serverEventNotifierValues.Count);
Assert.NotNull(serverEventNotifierValues[0].Value);

byte eventNotifier = (byte)serverEventNotifierValues[0].Value;

// Read history capabilities
var historyCapabilitiesReadIds = new ReadValueIdCollection
{
new ReadValueId
{
AttributeId = Attributes.Value,
NodeId = VariableIds.HistoryServerCapabilities_AccessHistoryEventsCapability
},
new ReadValueId
{
AttributeId = Attributes.Value,
NodeId = VariableIds.HistoryServerCapabilities_AccessHistoryDataCapability
}
};

m_requestHeader.Timestamp = DateTime.UtcNow;
response = m_server.Read(
m_requestHeader,
0,
TimestampsToReturn.Both,
historyCapabilitiesReadIds,
out DataValueCollection historyCapabilitiesValues,
out diagnosticInfos);

ServerFixtureUtils.ValidateResponse(response, historyCapabilitiesValues, historyCapabilitiesReadIds);
Assert.AreEqual(2, historyCapabilitiesValues.Count);

bool accessHistoryEventsCapability = historyCapabilitiesValues[0].Value != null &&
(bool)historyCapabilitiesValues[0].Value;
bool accessHistoryDataCapability = historyCapabilitiesValues[1].Value != null &&
(bool)historyCapabilitiesValues[1].Value;

logger.LogInformation("Server EventNotifier: {EventNotifier}", eventNotifier);
logger.LogInformation("AccessHistoryEventsCapability: {AccessHistoryEventsCapability}", accessHistoryEventsCapability);
logger.LogInformation("AccessHistoryDataCapability: {AccessHistoryDataCapability}", accessHistoryDataCapability);

// If either history capability is enabled, the HistoryRead bit should be set
if (accessHistoryEventsCapability || accessHistoryDataCapability)
{
Assert.IsTrue((eventNotifier & EventNotifiers.HistoryRead) != 0,
"Server EventNotifier should have HistoryRead bit set when history capabilities are enabled");
}

// Verify SubscribeToEvents bit is set (Server object should always support events)
Assert.IsTrue((eventNotifier & EventNotifiers.SubscribeToEvents) != 0,
"Server EventNotifier should have SubscribeToEvents bit set");
}
}
}
Loading