/* ======================================================================== * Copyright (c) 2005-2016 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; using System.Collections.Generic; using System.Text; using System.Xml; using System.IO; using System.Runtime.Serialization; using System.Reflection; using System.Threading; #pragma warning disable 0618 namespace Opc.Ua.Server { #if LEGACY_CORENODEMANAGER /// /// The base class for custom Object nodes. /// [Obsolete("The ObjectSource class is obsolete and is not supported. See Opc.Ua.BaseObjectState for a replacement.")] public class ObjectSource : BaseInstanceSource, IObject, IEventSource { #region Constructors /// /// Adds the source to the type table. /// public ObjectSource( IServerInternal server, NodeSource parent) : base(server, parent) { } /// /// Creates a new instance of the node. /// public static ObjectSource Construct( IServerInternal server, NodeSource parent, NodeId referenceTypeId, NodeId nodeId, QualifiedName browseName, uint numericId) { ObjectSource instance = new ObjectSource(server, parent); instance.Initialize(referenceTypeId, nodeId, browseName, numericId, ObjectTypes.BaseObjectType); return instance; } /// /// Creates a new instance of the node. /// public static ObjectSource Construct(IServerInternal server) { ObjectSource instance = new ObjectSource(server, null); instance.Initialize(null, null, null, 0, ObjectTypes.BaseObjectType); return instance; } #endregion #region ICloneable Members /// public override NodeSource Clone(NodeSource parent) { lock (DataLock) { ObjectSource clone = this; clone.Initialize(this); return clone; } } #endregion #region INode Members /// public override NodeClass NodeClass { get { return NodeClass.Object; } } #endregion #region ILocalNode Members /// public override bool SupportsAttribute(uint attributeId) { lock (DataLock) { switch (attributeId) { case Attributes.EventNotifier: { return true; } default: { return base.SupportsAttribute(attributeId); } } } } #endregion #region IObject Members /// public byte EventNotifier { get { lock (DataLock) { return m_eventNotifier; } } set { lock (DataLock) { m_eventNotifier = value; } } } #endregion #region Overridden Methods /// public override void Initialize(NodeSource source) { lock (DataLock) { base.Initialize(source); ObjectSource instance = (ObjectSource)source; m_eventNotifier = instance.m_eventNotifier; } } /// protected override void CreateNode(NodeId parentId, NodeId referenceTypeId) { CheckNodeManagerState(); ObjectAttributes attributes = new ObjectAttributes(); attributes.SpecifiedAttributes = (uint)NodeAttributesMask.DisplayName; attributes.DisplayName = DisplayName; NodeManager.CreateObject( parentId, referenceTypeId, NodeId, BrowseName, attributes, TypeDefinitionId); } /// protected override void UpdateAttributes(ILocalNode source) { base.UpdateAttributes(source); IObject instance = source as IObject; if (instance != null) { m_eventNotifier = instance.EventNotifier; } } /// protected override ServiceResult ReadAttribute(IOperationContext context, uint attributeId, DataValue value) { switch (attributeId) { case Attributes.EventNotifier: { value.Value = EventNotifier; break; } default: { return base.ReadAttribute(context, attributeId, value); } } return ServiceResult.Good; } /// protected override ServiceResult WriteAttribute(uint attributeId, DataValue value) { // check for status/timestamp writes. if (value.StatusCode != StatusCodes.Good || value.ServerTimestamp != DateTime.MinValue || value.SourceTimestamp != DateTime.MinValue) { return StatusCodes.BadWriteNotSupported; } switch (attributeId) { case Attributes.EventNotifier: { EventNotifier = (byte)value.Value; break; } default: { return base.WriteAttribute(attributeId, value); } } return ServiceResult.Good; } #endregion #region IEventSource Members /// public void SubscribeToEvents( OperationContext context, object notifier, uint subscriptionId, IEventMonitoredItem monitoredItem, bool unsubscribe) { lock (DataLock) { if (unsubscribe) { Unsubscribe(monitoredItem); } else { Subscribe(monitoredItem); } } } /// public void SubscribeToAllEvents( OperationContext context, uint subscriptionId, IEventMonitoredItem monitoredItem, bool unsubscribe) { if (context == null) throw new ArgumentNullException("context"); lock (DataLock) { if (unsubscribe) { Unsubscribe(monitoredItem); } else { Subscribe(monitoredItem); } } } /// public virtual void ConditionRefresh( OperationContext context, IList monitoredItems) { if (context == null) throw new ArgumentNullException("context"); lock (DataLock) { RefreshConditions(context, monitoredItems); } } #endregion #region Public Members /// /// Whether the object should report events to its parent. /// /// /// This property is used for objects like conditions that are not part of the HasNotifier hierarchy. /// public bool ReportEventsToParent { get { lock (DataLock) { return m_reportEventsToParent; } } set { lock (DataLock) { m_reportEventsToParent = value; } } } /// /// Reports an event produced by the object. /// public virtual void ReportEvent(BaseEvent e) { lock (DataLock) { if (m_reportEventsToParent) { ObjectSource parent = Parent as ObjectSource; if (parent != null) { parent.ReportEvent(e); } } List monitoredItems = new List(); if (MonitoredItems != null) { foreach (IMonitoredItem monitoredItem in MonitoredItems) { IEventMonitoredItem eventItem = monitoredItem as IEventMonitoredItem; if (eventItem != null) { monitoredItems.Add(eventItem); } } if (monitoredItems.Count > 0) { EventManager.ReportEvent(e, monitoredItems); } } } } /// /// Returns refresh events for any conditions belonging to the object. /// protected virtual void RefreshConditions( OperationContext context, IList monitoredItems) { // not implemented. } #endregion #region Private Fields private byte m_eventNotifier; private bool m_reportEventsToParent; #endregion } #region Folder Class /// /// Represents an instance of the Folder ObjectType in the address space. /// [Obsolete("The Folder class is obsolete and is not supported. See Opc.Ua.FolderState for a replacement.")] public partial class Folder : ObjectSource { #region Constructors /// /// Initializes the object with default values. /// protected Folder(IServerInternal server, NodeSource parent) : base(server, parent) { } /// /// Creates a new instance of the node. /// public static new Folder Construct( IServerInternal server, NodeSource parent, NodeId referenceTypeId, NodeId nodeId, QualifiedName browseName, uint numericId) { Folder instance = new Folder(server, parent); instance.Initialize(referenceTypeId, nodeId, browseName, numericId, ObjectTypes.FolderType); return instance; } #endregion #region ICloneable Members /// public override NodeSource Clone(NodeSource parent) { lock (DataLock) { Folder clone = new Folder(Server, parent); clone.Initialize(this); return clone; } } #endregion } #endregion #endif }