Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomNodeManager2 initialize predefined nodes in constructor #2966

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
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
Loading