Skip to content

Commit

Permalink
Fix stringtables for diagnostic results when service calls are batched (
Browse files Browse the repository at this point in the history
#2222)

- Issue fix: Currently when diagnostics is enabled in client calls, the string table in the response header is not updated when a service call is split into multiple service calls.  In this case the stringtables from all calls must be appended and the index in the diagnosticinfo must be updated to match the updated string list.
- To reduce the number of 'null' DiagnosticInfo allocations, the decoders now try to return null instead of a default DiagnosticInfo. A new property ÌsNullDiagnosticInfo' can be used to check for unused DiagnosticInfo entries.
- The tests were slightly improved to use test set data from the generated TestData namespace, which contains also a historical node.
- All `ServerFixtureUtils.ValidateXXX` checks were updated to include the check for diagnosticInfos and the string tables to catch issues.
  • Loading branch information
mregen committed Jul 13, 2023
1 parent 6fc58eb commit 17d4f04
Show file tree
Hide file tree
Showing 16 changed files with 560 additions and 224 deletions.
72 changes: 72 additions & 0 deletions Applications/Quickstarts.Servers/TestData/NodeStateComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* ========================================================================
* Copyright (c) 2005-2019 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.Collections.Generic;
using Opc.Ua;

namespace TestData
{
/// <summary>
/// Helper which implements IEqualityComparer for Linq queries.
/// </summary>
public class NodeStateComparer : IEqualityComparer<NodeState>
{
/// <inheritdoc/>
public bool Equals(NodeState x, NodeState y)
{
if (ReferenceEquals(x, y))
{
return true;
}

if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
{
return false;
}

if (x.NodeId == y.NodeId)
{
return true;
}

return false;
}

/// <inheritdoc/>
public int GetHashCode(NodeState node)
{
if (ReferenceEquals(node, null))
{
return 0;
}

return node.NodeId.GetHashCode();
}
}
}
14 changes: 11 additions & 3 deletions Applications/Quickstarts.Servers/TestData/TestDataSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public TestDataSystem(ITestDataSystemCallback callback, NamespaceTable namespace
m_callback = callback;
m_minimumSamplingInterval = Int32.MaxValue;
m_monitoredNodes = new Dictionary<uint, BaseVariableState>();
m_samplingNodes = null;
m_generator = new Opc.Ua.Test.DataGenerator(null);
m_generator.NamespaceUris = namespaceUris;
m_generator.ServerUris = serverUris;
Expand Down Expand Up @@ -895,6 +896,7 @@ public void StartMonitoringValue(uint monitoredItemId, double samplingInterval,
}

m_monitoredNodes[monitoredItemId] = variable;
m_samplingNodes = null;

SetSamplingInterval(samplingInterval);
}
Expand Down Expand Up @@ -952,7 +954,12 @@ void DoSample(object state)
return;
}

foreach (BaseVariableState variable in m_monitoredNodes.Values)
if (m_samplingNodes == null)
{
m_samplingNodes = m_monitoredNodes.Values.Distinct(new NodeStateComparer()).Cast<BaseVariableState>().ToList();
}

foreach (BaseVariableState variable in m_samplingNodes)
{
if (variable is ITestDataSystemValuesGenerator)
{
Expand Down Expand Up @@ -987,8 +994,7 @@ void DoSample(object state)
sample.Timestamp);
}

var distinctValues = generateValues.Distinct().ToList();
foreach (var generateValue in distinctValues)
foreach (var generateValue in generateValues)
{
m_callback.OnGenerateValues(generateValue);
}
Expand All @@ -1004,6 +1010,7 @@ public void StopMonitoringValue(uint monitoredItemId)
}

m_monitoredNodes.Remove(monitoredItemId);
m_samplingNodes = null;

if (m_monitoredNodes.Count == 0)
{
Expand All @@ -1026,6 +1033,7 @@ private class Sample
private Opc.Ua.Test.DataGenerator m_generator;
private int m_minimumSamplingInterval;
private Dictionary<uint, BaseVariableState> m_monitoredNodes;
private IList<BaseVariableState> m_samplingNodes;
private Timer m_timer;
private StatusCode m_systemStatus;
private HistoryArchive m_historyArchive;
Expand Down

0 comments on commit 17d4f04

Please sign in to comment.