Skip to content

Commit

Permalink
initialize predefined nodes in constructor (#2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanett authored Jan 27, 2025
1 parent f7815c8 commit fcc3b74
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions Libraries/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ protected CustomNodeManager2(
// create the table of monitored nodes.
// these are created by the node manager whenever a client subscribe to an attribute of the node.
m_monitoredNodes = new NodeIdDictionary<MonitoredNode2>();

m_predefinedNodes = new NodeIdDictionary<NodeState>();
}
#endregion

Expand All @@ -129,7 +131,7 @@ protected virtual void Dispose(bool disposing)
{
lock (Lock)
{
foreach (NodeState node in m_predefinedNodes?.Values)
foreach (NodeState node in m_predefinedNodes.Values)
{
Utils.SilentDispose(node);
}
Expand Down Expand Up @@ -321,7 +323,7 @@ protected virtual NodeHandle IsHandleInNamespace(object managerHandle)
public NodeState Find(NodeId nodeId)
{
NodeState node = null;
if (m_predefinedNodes?.TryGetValue(nodeId, out node) == true)
if (m_predefinedNodes.TryGetValue(nodeId, out node) == true)
{
return node;
}
Expand Down Expand Up @@ -349,11 +351,6 @@ public NodeId CreateNode(

lock (Lock)
{
if (m_predefinedNodes == null)
{
m_predefinedNodes = new NodeIdDictionary<NodeState>();
}

instance.ReferenceTypeId = referenceTypeId;

NodeState parent = null;
Expand Down Expand Up @@ -390,7 +387,7 @@ public bool DeleteNode(
List<LocalReference> referencesToRemove = new List<LocalReference>();

NodeState node = null;
if (m_predefinedNodes?.TryGetValue(nodeId, out node) != true)
if (m_predefinedNodes.TryGetValue(nodeId, out node) != true)
{
return false;
}
Expand Down Expand Up @@ -477,11 +474,6 @@ public virtual void LoadPredefinedNodes(
string resourcePath,
IDictionary<NodeId, IList<IReference>> externalReferences)
{
if (m_predefinedNodes == null)
{
m_predefinedNodes = new NodeIdDictionary<NodeState>();
}

// load the predefined nodes from an XML document.
NodeStateCollection predefinedNodes = new NodeStateCollection();
predefinedNodes.LoadFromResource(context, resourcePath, assembly, true);
Expand Down Expand Up @@ -544,11 +536,6 @@ protected virtual NodeState AddBehaviourToPredefinedNode(ISystemContext context,
/// </summary>
protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
{
if (m_predefinedNodes == null)
{
m_predefinedNodes = new NodeIdDictionary<NodeState>();
}

// assign a default value to any variable in namespace 0
if (node is BaseVariableState nodeStateVar)
{
Expand Down Expand Up @@ -614,7 +601,7 @@ protected virtual void RemovePredefinedNode(
NodeState node,
List<LocalReference> referencesToRemove)
{
if (m_predefinedNodes?.TryRemove(node.NodeId, out _) != true)
if (m_predefinedNodes.TryRemove(node.NodeId, out _) != true)
{
return;
}
Expand Down Expand Up @@ -687,7 +674,7 @@ protected virtual void OnNodeRemoved(NodeState node)
/// <param name="externalReferences">A list of references to add to external targets.</param>
protected virtual void AddReverseReferences(IDictionary<NodeId, IList<IReference>> externalReferences)
{
foreach (NodeState source in m_predefinedNodes?.Values)
foreach (NodeState source in m_predefinedNodes.Values)
{
IList<IReference> references = new List<IReference>();
source.GetReferences(SystemContext, references);
Expand Down Expand Up @@ -855,15 +842,12 @@ public NodeState FindPredefinedNode(NodeId nodeId, Type expectedType)
/// </summary>
public virtual void DeleteAddressSpace()
{
if (m_predefinedNodes != null)
{
var nodes = m_predefinedNodes.Values.ToArray();
m_predefinedNodes.Clear();
var nodes = m_predefinedNodes.Values.ToArray();
m_predefinedNodes.Clear();

foreach (NodeState node in nodes)
{
Utils.SilentDispose(node);
}
foreach (NodeState node in nodes)
{
Utils.SilentDispose(node);
}
}

Expand Down Expand Up @@ -894,7 +878,7 @@ protected virtual NodeHandle GetManagerHandle(ServerSystemContext context, NodeI
}

NodeState node = null;
if (m_predefinedNodes?.TryGetValue(nodeId, out node) == true)
if (m_predefinedNodes.TryGetValue(nodeId, out node) == true)
{
var handle = new NodeHandle {
NodeId = nodeId,
Expand Down

0 comments on commit fcc3b74

Please sign in to comment.