示例#1
0
        /// <summary>
        /// Returns a unique handle for the node.
        /// </summary>
        protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache)
        {
            lock (Lock)
            {
                // quickly exclude nodes that are not in the namespace.
                if (!IsNodeIdInNamespace(nodeId))
                {
                    return(null);
                }

                NodeHandle handle = new NodeHandle();
                handle.NodeId    = nodeId;
                handle.Validated = true;

                uint id = (uint)nodeId.Identifier;

                // find register
                int registerId = (int)((id & 0xFF000000) >> 24);
                int index      = (int)(id & 0x00FFFFFF);

                if (registerId == 0)
                {
                    MemoryRegister register = m_system.GetRegister(index);

                    if (register == null)
                    {
                        return(null);
                    }

                    handle.Node = ModelUtils.GetRegister(register, NamespaceIndex);
                }

                // find register variable.
                else
                {
                    MemoryRegister register = m_system.GetRegister(registerId);

                    if (register == null)
                    {
                        return(null);
                    }

                    // find register variable.
                    BaseDataVariableState variable = ModelUtils.GetRegisterVariable(register, index, NamespaceIndex);

                    if (variable == null)
                    {
                        return(null);
                    }

                    handle.Node = variable;
                }

                return(handle);
            }
        }
示例#2
0
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.
        /// </remarks>
        public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences)
        {
            lock (Lock)
            {
                m_system.Initialize();

                IList <MemoryRegister> registers = m_system.GetRegisters();

                for (int ii = 0; ii < registers.Count; ii++)
                {
                    NodeId targetId = ModelUtils.GetRegisterId(registers[ii], NamespaceIndex);

                    IList <IReference> references = null;

                    if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
                    {
                        externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>();
                    }

                    references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId));
                }
            }
        }
示例#3
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            NodeId targetId = null;

            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                // browse name must be qualified by the correct namespace.
                if (m_parent.BrowseName.NamespaceIndex != base.BrowseName.NamespaceIndex)
                {
                    return(null);
                }

                // parse the browse name.
                int index = 0;

                for (int ii = 0; ii < base.BrowseName.Name.Length; ii++)
                {
                    char ch = base.BrowseName.Name[ii];

                    if (!Char.IsDigit(ch))
                    {
                        return(null);
                    }

                    index *= 10;
                    index += Convert.ToInt32(ch - '0');
                }

                // check for valid browse name.
                if (index < 0 || index > m_parent.Register.Size)
                {
                    return(null);
                }

                // return target.
                targetId = ModelUtils.GetRegisterVariableId(m_parent.Register, index, m_parent.NodeId.NamespaceIndex);
            }

            // return the child at the next position.
            else
            {
                // look for next segment.
                if (m_position >= m_parent.Register.Size)
                {
                    return(null);
                }

                // return target.
                targetId = ModelUtils.GetRegisterVariableId(m_parent.Register, m_position, m_parent.NodeId.NamespaceIndex);
                m_position++;
            }

            // create reference.
            if (targetId != null)
            {
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId));
            }

            return(null);
        }