/* ======================================================================== * 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.Threading; using System.Threading.Tasks; namespace Opc.Ua.Server { /// /// An object that manages modelling rules supported by the server. /// public class ModellingRulesManager : IDisposable { /// /// Initializes the manager. /// public ModellingRulesManager(IServerInternal server) { m_server = server; m_modellingRules = []; } /// /// Frees any unmanaged resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// An overrideable version of the Dispose. /// protected virtual void Dispose(bool disposing) { if (disposing) { // TBD } } /// /// Checks if the modelling rule is supported by the server. /// /// The id of the modelling rule. /// True if the modelling rule is supported. public bool IsSupported(NodeId modellingRuleId) { if (modellingRuleId.IsNull) { return false; } lock (m_lock) { return m_modellingRules.ContainsKey(modellingRuleId); } } /// /// Registers a modelling rule. /// /// The id of the modelling rule. /// The name of the modelling rule. /// A cancellation token. public async ValueTask RegisterModellingRuleAsync( NodeId modellingRuleId, string modellingRuleName, CancellationToken cancellationToken = default) { lock (m_lock) { m_modellingRules[modellingRuleId] = modellingRuleName; } await m_server.DiagnosticsNodeManager.AddModellingRuleAsync(modellingRuleId, modellingRuleName, cancellationToken) .ConfigureAwait(false); } /// /// Unregisters a modelling rule. /// /// The id of the modelling rule. public void UnregisterModellingRule(NodeId modellingRuleId) { lock (m_lock) { m_modellingRules.Remove(modellingRuleId); } } private readonly Lock m_lock = new(); private readonly IServerInternal m_server; private readonly NodeIdDictionary m_modellingRules; } }