-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathEmptyNodeManager.cs
234 lines (201 loc) · 8.33 KB
/
EmptyNodeManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* ========================================================================
* Copyright (c) 2005-2019 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 System.Text;
using System.Diagnostics;
using System.Xml;
using System.IO;
using System.Threading;
using System.Reflection;
using Opc.Ua;
using Opc.Ua.Server;
namespace Quickstarts.EmptyServer
{
/// <summary>
/// A node manager for a server that exposes several variables.
/// </summary>
public class EmptyNodeManager : CustomNodeManager2
{
#region Constructors
/// <summary>
/// Initializes the node manager.
/// </summary>
public EmptyNodeManager(IServerInternal server, ApplicationConfiguration configuration)
:
base(server, configuration, Namespaces.Empty)
{
SystemContext.NodeIdFactory = this;
// get the configuration for the node manager.
m_configuration = configuration.ParseExtension<EmptyServerConfiguration>();
// use suitable defaults if no configuration exists.
if (m_configuration == null)
{
m_configuration = new EmptyServerConfiguration();
}
}
#endregion
#region IDisposable Members
/// <summary>
/// An overrideable version of the Dispose.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
// TBD
}
}
#endregion
#region INodeIdFactory Members
/// <summary>
/// Creates the NodeId for the specified node.
/// </summary>
public override NodeId New(ISystemContext context, NodeState node)
{
return node.NodeId;
}
#endregion
#region INodeManager Members
/// <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)
{
BaseObjectState trigger = new BaseObjectState(null);
trigger.NodeId = new NodeId(1, NamespaceIndex);
trigger.BrowseName = new QualifiedName("Trigger", NamespaceIndex);
trigger.DisplayName = trigger.BrowseName.Name;
trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType;
// ensure trigger can be found via the server object.
IList<IReference> references = null;
if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
{
externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>();
}
trigger.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder);
references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, trigger.NodeId));
PropertyState property = new PropertyState(trigger);
property.NodeId = new NodeId(2, NamespaceIndex);
property.BrowseName = new QualifiedName("Matrix", NamespaceIndex);
property.DisplayName = property.BrowseName.Name;
property.TypeDefinitionId = VariableTypeIds.PropertyType;
property.ReferenceTypeId = ReferenceTypeIds.HasProperty;
property.DataType = DataTypeIds.Int32;
property.ValueRank = ValueRanks.TwoDimensions;
property.ArrayDimensions = new ReadOnlyList<uint>(new uint[] { 2, 2 });
trigger.AddChild(property);
// save in dictionary.
AddPredefinedNode(SystemContext, trigger);
ReferenceTypeState referenceType = new ReferenceTypeState();
referenceType.NodeId = new NodeId(3, NamespaceIndex);
referenceType.BrowseName = new QualifiedName("IsTriggerSource", NamespaceIndex);
referenceType.DisplayName = referenceType.BrowseName.Name;
referenceType.InverseName = new LocalizedText("IsSourceOfTrigger");
referenceType.SuperTypeId = ReferenceTypeIds.NonHierarchicalReferences;
if (!externalReferences.TryGetValue(ObjectIds.Server, out references))
{
externalReferences[ObjectIds.Server] = references = new List<IReference>();
}
trigger.AddReference(referenceType.NodeId, false, ObjectIds.Server);
references.Add(new NodeStateReference(referenceType.NodeId, true, trigger.NodeId));
// save in dictionary.
AddPredefinedNode(SystemContext, referenceType);
}
}
/// <summary>
/// Frees any resources allocated for the address space.
/// </summary>
public override void DeleteAddressSpace()
{
lock (Lock)
{
// TBD
}
}
/// <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;
}
NodeState node = null;
if (!PredefinedNodes.TryGetValue(nodeId, out node))
{
return null;
}
NodeHandle handle = new NodeHandle();
handle.NodeId = nodeId;
handle.Node = node;
handle.Validated = true;
return handle;
}
}
/// <summary>
/// Verifies that the specified node exists.
/// </summary>
protected override NodeState ValidateNode(
ServerSystemContext context,
NodeHandle handle,
IDictionary<NodeId, NodeState> cache)
{
// not valid if no root.
if (handle == null)
{
return null;
}
// check if previously validated.
if (handle.Validated)
{
return handle.Node;
}
// TBD
return null;
}
#endregion
#region Overridden Methods
#endregion
#region Private Fields
private EmptyServerConfiguration m_configuration;
#endregion
}
}