Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.Server/Diagnostics/DiagnosticsNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public override void CreateAddressSpace(

// The nodes are now loaded by the DiagnosticsNodeManager from the file
// output by the ModelDesigner V2. These nodes are added to the CoreNodeManager
// via the AttachNode() method when the DiagnosticsNodeManager starts.
Server.CoreNodeManager.ImportNodes(SystemContext, PredefinedNodes.Values, true);
// via ImportNodes() method when the DiagnosticsNodeManager starts.
Server.CoreNodeManager.ImportNodes(SystemContext, PredefinedNodes.Values);

// hook up the server GetMonitoredItems method.
var getMonitoredItems = (GetMonitoredItemsMethodState)FindPredefinedNode(
Expand Down
44 changes: 41 additions & 3 deletions Libraries/Opc.Ua.Server/NodeManager/CoreNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ namespace Opc.Ua.Server
/// <remarks>
/// Every Server has one instance of this NodeManager.
/// It stores objects that implement ILocalNode and indexes them by NodeId.
/// This class is deprecated. Use <see cref="CoreNodeManager2"/> instead.
/// </remarks>
public class CoreNodeManager : INodeManager, IDisposable
[Obsolete("Use CoreNodeManager2 instead. This class will be removed in a future version.")]
public class CoreNodeManager : INodeManager, ICoreNodeManager, IDisposable
{
/// <summary>
/// Initializes the object with default values.
Expand Down Expand Up @@ -148,11 +150,11 @@ internal void ImportNodes(
node.Export(context, nodesToExport);
}

lock (Server.CoreNodeManager.DataLock)
lock (DataLock)
{
foreach (ILocalNode nodeToExport in nodesToExport.OfType<ILocalNode>())
{
Server.CoreNodeManager.AttachNode(nodeToExport, isInternal);
AttachNode(nodeToExport, isInternal);
}
}
}
Expand Down Expand Up @@ -3571,6 +3573,11 @@ public NodeId CreateUniqueNodeId()
return CreateUniqueNodeId(m_dynamicNamespaceIndex);
}

/// <summary>
/// Returns the namespace index used for dynamically created nodes.
/// </summary>
public ushort DynamicNamespaceIndex => m_dynamicNamespaceIndex;

/// <inheritdoc/>
private object GetManagerHandle(ExpandedNodeId nodeId)
{
Expand Down Expand Up @@ -3682,6 +3689,37 @@ private NodeId CreateUniqueNodeId(ushort namespaceIndex)
return new NodeId(Utils.IncrementIdentifier(ref m_lastId), namespaceIndex);
}

/// <summary>
/// Called when the session is closed.
/// </summary>
public void SessionClosing(OperationContext context, NodeId sessionId, bool deleteSubscriptions)
{
// No special handling needed for session closing in the core node manager
}

/// <summary>
/// Returns true if the node is in the view.
/// </summary>
public bool IsNodeInView(OperationContext context, NodeId viewId, object nodeHandle)
{
// Core node manager supports all views
return true;
}

/// <summary>
/// Returns the metadata needed for validating permissions, associated with the node.
/// </summary>
public NodeMetadata GetPermissionMetadata(
OperationContext context,
object targetHandle,
BrowseResultMask resultMask,
Dictionary<NodeId, List<object>> uniqueNodesServiceAttributesCache,
bool permissionsOnly)
{
// Delegate to the standard GetNodeMetadata method
return GetNodeMetadata(context, targetHandle, resultMask);
}

private readonly NodeTable m_nodes;
private uint m_lastId;
private readonly SamplingGroupManager m_samplingGroupManager;
Expand Down
181 changes: 181 additions & 0 deletions Libraries/Opc.Ua.Server/NodeManager/CoreNodeManager2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/* ========================================================================
* Copyright (c) 2005-2025 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;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace Opc.Ua.Server
{
/// <summary>
/// The core node manager for the server based on CustomNodeManager2.
/// </summary>
/// <remarks>
/// Every Server has one instance of this NodeManager.
/// It manages the built-in OPC UA nodes and provides core functionality.
/// This is a refactored version of CoreNodeManager that inherits from CustomNodeManager2
/// to consolidate the NodeManager implementations in the server library.
/// </remarks>
public class CoreNodeManager2 : CustomNodeManager2, ICoreNodeManager
{
/// <summary>
/// Initializes the node manager with default values.
/// </summary>
public CoreNodeManager2(
IServerInternal server,
ApplicationConfiguration configuration,
ushort dynamicNamespaceIndex)
: base(
server,
configuration,
true, // Enable SamplingGroups
server.Telemetry.CreateLogger<CoreNodeManager2>(),
Array.Empty<string>()) // CoreNodeManager manages namespaces 0 and 1 by default
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

// Store the dynamic namespace index (typically namespace index 1)
m_dynamicNamespaceIndex = dynamicNamespaceIndex;

// Use namespace 1 if out of range
if (m_dynamicNamespaceIndex == 0 ||
m_dynamicNamespaceIndex >= server.NamespaceUris.Count)
{
m_dynamicNamespaceIndex = 1;
}

// Set up namespaces - CoreNodeManager handles namespace 0 (UA) and 1 (server namespace)
SetNamespaceIndexes(new ushort[] { 0, m_dynamicNamespaceIndex });
}

/// <summary>
/// Acquires the lock on the node manager.
/// </summary>
/// <remarks>
/// This property provides compatibility with the old CoreNodeManager API.
/// It maps to the Lock property from CustomNodeManager2.
/// </remarks>
public object DataLock => Lock;

/// <summary>
/// Returns an opaque handle identifying the node to the node manager.
/// </summary>
public override object GetManagerHandle(NodeId nodeId)
{
lock (Lock)
{
if (NodeId.IsNull(nodeId))
{
return null;
}

// Check if it's in namespace 0 (UA standard namespace) or the dynamic namespace
if (nodeId.NamespaceIndex != 0 && nodeId.NamespaceIndex != m_dynamicNamespaceIndex)
{
return null;
}

// Try to find the node in predefined nodes
NodeState node = Find(nodeId);
if (node != null)
{
return new NodeHandle(nodeId, node);
}

// Return null if not found (will be handled by other node managers)
return null;
}
}

/// <summary>
/// Creates a unique node identifier.
/// </summary>
public NodeId CreateUniqueNodeId()
{
return CreateUniqueNodeId(m_dynamicNamespaceIndex);
}

/// <summary>
/// Creates a new unique identifier for a node in the specified namespace.
/// </summary>
private NodeId CreateUniqueNodeId(ushort namespaceIndex)
{
return new NodeId(Utils.IncrementIdentifier(ref m_lastId), namespaceIndex);
}

/// <summary>
/// Imports the nodes from a dictionary of NodeState objects.
/// </summary>
public void ImportNodes(ISystemContext context, IEnumerable<NodeState> predefinedNodes)
{
ImportNodes(context, predefinedNodes, false);
}

/// <summary>
/// Imports the nodes from a dictionary of NodeState objects.
/// </summary>
internal void ImportNodes(
ISystemContext context,
IEnumerable<NodeState> predefinedNodes,
bool isInternal)
{
lock (Lock)
{
foreach (NodeState node in predefinedNodes)
{
// Add the node to the predefined nodes dictionary
AddPredefinedNode(context, node);
}
}
}

/// <summary>
/// Attaches a node to the address space.
/// </summary>
/// <remarks>
/// This method is provided for compatibility with the old CoreNodeManager.
/// It maps to AddPredefinedNode from CustomNodeManager2.
/// </remarks>
internal void AttachNode(NodeState node, bool isInternal)
{
AddPredefinedNode(SystemContext, node);
}

/// <summary>
/// Returns the namespace index used for dynamically created nodes.
/// </summary>
public ushort DynamicNamespaceIndex => m_dynamicNamespaceIndex;

private uint m_lastId;
private readonly ushort m_dynamicNamespaceIndex;
}
}
79 changes: 79 additions & 0 deletions Libraries/Opc.Ua.Server/NodeManager/ICoreNodeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* ========================================================================
* Copyright (c) 2005-2025 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;

namespace Opc.Ua.Server
{
/// <summary>
/// The interface for the core node manager.
/// </summary>
/// <remarks>
/// This interface defines the contract for the core node manager that handles
/// the built-in OPC UA nodes (namespace 0) and the server's dynamic namespace.
/// It extends INodeManager2 with additional methods specific to the core node manager.
/// </remarks>
public interface ICoreNodeManager : INodeManager2
{
/// <summary>
/// Acquires the lock on the node manager.
/// </summary>
/// <remarks>
/// This lock should be used when accessing or modifying the node manager's internal state.
/// </remarks>
object DataLock { get; }

/// <summary>
/// Imports the nodes from a collection of NodeState objects.
/// </summary>
/// <param name="context">The system context.</param>
/// <param name="predefinedNodes">The predefined nodes to import.</param>
/// <remarks>
/// This method is used to add nodes to the core node manager's address space.
/// It is typically called during initialization or when loading predefined nodes.
/// </remarks>
void ImportNodes(ISystemContext context, IEnumerable<NodeState> predefinedNodes);

/// <summary>
/// Creates a unique node identifier.
/// </summary>
/// <returns>A new unique NodeId in the dynamic namespace.</returns>
/// <remarks>
/// This method generates unique node identifiers for dynamically created nodes.
/// The NodeIds are created in the server's dynamic namespace.
/// </remarks>
NodeId CreateUniqueNodeId();

/// <summary>
/// Returns the namespace index used for dynamically created nodes.
/// </summary>
/// <value>The dynamic namespace index.</value>
ushort DynamicNamespaceIndex { get; }
}
}
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.Server/NodeManager/MasterNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public MasterNodeManager(

// add the core node manager second because the diagnostics node manager takes priority.
// always add the core node manager to the second of the list.
var coreNodeManager = new CoreNodeManager(Server, configuration, (ushort)dynamicNamespaceIndex);
var coreNodeManager = new CoreNodeManager2(Server, configuration, (ushort)dynamicNamespaceIndex);
m_nodeManagers.Add(coreNodeManager.ToAsyncNodeManager());

// register core node manager for default UA namespace.
Expand Down Expand Up @@ -306,7 +306,7 @@ protected static PermissionType GetHistoryPermissionType(PerformUpdateType updat
/// <summary>
/// Returns the core node manager.
/// </summary>
public CoreNodeManager CoreNodeManager => m_nodeManagers[1].SyncNodeManager as CoreNodeManager;
public ICoreNodeManager CoreNodeManager => m_nodeManagers[1].SyncNodeManager as ICoreNodeManager;

/// <summary>
/// Returns the diagnostics node manager.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Server/Server/IServerInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public interface IServerInternal : IAuditEventServer, IDisposable
/// The internal node manager for the servers.
/// </summary>
/// <value>The core node manager.</value>
CoreNodeManager CoreNodeManager { get; }
ICoreNodeManager CoreNodeManager { get; }

/// <summary>
/// Returns the node manager that managers the server diagnostics.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Server/Server/ServerInternalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void SetModellingRulesManager(ModellingRulesManager modellingRulesManager
/// The internal node manager for the servers.
/// </summary>
/// <value>The core node manager.</value>
public CoreNodeManager CoreNodeManager { get; private set; }
public ICoreNodeManager CoreNodeManager { get; private set; }

/// <summary>
/// Returns the node manager that managers the server diagnostics.
Expand Down
Loading
Loading