Skip to content

Commit

Permalink
Fix nodestate remove for diagnostic infos (#2450)
Browse files Browse the repository at this point in the history
revert fix for regression introduced by fix for #2343, apply fix in nodemanagers which do not invert the inverse property, so bidirectional references were not removed.
  • Loading branch information
mregen committed Jan 17, 2024
1 parent 8c34076 commit 48e06d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
LocalReference referenceToRemove = new LocalReference(
(NodeId)reference.TargetId,
reference.ReferenceTypeId,
reference.IsInverse,
!reference.IsInverse,
node.NodeId);

referencesToRemove.Add(referenceToRemove);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
LocalReference referenceToRemove = new LocalReference(
(NodeId)reference.TargetId,
reference.ReferenceTypeId,
reference.IsInverse,
!reference.IsInverse,
node.NodeId);

referencesToRemove.Add(referenceToRemove);
Expand Down
3 changes: 1 addition & 2 deletions Libraries/Opc.Ua.Server/NodeManager/MasterNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,7 @@ public void RemoveReferences(List<LocalReference> referencesToRemove)
LocalReference reference = referencesToRemove[ii];

// find source node.
INodeManager nodeManager = null;
object sourceHandle = GetManagerHandle(reference.SourceId, out nodeManager);
object sourceHandle = GetManagerHandle(reference.SourceId, out INodeManager nodeManager);

if (sourceHandle == null)
{
Expand Down
47 changes: 9 additions & 38 deletions Stack/Opc.Ua.Core/Stack/State/NodeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,10 +2347,7 @@ public void SetAreEventsMonitored(ISystemContext context, bool areEventsMonitore
/// <param name="e">The event to report.</param>
public virtual void ReportEvent(ISystemContext context, IFilterTarget e)
{
if (OnReportEvent != null)
{
OnReportEvent(context, this, e);
}
OnReportEvent?.Invoke(context, this, e);

// report event to notifier sources.
if (m_notifiers != null)
Expand Down Expand Up @@ -2498,10 +2495,7 @@ public virtual void RemoveNotifier(ISystemContext context, NodeState target, boo
/// <param name="includeChildren">Whether to recursively report events for the children.</param>
public virtual void ConditionRefresh(ISystemContext context, List<IFilterTarget> events, bool includeChildren)
{
if (OnConditionRefresh != null)
{
OnConditionRefresh(context, this, events);
}
OnConditionRefresh?.Invoke(context, this, events);

if (includeChildren)
{
Expand Down Expand Up @@ -2581,15 +2575,9 @@ public void ClearChangeMasks(ISystemContext context, bool includeChildren)

if (m_changeMasks != NodeStateChangeMasks.None)
{
if (OnStateChanged != null)
{
OnStateChanged(context, this, m_changeMasks);
}
OnStateChanged?.Invoke(context, this, m_changeMasks);

if (StateChanged != null)
{
StateChanged(context, this, m_changeMasks);
}
StateChanged?.Invoke(context, this, m_changeMasks);

m_changeMasks = NodeStateChangeMasks.None;
}
Expand Down Expand Up @@ -2912,10 +2900,7 @@ public virtual bool Validate(ISystemContext context)

PopulateBrowser(context, browser);

if (OnPopulateBrowser != null)
{
OnPopulateBrowser(context, this, browser);
}
OnPopulateBrowser?.Invoke(context, this, browser);

return browser;
}
Expand Down Expand Up @@ -4472,25 +4457,11 @@ public void RemoveChild(BaseInstanceState child)
return false;
}

NodeStateReference sourceRef = null;

foreach (var m_refKey in m_references.Keys)
if (m_references.Remove(new NodeStateReference(referenceTypeId, isInverse, targetId)))
{
if (m_refKey.TargetId != null && m_refKey.TargetId.IdentifierText.Equals(targetId.IdentifierText))
{
sourceRef = m_refKey as NodeStateReference;
break;
}
}

if (sourceRef != null)
{
if (m_references.Remove(sourceRef))
{
m_changeMasks |= NodeStateChangeMasks.References;
OnReferenceRemoved?.Invoke(this, referenceTypeId, isInverse, targetId);
return true;
}
m_changeMasks |= NodeStateChangeMasks.References;
OnReferenceRemoved?.Invoke(this, referenceTypeId, isInverse, targetId);
return true;
}

return false;
Expand Down

0 comments on commit 48e06d0

Please sign in to comment.